comparison 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
comparison
equal deleted inserted replaced
33:a0b1b1aa6cdf 34:49be04cc6389
18 package gov.nasa.jpf.vm; 18 package gov.nasa.jpf.vm;
19 19
20 // see mixinJPFStack() comments 20 // see mixinJPFStack() comments
21 //import sun.misc.SharedSecrets; 21 //import sun.misc.SharedSecrets;
22 //import sun.misc.JavaLangAccess; 22 //import sun.misc.JavaLangAccess;
23 import jdk.internal.misc.SharedSecrets; 23 // import jdk.internal.misc.SharedSecrets;
24 import jdk.internal.misc.JavaLangAccess; 24 // import jdk.internal.misc.JavaLangAccess;
25 import java.lang.StackWalker;
26 import java.util.stream.Stream;
27 import java.util.Optional;
25 28
26 import gov.nasa.jpf.Config; 29 import gov.nasa.jpf.Config;
27 import static gov.nasa.jpf.util.OATHash.*; 30 import static gov.nasa.jpf.util.OATHash.*;
28 31
29 /** 32 /**
82 * StackTraceElement[] ste = throwable.getStackTrace(); 85 * StackTraceElement[] ste = throwable.getStackTrace();
83 * StackTraceElement e = ste[4]; 86 * StackTraceElement e = ste[4];
84 * if (e.getClassName().equals("gov.nasa.jpf.vm.MJIEnv") && e.getMethodName().startsWith("new")){ .. 87 * if (e.getClassName().equals("gov.nasa.jpf.vm.MJIEnv") && e.getMethodName().startsWith("new")){ ..
85 */ 88 */
86 89
87 static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess(); 90 // static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
88 static final String ENV_CLSNAME = MJIEnv.class.getName(); 91 static final String ENV_CLSNAME = MJIEnv.class.getName();
89 92
90 // <2do> this method is problematic - we should not assume a fixed stack position 93 // <2do> this method is problematic - we should not assume a fixed stack position
91 // but we can't just mixin the whole stack since this would cause different class object 94 // but we can't just mixin the whole stack since this would cause different class object
92 // allocation contexts (registerClass can happen from lots of locations). 95 // allocation contexts (registerClass can happen from lots of locations).
93 // At the other end of the spectrum, MJIEnv.newXX() is not differentiating enough since 96 // At the other end of the spectrum, MJIEnv.newXX() is not differentiating enough since
94 // those are convenience methods used from a gazillion of places that might share 97 // those are convenience methods used from a gazillion of places that might share
95 // the same SUT state 98 // the same SUT state
96 static int mixinJPFStack (int h) { 99 static int mixinJPFStack (int h) {
97 throwable.fillInStackTrace(); 100 // throwable.fillInStackTrace();
98 101
99 // we know the callstack is at least 4 levels deep: 102 // we know the callstack is at least 4 levels deep:
100 // 0: mixinJPFStack 103 // 0: mixinJPFStack
101 // 1: getXAllocationContext 104 // 1: getXAllocationContext
102 // 2: heap.getXAllocationContext 105 // 2: heap.getXAllocationContext
106 109
107 // note that it is not advisable to mixin more than the immediate newX() caller since 110 // note that it is not advisable to mixin more than the immediate newX() caller since
108 // this would create state leaks for allocations that are triggered by SUT threads and 111 // this would create state leaks for allocations that are triggered by SUT threads and
109 // have different native paths (e.g. Class object creation caused by different SUT thread context) 112 // have different native paths (e.g. Class object creation caused by different SUT thread context)
110 113
111 StackTraceElement e = JLA.getStackTraceElement(throwable, 4); // see note below regarding fixed call depth fragility 114 // StackTraceElement e = JLA.getStackTraceElement(throwable, 4); // see note below regarding fixed call depth fragility
112 // <2do> this sucks - MJIEnv.newObject/newArray/newString are used from a gazillion of places that might not differ in SUT state 115 // <2do> this sucks - MJIEnv.newObject/newArray/newString are used from a gazillion of places that might not differ in SUT state
113 if (e.getClassName() == ENV_CLSNAME && e.getMethodName().startsWith("new")){ 116 // if (e.getClassName() == ENV_CLSNAME && e.getMethodName().startsWith("new")){
114 // there is not much use to loop, since we don't have a good end condition 117 // there is not much use to loop, since we don't have a good end condition
115 e = JLA.getStackTraceElement(throwable, 5); 118 // e = JLA.getStackTraceElement(throwable, 5);
116 } 119 // }
120
121 Optional<StackWalker.StackFrame> o = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).walk(s ->
122 s.dropWhile(f -> f.getClassName() == ENV_CLSNAME && f.getMethodName().startsWith("new")) .findFirst());
123 if (!o.isPresent()) return h;
124 StackWalker.StackFrame e = o.get();
117 125
118 // NOTE - this is fragile since it is implementation dependent and differs 126 // NOTE - this is fragile since it is implementation dependent and differs
119 // between JPF runs 127 // between JPF runs
120 // the names are interned string from the class object 128 // the names are interned string from the class object
121 // h = hashMixin( h, System.identityHashCode(e.getClassName())); 129 // h = hashMixin( h, System.identityHashCode(e.getClassName()));