Moving recursive lookup for defineClass0 just in the native method itself; messing...
authorrtrimana <rtrimana@uci.edu>
Fri, 5 Jul 2019 19:01:56 +0000 (12:01 -0700)
committerrtrimana <rtrimana@uci.edu>
Fri, 5 Jul 2019 19:01:56 +0000 (12:01 -0700)
src/main/gov/nasa/jpf/vm/ClassLoaderInfo.java
src/peers/gov/nasa/jpf/vm/JPF_java_lang_ClassLoader.java
src/tests/gov/nasa/jpf/test/java/lang/ClassLoaderTest.java

index 63c3c883b19a4a05d14bd53d41d715e1bb8c621f..b32858739172ee74fd52de1272650688e842d879 100644 (file)
@@ -360,13 +360,7 @@ public class ClassLoaderInfo
           }
 
         } else { // no match found
           }
 
         } else { // no match found
-          // TODO: Fix for Groovy's model-checking
-          // TODO: May need to do a recursive lookup
-          if (parent != null) {
-            return parent.getResolvedClassInfo(typeName);
-          } else {
-            throw new ClassInfoException("class not found: " + typeName, this, "java.lang.ClassNotFoundException", typeName);
-          }
+          throw new ClassInfoException("class not found: " + typeName, this, "java.lang.ClassNotFoundException", typeName);
         }
       }
       
         }
       }
       
@@ -591,11 +585,6 @@ public class ClassLoaderInfo
           }          
         }
       }
           }          
         }
       }
-      // TODO: Fix for Groovy's model-checking
-      // TODO: May need to do a recursive lookup
-      if (parent != null) {
-        return parent.loadClass(typeName);
-      }
 
       // initiate the roundtrip & bail out
       pushloadClassFrame(typeName);
 
       // initiate the roundtrip & bail out
       pushloadClassFrame(typeName);
index 98a8dd4fc124376f5723da41f72b4910f1d59890..25a1dcf1afb58efe08e48687189ce4d9a1f55317 100644 (file)
@@ -128,17 +128,19 @@ public class JPF_java_lang_ClassLoader extends NativePeer {
     return ci.getClassObjectRef();
   }
 
     return ci.getClassObjectRef();
   }
 
+  // TODO: Fix for Groovy's model-checking
+  // TODO: Load the SystemClassLoader if this ClassLoader fails, but just get it if it is already defined!
+  // TODO: This is needed for sun.reflect.GroovyMagic and some other classes
   @MJI
   public int defineClass0__Ljava_lang_String_2_3BII__Ljava_lang_Class_2 
                                       (MJIEnv env, int objRef, int nameRef, int bufferRef, int offset, int length) {
     String cname = env.getStringObject(nameRef);
     ClassLoaderInfo cl = env.getClassLoaderInfo(objRef);
 
   @MJI
   public int defineClass0__Ljava_lang_String_2_3BII__Ljava_lang_Class_2 
                                       (MJIEnv env, int objRef, int nameRef, int bufferRef, int offset, int length) {
     String cname = env.getStringObject(nameRef);
     ClassLoaderInfo cl = env.getClassLoaderInfo(objRef);
 
-    // determine whether that the corresponding class is already defined by this 
-    // classloader, if so, this attempt is invalid, and loading throws a LinkageError
+    // determine whether that the corresponding class is already defined by this
+    // classloader, if so, just return the already defined class!
     if (cl.getDefinedClassInfo(cname) != null) {  // attempt to define twice
     if (cl.getDefinedClassInfo(cname) != null) {  // attempt to define twice
-      env.throwException("java.lang.LinkageError"); 
-      return MJIEnv.NULL;
+      return cl.getDefinedClassInfo(cname).getClassObjectRef();
     }
         
     byte[] buffer = env.getByteArrayObject(bufferRef);
     }
         
     byte[] buffer = env.getByteArrayObject(bufferRef);
@@ -154,13 +156,32 @@ public class JPF_java_lang_ClassLoader extends NativePeer {
       ci.registerClass(ti);
 
       return ci.getClassObjectRef();
       ci.registerClass(ti);
 
       return ci.getClassObjectRef();
-      
+
+    } catch (LoadOnJPFRequired rre) {
+      return searchThroughSystemClassLoader(env, objRef, nameRef, bufferRef, offset, length);
+
     } catch (ClassInfoException cix){
     } catch (ClassInfoException cix){
+      if (cix.getExceptionClass().equals("java.lang.ClassNotFoundException")) {
+        return searchThroughSystemClassLoader(env, objRef, nameRef, bufferRef, offset, length);
+      }
       env.throwException("java.lang.ClassFormatError");
       return MJIEnv.NULL;
       env.throwException("java.lang.ClassFormatError");
       return MJIEnv.NULL;
+
     }
   }
 
     }
   }
 
+  private int searchThroughSystemClassLoader
+          (MJIEnv env, int objRef, int nameRef, int bufferRef, int offset, int length) {
+
+    int sysObjRef = env.getSystemClassLoaderInfo().getClassLoaderObjectRef();
+    if (objRef != sysObjRef) {
+      return defineClass0__Ljava_lang_String_2_3BII__Ljava_lang_Class_2
+              (env, sysObjRef, nameRef, bufferRef, offset, length);
+    }
+    env.throwException("java.lang.ClassNotFoundException");
+    return MJIEnv.NULL;
+  }
+
 
   protected static boolean check(MJIEnv env, String cname, byte[] buffer, int offset, int length) {
     // throw SecurityExcpetion if the package prefix is java
 
   protected static boolean check(MJIEnv env, String cname, byte[] buffer, int offset, int length) {
     // throw SecurityExcpetion if the package prefix is java
index 5e164fc7375eb1ae3096ce6ea15d632abeefe320..5899d2bb2733a6eab5b9d5f2e7225cf015e3beec 100644 (file)
@@ -6,13 +6,13 @@
  * The Java Pathfinder core (jpf-core) platform is licensed under the
  * Apache License, Version 2.0 (the "License"); you may not use this file except
  * in compliance with the License. You may obtain a copy of the License at
  * The Java Pathfinder core (jpf-core) platform is licensed under the
  * Apache License, Version 2.0 (the "License"); you may not use this file except
  * in compliance with the License. You may obtain a copy of the License at
- * 
- *        http://www.apache.org/licenses/LICENSE-2.0. 
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0.
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and 
+ * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package gov.nasa.jpf.test.java.lang;
  * limitations under the License.
  */
 package gov.nasa.jpf.test.java.lang;
@@ -30,7 +30,7 @@ import org.junit.Test;
  * test of java.lang.ClassLoader API
  */
 public class ClassLoaderTest extends TestJPF {
  * test of java.lang.ClassLoader API
  */
 public class ClassLoaderTest extends TestJPF {
-  
+
   @Test
   public void testGetResource() {
     if(verifyNoPropertyViolation()) {
   @Test
   public void testGetResource() {
     if(verifyNoPropertyViolation()) {
@@ -128,7 +128,7 @@ public class ClassLoaderTest extends TestJPF {
   public void testFoundResources() throws IOException {
     if(verifyNoPropertyViolation()) {
       TestClassLoader classLoader = new TestClassLoader();
   public void testFoundResources() throws IOException {
     if(verifyNoPropertyViolation()) {
       TestClassLoader classLoader = new TestClassLoader();
-      Enumeration<URL> enm = classLoader.findResources("not_existing_resource"); 
+      Enumeration<URL> enm = classLoader.findResources("not_existing_resource");
       assertNotNull(enm);
       assertFalse(enm.hasMoreElements());
     }
       assertNotNull(enm);
       assertFalse(enm.hasMoreElements());
     }
@@ -168,7 +168,7 @@ public class ClassLoaderTest extends TestJPF {
   }
 
   class TestClassLoader extends ClassLoader {
   }
 
   class TestClassLoader extends ClassLoader {
-      
+
     public TestClassLoader() {
       super();
     }
     public TestClassLoader() {
       super();
     }
@@ -178,8 +178,8 @@ public class ClassLoaderTest extends TestJPF {
     }
 
     @Override
     }
 
     @Override
-       protected Enumeration<URL> findResources(String name) throws IOException {
+    protected Enumeration<URL> findResources(String name) throws IOException {
       return super.findResources(name);
     }
   }
       return super.findResources(name);
     }
   }
-}
+}
\ No newline at end of file