Instantiating TypeVariableImpl.java
authorRahmadi Trimananda <rtrimana@uci.edu>
Tue, 18 Jun 2019 06:55:10 +0000 (23:55 -0700)
committerRahmadi Trimananda <rtrimana@uci.edu>
Tue, 18 Jun 2019 06:55:10 +0000 (23:55 -0700)
examples/Reflection.java
src/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java
src/main/gov/nasa/jpf/jvm/ClassFile.java
src/peers/gov/nasa/jpf/vm/JPF_java_lang_Class.java

index a5451eacbdef9c6e17798f5e1805e6ba90e651a5..0a021b2f180d87d77e402098a5aa3c0f959b25cd 100644 (file)
@@ -53,7 +53,6 @@ public class Reflection {
       }
       System.out.println();*/
       TypeVariable[] typeParameters = Generic.class.getTypeParameters();
       }
       System.out.println();*/
       TypeVariable[] typeParameters = Generic.class.getTypeParameters();
-      System.out.println("Members: " + typeParameters.length);
       //TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
       for(TypeVariable typeVar: typeParameters){
          System.out.println(typeVar);   
       //TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
       for(TypeVariable typeVar: typeParameters){
          System.out.println(typeVar);   
index bb1a3d3de3270ba99419876b989b848c95ba528b..f845539b3c4ecf725fa90a2bdeeb58c79831b1e8 100644 (file)
@@ -25,11 +25,12 @@ import sun.reflect.generics.tree.FieldTypeSignature;
  */
 public class TypeVariableImpl<D extends GenericDeclaration>
     extends LazyReflectiveObjectGenerator implements TypeVariable<D> {
  */
 public class TypeVariableImpl<D extends GenericDeclaration>
     extends LazyReflectiveObjectGenerator implements TypeVariable<D> {
+//public class TypeVariableImpl {
     D genericDeclaration;
     private String name;
     private Type[] bounds;
     private FieldTypeSignature[] boundASTs;
     D genericDeclaration;
     private String name;
     private Type[] bounds;
     private FieldTypeSignature[] boundASTs;
-    private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
+    //private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
 
     // constructor is private to enforce access through static factory
     private TypeVariableImpl(D decl, String n, FieldTypeSignature[] bs,
 
     // constructor is private to enforce access through static factory
     private TypeVariableImpl(D decl, String n, FieldTypeSignature[] bs,
@@ -63,7 +64,7 @@ public class TypeVariableImpl<D extends GenericDeclaration>
                                                       GenericsFactory f) {
 
         if (!((decl instanceof Class) ||
                                                       GenericsFactory f) {
 
         if (!((decl instanceof Class) ||
-                (decl instanceof Method) ||
+                //(decl instanceof Method) ||
                 (decl instanceof Constructor))) {
             throw new AssertionError("Unexpected kind of GenericDeclaration" +
                     decl.getClass().toString());
                 (decl instanceof Constructor))) {
             throw new AssertionError("Unexpected kind of GenericDeclaration" +
                     decl.getClass().toString());
index 4bac2b27b64ff71deb19eaed631ee1b521e1191f..fd879f1aeca9dc1db9c44d1dc16b81cfb87e1a18 100644 (file)
@@ -422,6 +422,15 @@ public class ClassFile extends BinaryClassSource {
     return ((data[idx++]&0xff) << 8) | (data[idx]&0xff);
   }
 
     return ((data[idx++]&0xff) << 8) | (data[idx]&0xff);
   }
 
+  // TODO: DIRTY HACKS!!!
+  public final int readU4(){
+    int idx = pos;
+    pos += 4;
+    byte[] data = this.data;
+
+    return ((data[idx++]&0xff) <<24) | ((data[idx++]&0xff) << 16) | ((data[idx++]&0xff) << 8) | (data[idx]&0xff);
+  }
+
   public final int readI2() {
     int idx = pos;
     pos += 2;
   public final int readI2() {
     int idx = pos;
     pos += 2;
index 0d817c2e73d105361508f57a0fb2969f0618ddc3..9e8fc2b3d1f7cca3cd3b2a4866ed500159e8fa98 100644 (file)
@@ -114,14 +114,22 @@ public class JPF_java_lang_Class extends NativePeer {
   @MJI
   public int getTypeParameters_____3Ljava_lang_reflect_TypeVariable_2 (MJIEnv env, int robj){
     ClassLoaderInfo cli = env.getSystemClassLoaderInfo();
   @MJI
   public int getTypeParameters_____3Ljava_lang_reflect_TypeVariable_2 (MJIEnv env, int robj){
     ClassLoaderInfo cli = env.getSystemClassLoaderInfo();
-    ClassInfo rci = cli.getResolvedClassInfo("sun.reflect.generics.reflectiveObjects.TypeVariableImpl");
+    ClassInfo ci = cli.getResolvedClassInfo("sun.reflect.generics.reflectiveObjects.TypeVariableImpl");
+    //ClassInfo rci = cli.getResolvedClassInfo("sun.reflect.generics.reflectiveObjects.Test");
     // TODO: Need to 1) Just create the object of TypeVariableImpl, 2) Declare class type and name only, 3) Return the
     //  object reference back to the caller
     // TODO: Need to 1) Just create the object of TypeVariableImpl, 2) Declare class type and name only, 3) Return the
     //  object reference back to the caller
-    ClassInfo test = cli.getResolvedClassInfo("java.lang.Class");
+    int tvRef = env.newObject(ci);
+    ElementInfo ei = env.getModifiableElementInfo(tvRef);
+
     ClassInfo tci = env.getReferredClassInfo( robj);
     ClassInfo tci = env.getReferredClassInfo( robj);
-    int ei = env.newObject(test);
+    //ei.setReferenceField("genericDeclaration", env.newObject(tci.getName() + ".class"));
+    ei.setReferenceField("name", env.newString("TUVW"));
+    int aRef = env.newObjectArray("Ljava/lang/reflect/TypeVariable;", 1);
+    for (int i = 0; i < 1; i++) {
+      env.setReferenceArrayElement(aRef, i, tvRef);
+    }
 
 
-    return MJIEnv.NULL;
+    return aRef;
   }
   
   @MJI
   }
   
   @MJI