1 cananian 1.1.2.1 // RuntimeInformation.java, created Mon Jan 17 00:51:55 2000 by cananian 2 cananian 1.1.2.2 // Copyright (C) 2000 C. Scott Ananian <cananian@alumni.princeton.edu> 3 cananian 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 cananian 1.1.2.1 package harpoon.Backend.Generic; 5 cananian 1.1.2.1 6 cananian 1.1.2.1 import harpoon.ClassFile.HMethod; 7 cananian 1.1.2.1 import harpoon.ClassFile.Linker; 8 cananian 1.1.2.4 import java.util.HashSet; 9 cananian 1.1.2.1 import java.util.Set; 10 cananian 1.1.2.1 /** 11 cananian 1.1.2.1 * <code>RuntimeInformation</code> is an abstract encapsulation of 12 cananian 1.1.2.1 * analysis information about native methods as executed by 13 cananian 1.1.2.1 * a particular runtime system. Examples of runtime systems include 14 cananian 1.1.2.1 * Sun's <A HREF="http://java.sun.com/products/jdk/1.1/">JDK 1.1</A>, 15 cananian 1.1.2.1 * <A HREF="http://java.sun.com/products/jdk/1.2/">JDK1.2</A>, or 16 cananian 1.1.2.1 * <A HREF="http://java.sun.com/products/jdk/1.3/">JDK1.3</A>; 17 cananian 1.1.2.1 * GNU <A HREF="http://www.classpath.org">classpath</a>, and etc. 18 cananian 1.1.2.1 * Note that there may be additional behaviors introduced by the 19 cananian 1.1.2.1 * particular <code>Generic.Runtime</code> the code is executed 20 cananian 1.1.2.1 * by: native code executed via the 21 cananian 1.1.2.3 * <A HREF="http://www.java.sun.com/products/jdk/1.2/docs/guide/jni/index.html">Java Native Interface</A> 22 cananian 1.1.2.1 * may have additional behaviors due to the particular implementation 23 cananian 1.1.2.1 * of the JNI being used. JNI implementations are typically tied to 24 cananian 1.1.2.1 * a particular JVM; for example Sun's JDKs, 25 cananian 1.1.2.1 * <A HREF="http://www.transvirtual.com/">Transvirtual</A>'s 26 cananian 1.1.2.1 * <A HREF="http://www.transvirtual.com/products/index.html">Kaffe</A>, 27 cananian 1.1.2.1 * or our own 28 cananian 1.1.2.1 * <A HREF="http://lesser-magoo.lcs.mit.edu/~cananian/hypermail/java-dev/0341.html">FLEX native code runtime implementation</A>. 29 cananian 1.1.2.1 * <p> 30 cananian 1.1.2.1 * <code>Generic.RuntimeInformation</code> class is designed to use 31 cananian 1.1.2.1 * inheritance and proxy-ing to intelligently represent common behaviors. 32 cananian 1.1.2.1 * Behaviors discovered missing from an implementation should be added 33 cananian 1.1.2.1 * to the most general <b>appropriate</b> class (which may be either 34 cananian 1.1.2.1 * a superclass of the instance used, or a class proxied by the instance 35 cananian 1.1.2.1 * or its superclasses) in order to reduce code duplication. The 36 cananian 1.1.2.1 * root <code>Generic.RuntimeInformation</code> class should always 37 cananian 1.1.2.1 * be kept <b>completely abstract</b>. 38 cananian 1.1.2.1 * 39 cananian 1.1.2.1 * @author C. Scott Ananian <cananian@alumni.princeton.edu> 40 cananian 1.2 * @version $Id: RuntimeInformation.java,v 1.2 2002/02/25 21:01:28 cananian Exp $ 41 cananian 1.1.2.1 * @see JDK11RuntimeImplementation 42 cananian 1.1.2.1 * @see JDK12RuntimeImplementation 43 cananian 1.1.2.1 */ 44 cananian 1.1.2.1 public abstract class RuntimeInformation { 45 cananian 1.1.2.1 /** The <code>Linker</code> to use for all non-primitive elements 46 cananian 1.1.2.1 * of the returned <code>Set</code>s. */ 47 cananian 1.1.2.1 public final Linker linker; // nothing makes sense without one 48 cananian 1.1.2.1 protected RuntimeInformation(Linker linker) { 49 cananian 1.1.2.1 this.linker = linker; 50 cananian 1.1.2.1 } 51 cananian 1.1.2.1 52 cananian 1.1.2.1 /** Returns the set of methods called during the initialization 53 cananian 1.1.2.1 * of the runtime system. These methods are called <i>before</i> 54 cananian 1.1.2.1 * the "main" method of the program. Instantiation of any classes 55 cananian 1.1.2.1 * during the runtime system initialization should be indicated 56 cananian 1.1.2.1 * via inclusion of an appropriate <code>HConstructor</code> in 57 cananian 1.1.2.1 * the set of callable methods. 58 cananian 1.1.2.1 * @return a <code>Set</code> of <code>HMethod</code>s. 59 cananian 1.1.2.1 */ 60 cananian 1.1.2.1 public abstract Set initiallyCallableMethods(); 61 cananian 1.1.2.1 /** Returns the set of methods called during the execution of the 62 cananian 1.1.2.1 * specified method. The method may or may not be native; a 63 cananian 1.1.2.1 * particular run-time may do something "tricky" during the 64 cananian 1.1.2.1 * execution of an otherwise normal method which can be described 65 cananian 1.1.2.1 * by the results of this call. The specified method may not 66 cananian 1.1.2.1 * be null. To indicate that a particular method may cause the 67 cananian 1.1.2.1 * instantiation of one of more classes, appropriate 68 cananian 1.1.2.1 * <code>HConstructor</code>s should be included in the returned 69 cananian 1.1.2.1 * set. 70 cananian 1.1.2.1 * @return a <code>Set</code> of <code>HMethod</code>s. 71 cananian 1.1.2.1 */ 72 cananian 1.1.2.1 public abstract Set methodsCallableFrom(HMethod m); 73 cananian 1.1.2.1 74 cananian 1.1.2.1 /** 75 cananian 1.1.2.1 * Returns the set of basic classes which may be referenced 76 cananian 1.1.2.1 * in some way by the runtime (for example, as the component type of an 77 cananian 1.1.2.1 * array). This does not include classes which may be 78 cananian 1.1.2.1 * <i>instantiated</i> by the runtime, constructors for which 79 cananian 1.1.2.1 * ought to be included as callable methods instead of including 80 cananian 1.1.2.1 * them in the result set from this method. The only classes I can 81 cananian 1.1.2.1 * think of that ought to be included in this set are the 82 cananian 1.1.2.1 * 8 primitive type classes, which are sometimes referenced 83 cananian 1.1.2.1 * via reflection (as opposed to instantiation) via the 84 cananian 1.1.2.1 * <code>java.lang.Class.forName()</code> method; feel free to 85 cananian 1.1.2.1 * extend your implementation if I happen to be missing some 86 cananian 1.1.2.1 * possibilities. 87 cananian 1.1.2.1 * @return a <code>Set</code> of <code>HClass</code>es. 88 cananian 1.1.2.1 */ 89 cananian 1.1.2.1 public abstract Set baseClasses(); 90 cananian 1.1.2.4 91 cananian 1.1.2.4 /** Convenience method to union two sets, either or both of which 92 cananian 1.1.2.4 * may be unmodifiable. If either set is modifiable, it adds 93 cananian 1.1.2.4 * the contents of the other to it and returns the modified set. 94 cananian 1.1.2.4 * If neither is modifiable, it creates a new modifiable set and 95 cananian 1.1.2.4 * adds both sets to it before returning it. */ 96 cananian 1.1.2.4 protected final Set union(Set s1, Set s2) { 97 cananian 1.1.2.4 // first try to add elements to s1 98 cananian 1.1.2.4 try { 99 cananian 1.1.2.4 s1.addAll(s2); return s1; 100 cananian 1.1.2.4 } catch (UnsupportedOperationException e) { /* ignore */ } 101 cananian 1.1.2.4 // then try to add elements to s2 102 cananian 1.1.2.4 try { 103 cananian 1.1.2.4 s2.addAll(s1); return s2; 104 cananian 1.1.2.4 } catch (UnsupportedOperationException e) { /* ignore */ } 105 cananian 1.1.2.4 // okay, then make a new set. 106 cananian 1.1.2.4 if (s1.size() > s2.size()) { 107 cananian 1.1.2.4 Set s3 = new HashSet(s1); s3.addAll(s2); return s3; 108 cananian 1.1.2.4 } else { 109 cananian 1.1.2.4 Set s4 = new HashSet(s2); s4.addAll(s1); return s4; 110 cananian 1.1.2.4 } 111 cananian 1.1.2.4 } 112 cananian 1.2 }