public inbox for frysk-cvs@sourceware.org help / color / mirror / Atom feed
From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Limit jnixx wrappers to native classes. Date: Mon, 12 May 2008 19:14:00 -0000 [thread overview] Message-ID: <20080512191412.29021.qmail@sourceware.org> (raw) The branch, master has been updated via b2ba3c8a7b2e3a94e6f2b6a08119452610185528 (commit) from 8a5126c082dfca9c91ecaf4e80e7ff9583ae8f6d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit b2ba3c8a7b2e3a94e6f2b6a08119452610185528 Author: Andrew Cagney <cagney@redhat.com> Date: Mon May 12 15:12:14 2008 -0400 Limit jnixx wrappers to native classes. frysk-sys/frysk/jnixx/ChangeLog 2008-05-12 Andrew Cagney <cagney@redhat.com> * Main.java (getJarClasses(String)): New. (getNativeClasses(HashSet)): New. (getReferences(HashSet)): New. (main(String[])): Limit to native classes. * ClassVisitor.java (visit(Class[])): Delete. (acceptComponent(Class)): Delete. * PrintHxxDefinitions.java: Update. * PrintDeclarations.java: Update. ----------------------------------------------------------------------- Summary of changes: frysk-sys/frysk/jnixx/ChangeLog | 9 ++ frysk-sys/frysk/jnixx/ClassVisitor.java | 9 +-- frysk-sys/frysk/jnixx/ClassWalker.java | 2 - frysk-sys/frysk/jnixx/Main.java | 100 ++++++++++++++++++----- frysk-sys/frysk/jnixx/PrintCxxDefinitions.java | 2 - frysk-sys/frysk/jnixx/PrintDeclarations.java | 2 - frysk-sys/frysk/jnixx/PrintHxxDefinitions.java | 2 - 7 files changed, 88 insertions(+), 38 deletions(-) First 500 lines of diff: diff --git a/frysk-sys/frysk/jnixx/ChangeLog b/frysk-sys/frysk/jnixx/ChangeLog index 7acd570..aa7319e 100644 --- a/frysk-sys/frysk/jnixx/ChangeLog +++ b/frysk-sys/frysk/jnixx/ChangeLog @@ -1,5 +1,14 @@ 2008-05-12 Andrew Cagney <cagney@redhat.com> + * Main.java (getJarClasses(String)): New. + (getNativeClasses(HashSet)): New. + (getReferences(HashSet)): New. + (main(String[])): Limit to native classes. + * ClassVisitor.java (visit(Class[])): Delete. + (acceptComponent(Class)): Delete. + * PrintHxxDefinitions.java: Update. + * PrintDeclarations.java: Update. + Have object array extend ::java::lang::Object. * JniBindings.java (printGlobals(Printer,Class)): New. Generate the array template. diff --git a/frysk-sys/frysk/jnixx/ClassVisitor.java b/frysk-sys/frysk/jnixx/ClassVisitor.java index 6520b2d..ebcce61 100644 --- a/frysk-sys/frysk/jnixx/ClassVisitor.java +++ b/frysk-sys/frysk/jnixx/ClassVisitor.java @@ -44,13 +44,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Constructor; abstract class ClassVisitor { - void visit(Class[] classes) { - for (int i = 0; i < classes.length; i++) { - visit(classes[i]); - } - } void visit(Class klass) { - acceptComponent(klass.getComponentType()); Class[] interfaces = klass.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { acceptInterface(interfaces[i]); @@ -80,7 +74,7 @@ abstract class ClassVisitor { continue; acceptMethod(method); } - Class[] classes = klass.getClasses(); + Class[] classes = klass.getDeclaredClasses(); for (int i = 0; i < classes.length; i++) { Class inner = classes[i]; acceptClass(inner); @@ -91,6 +85,5 @@ abstract class ClassVisitor { abstract void acceptConstructor(Constructor constructor); abstract void acceptField(Field field); abstract void acceptMethod(Method method); - abstract void acceptComponent(Class klass); abstract void acceptClass(Class klass); } diff --git a/frysk-sys/frysk/jnixx/ClassWalker.java b/frysk-sys/frysk/jnixx/ClassWalker.java index 169a14a..c89364a 100644 --- a/frysk-sys/frysk/jnixx/ClassWalker.java +++ b/frysk-sys/frysk/jnixx/ClassWalker.java @@ -53,8 +53,6 @@ abstract class ClassWalker { } } private final ClassVisitor visitor = new ClassVisitor() { - void acceptComponent(Class klass) { - } void acceptInterface(Class klass) { walk(klass); } diff --git a/frysk-sys/frysk/jnixx/Main.java b/frysk-sys/frysk/jnixx/Main.java index 3d5263d..3d810e9 100644 --- a/frysk-sys/frysk/jnixx/Main.java +++ b/frysk-sys/frysk/jnixx/Main.java @@ -40,6 +40,8 @@ package frysk.jnixx; import java.io.PrintWriter; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Member; @@ -52,8 +54,16 @@ import java.util.Iterator; import java.io.IOException; class Main { + /** + * Collection of classes that need native bindings. + */ + private static final HashSet nativeClasses = new HashSet(); - private static HashSet localClasses = new HashSet(); + /** + * Collection of classes that should be visible (non-visible + * classes don't get their bindings generated). + */ + private static final HashSet visibleClasses = new HashSet(); /** * Does this method require native bindings? Methods that are not @@ -61,9 +71,7 @@ class Main { * virtual. */ static boolean treatAsNative(Method method) { - // FIXME: Should be filtering based on something smarter than - // this. - if (!localClasses.contains(method.getDeclaringClass())) + if (!nativeClasses.contains(method.getDeclaringClass())) return false; return Modifier.isNative(method.getModifiers()); } @@ -74,12 +82,57 @@ class Main { * visible. */ static boolean treatAsInvisible(Member member) { - // Local or defining classea are always visible. - if (localClasses.contains(member.getDeclaringClass())) + // Native and explicitly requested classes are always visible. + if (visibleClasses.contains(member.getDeclaringClass())) return false; return Modifier.isPrivate(member.getModifiers()); } + private static HashSet getJarClasses(String jarFile) + throws IOException, ClassNotFoundException { + // Generate a list of classes in the jar file. + HashSet jarClasses = new HashSet(); + List entries = Collections.list(new JarFile(jarFile).entries()); + for (Iterator i = entries.iterator(); i.hasNext(); ) { + JarEntry entry = (JarEntry) i.next(); + String name = entry.getName(); + if (!name.endsWith(".class")) + continue; + String className = name + .replaceAll(".class$", "") + .replaceAll("/", "."); + Class klass = Class.forName(className, false, + Main.class.getClassLoader()); + jarClasses.add(klass); + } + return jarClasses; + } + + private static HashSet getNativeClasses(HashSet classes) { + final HashSet natives = new HashSet(); + // Iterate over just these identifying which are native. + ClassVisitor findNatives = new ClassVisitor() { + void acceptInterface(Class klass) { + } + void acceptConstructor(Constructor constructor) { + } + void acceptField(Field field) { + } + void acceptMethod(Method method) { + if (Modifier.isNative(method.getModifiers())) { + natives.add(method.getDeclaringClass()); + } + } + void acceptClass(Class component) { + } + }; + for (Iterator i = classes.iterator(); i.hasNext(); ) { + Class klass = (Class) i.next(); + findNatives.visit(klass); + } + return natives; + } + private static void printHxxFile(Printer p, String headerFile, Class[] classes) { p.println("#include \"frysk/jnixx/jnixx.hxx\""); @@ -123,31 +176,34 @@ class Main { public static void main(String[] args) throws ClassNotFoundException, IOException { - if (args.length != 3) { + if (args.length < 3) { throw new RuntimeException("Usage: jnixx cxx|hxx <header-filename> <jar-file>"); } boolean generateHeader = args[0].equals("hxx"); String headerFile = args[1]; String jarFile = args[2]; - - System.err.println("Reading " + jarFile); - List entries = Collections.list(new JarFile(jarFile).entries()); - for (Iterator i = entries.iterator(); i.hasNext(); ) { - JarEntry entry = (JarEntry) i.next(); - String name = entry.getName(); - if (!name.endsWith(".class")) - continue; - String className = name - .replaceAll(".class$", "") - .replaceAll("/", "."); - Class klass = Class.forName(className, false, + HashSet explicitClasses = new HashSet(); + for (int i = 3; i < args.length; i++) { + Class klass = Class.forName(args[i], false, Main.class.getClassLoader()); - localClasses.add(klass); + explicitClasses.add(klass); } - Class[] classes = new Class[localClasses.size()]; - localClasses.toArray(classes); + HashSet jarClasses = getJarClasses(jarFile); + visibleClasses.addAll(jarClasses); + visibleClasses.addAll(explicitClasses); + + nativeClasses.addAll(getNativeClasses(jarClasses)); + + HashSet requiredClasses = new HashSet(); + requiredClasses.addAll(nativeClasses); + requiredClasses.addAll(explicitClasses); + System.err.print("Required " + requiredClasses.size() + " - "); + System.err.println(requiredClasses); + + Class[] classes = new Class[requiredClasses.size()]; + requiredClasses.toArray(classes); Printer p = new Printer(new PrintWriter(System.out)); if (generateHeader) diff --git a/frysk-sys/frysk/jnixx/PrintCxxDefinitions.java b/frysk-sys/frysk/jnixx/PrintCxxDefinitions.java index da83514..5c02706 100644 --- a/frysk-sys/frysk/jnixx/PrintCxxDefinitions.java +++ b/frysk-sys/frysk/jnixx/PrintCxxDefinitions.java @@ -137,8 +137,6 @@ class PrintCxxDefinitions extends ClassWalker { } void acceptField(Field field) { } - void acceptComponent(Class klass) { - } void acceptClass(Class klass) { } }; diff --git a/frysk-sys/frysk/jnixx/PrintDeclarations.java b/frysk-sys/frysk/jnixx/PrintDeclarations.java index abc1353..f5baa5d 100644 --- a/frysk-sys/frysk/jnixx/PrintDeclarations.java +++ b/frysk-sys/frysk/jnixx/PrintDeclarations.java @@ -113,8 +113,6 @@ class PrintDeclarations extends ClassWalker { } private final ClassVisitor printer = new ClassVisitor() { - public void acceptComponent(Class klass) { - } public void acceptClass(Class klass) { } public void acceptInterface(Class klass) { diff --git a/frysk-sys/frysk/jnixx/PrintHxxDefinitions.java b/frysk-sys/frysk/jnixx/PrintHxxDefinitions.java index 6268e7f..a255ece 100644 --- a/frysk-sys/frysk/jnixx/PrintHxxDefinitions.java +++ b/frysk-sys/frysk/jnixx/PrintHxxDefinitions.java @@ -223,8 +223,6 @@ class PrintHxxDefinitions extends ClassWalker { private final ClassVisitor printer = new ClassVisitor() { - void acceptComponent(Class klass) { - } void acceptInterface(Class klass) { } void acceptClass(Class klass) { hooks/post-receive -- frysk system monitor/debugger
reply other threads:[~2008-05-12 19:14 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20080512191412.29021.qmail@sourceware.org \ --to=cagney@sourceware.org \ --cc=frysk-cvs@sourceware.org \ --cc=frysk@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).