diff src/main/gov/nasa/jpf/vm/HashedAllocationContext.java @ 34:49be04cc6389 default tip java9-try

cyclic dependency ...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 19 Dec 2017 11:21:23 +0900
parents a0b1b1aa6cdf
children
line wrap: on
line diff
--- a/src/main/gov/nasa/jpf/vm/HashedAllocationContext.java	Tue Dec 19 09:05:20 2017 +0900
+++ b/src/main/gov/nasa/jpf/vm/HashedAllocationContext.java	Tue Dec 19 11:21:23 2017 +0900
@@ -20,8 +20,11 @@
 // see mixinJPFStack() comments
 //import sun.misc.SharedSecrets;
 //import sun.misc.JavaLangAccess;
-import jdk.internal.misc.SharedSecrets;
-import jdk.internal.misc.JavaLangAccess;
+// import jdk.internal.misc.SharedSecrets;
+// import jdk.internal.misc.JavaLangAccess;
+import java.lang.StackWalker;
+import java.util.stream.Stream;
+import java.util.Optional;
 
 import gov.nasa.jpf.Config;
 import static gov.nasa.jpf.util.OATHash.*;
@@ -84,7 +87,7 @@
    *   if (e.getClassName().equals("gov.nasa.jpf.vm.MJIEnv") && e.getMethodName().startsWith("new")){ ..
    */ 
   
-   static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
+   // static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
    static final String ENV_CLSNAME = MJIEnv.class.getName();
   
   // <2do> this method is problematic - we should not assume a fixed stack position
@@ -94,7 +97,7 @@
   // those are convenience methods used from a gazillion of places that might share
    // the same SUT state
   static int mixinJPFStack (int h) {
-    throwable.fillInStackTrace();
+    // throwable.fillInStackTrace();
     
     // we know the callstack is at least 4 levels deep:
     //   0: mixinJPFStack
@@ -108,12 +111,17 @@
     // this would create state leaks for allocations that are triggered by SUT threads and
     // have different native paths (e.g. Class object creation caused by different SUT thread context)
     
-    StackTraceElement e = JLA.getStackTraceElement(throwable, 4); // see note below regarding fixed call depth fragility
+    // StackTraceElement e = JLA.getStackTraceElement(throwable, 4); // see note below regarding fixed call depth fragility
     // <2do> this sucks - MJIEnv.newObject/newArray/newString are used from a gazillion of places that might not differ in SUT state
-    if (e.getClassName() == ENV_CLSNAME && e.getMethodName().startsWith("new")){
+    // if (e.getClassName() == ENV_CLSNAME && e.getMethodName().startsWith("new")){
       // there is not much use to loop, since we don't have a good end condition
-      e = JLA.getStackTraceElement(throwable, 5);
-    }
+    //   e = JLA.getStackTraceElement(throwable, 5);
+    // }
+
+    Optional<StackWalker.StackFrame> o = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).walk(s ->
+     s.dropWhile(f -> f.getClassName() == ENV_CLSNAME && f.getMethodName().startsWith("new")) .findFirst());
+    if (!o.isPresent()) return h;
+    StackWalker.StackFrame e = o.get();
           
     // NOTE - this is fragile since it is implementation dependent and differs
     // between JPF runs