Added WildcardTypeImpl implementation (minimal support).
authorrtrimana <rtrimana@uci.edu>
Sat, 22 Jun 2019 00:05:46 +0000 (17:05 -0700)
committerrtrimana <rtrimana@uci.edu>
Sat, 22 Jun 2019 00:05:46 +0000 (17:05 -0700)
src/classes/sun/reflect/generics/reflectiveObjects/WildcardTypeImpl.java
src/main/gov/nasa/jpf/vm/Types.java
src/peers/gov/nasa/jpf/vm/JPF_java_lang_reflect_Method.java
src/peers/gov/nasa/jpf/vm/JPF_sun_reflect_generics_reflectiveObjects_WildcardTypeImpl.java

index 1feb20d4a6d0259d8fc2c2b3e1fcea091033fa3f..865c202c35a075a9f9e53c6820622e8b111d817e 100644 (file)
@@ -37,9 +37,6 @@ public class WildcardTypeImpl extends LazyReflectiveObjectGenerator
         lowerBoundASTs = lbs;
     }
 
-    /**
-     * Static factory.
-     */
     public static WildcardTypeImpl make(FieldTypeSignature[] ubs,
                                         FieldTypeSignature[] lbs,
                                         GenericsFactory f) {
@@ -55,9 +52,13 @@ public class WildcardTypeImpl extends LazyReflectiveObjectGenerator
         throw new UnsupportedOperationException();
     }
 
-    public native Type[] getUpperBounds();
+    public Type[] getUpperBounds() {
+        return upperBounds;
+    }
 
-    public native Type[] getLowerBounds();
+    public Type[] getLowerBounds() {
+        return lowerBounds;
+    }
 
     public String toString() {
         Type[] lowerBounds = getLowerBounds();
@@ -75,7 +76,9 @@ public class WildcardTypeImpl extends LazyReflectiveObjectGenerator
                 return "?";
         }
 
-        assert bounds.length > 0;
+        // TODO: Commented out since it's producing <clinit> that blocks us from getting a new object without
+        // TODO: initializing it through the constructor.
+        //assert bounds.length > 0;
 
         boolean first = true;
         for(Type bound: bounds) {
index 90e7f54dca5a3a8ba6316ee3d83a07e9daf4d07a..948b42e512013b1b7cd88d2a0b002252e59dd8c3 100644 (file)
@@ -1260,5 +1260,16 @@ public class Types {
     String typeParamSig = parameterizedType.concat(":");
     return signature.contains(typeParamSig);
   }
+
+  public static boolean isWildcardType(String signature) {
+    return (signature.startsWith("+L") || signature.equals("*"));
+  }
+
+  public static String getWildcardType(String signature) {
+    if (signature.equals("*")) {
+      return "java.lang.Object";
+    }
+    return signature.replace("+L", "");
+  }
   // TODO: Fix for Groovy's model-checking
 }
index bf2594583885752ca60cc8f36cbaba66b81ad50f..026e54fc843a1621328053ce813947dcfe994f5d 100644 (file)
@@ -140,8 +140,11 @@ public class JPF_java_lang_reflect_Method extends NativePeer {
     String methodGenericSig = mi.getGenericSignature();
     for(int j = 0; j < parameterizedTypes.length; j++) {
       if (Types.isTypeParameter(parameterizedTypes[j], methodGenericSig) ||
-          Types.isTypeParameter(parameterizedTypes[j], classGenericSig)) {
+              Types.isTypeParameter(parameterizedTypes[j], classGenericSig)) {
         types[j] = getTypeVariableImplObject(env, objRef, parameterizedTypes[j]);
+      } else if (Types.isWildcardType(parameterizedTypes[j])) {
+        String wildcardType = Types.getWildcardType(parameterizedTypes[j]);
+        types[j] = getWildcardTypeImplObject(env, objRef, wildcardType);
       } else {
         ClassInfo pci = cli.getResolvedClassInfo(parameterizedTypes[j]);
         if (!pci.isRegistered()) {
@@ -172,6 +175,26 @@ public class JPF_java_lang_reflect_Method extends NativePeer {
     return paramTypeRef;
   }
 
+  private static int getWildcardTypeImplObject(MJIEnv env, int objRef, String wildcardType) {
+    ThreadInfo ti = env.getThreadInfo();
+    ClassLoaderInfo cli = env.getSystemClassLoaderInfo();
+    ClassInfo ci = cli.getResolvedClassInfo("sun.reflect.generics.reflectiveObjects.WildcardTypeImpl");
+
+    int wildcardRef = env.newObject(ci);
+    ElementInfo ei = env.getModifiableElementInfo(wildcardRef);
+    int uRef = env.newObjectArray("Ljava/lang/reflect/Type;", 1);
+    ClassInfo uci = cli.getResolvedClassInfo(wildcardType);
+    if (!uci.isRegistered()) {
+      uci.registerClass(ti);
+    }
+    env.setReferenceArrayElement(uRef, 0, uci.getClassObjectRef());
+    ei.setReferenceField("upperBounds", uRef);
+    int lRef = env.newObjectArray("Ljava/lang/reflect/Type;", 0);
+    ei.setReferenceField("lowerBounds", lRef);
+
+    return wildcardRef;
+  }
+
   private static int getTypeVariableImplObject(MJIEnv env, int objRef, String parameterizedType) {
 
     ClassLoaderInfo cli = env.getSystemClassLoaderInfo();
@@ -188,7 +211,6 @@ public class JPF_java_lang_reflect_Method extends NativePeer {
 
   static int getGenericParameterTypes( MJIEnv env, int objRef, MethodInfo mi) {
     ThreadInfo ti = env.getThreadInfo();
-    String name = mi.getName();
     String[] argTypeNames = mi.getArgumentGenericTypeNames();
     int[] ar = new int[argTypeNames.length];
 
index 89bab397c21d761acc6269319bdd590eff93c28d..b5ec06e0cc645a6713ac132bdb949a5699fddd65 100644 (file)
@@ -20,11 +20,10 @@ package gov.nasa.jpf.vm;
 
 import gov.nasa.jpf.annotation.MJI;
 
-public class JPF_sun_reflect_generics_reflectiveObjects_WildcardTypeImpl {
+public class JPF_sun_reflect_generics_reflectiveObjects_WildcardTypeImpl extends NativePeer {
 
-    // TODO: Need to fix the following 2 methods!!!
-
-    @MJI
+    // TODO: Need to fix the following 2 methods if needed!!!
+    /*@MJI
     public int getUpperBounds_____3Ljava_lang_reflect_Type_2 (MJIEnv env, int objRef){
         ThreadInfo ti = env.getThreadInfo();
         ClassInfo ci = ClassLoaderInfo.getCurrentResolvedClassInfo("java.lang.Object");
@@ -48,5 +47,5 @@ public class JPF_sun_reflect_generics_reflectiveObjects_WildcardTypeImpl {
         env.setReferenceArrayElement(aRef, 0, MJIEnv.NULL);
 
         return aRef;
-    }
+    }*/
 }