9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.hotspot.test;
26
27 import java.util.function.Function;
28
29 import org.graalvm.compiler.test.GraalTest;
30 import org.junit.Assume;
31 import org.junit.Rule;
32 import org.junit.Test;
33 import org.junit.rules.TestRule;
34
35 import jdk.vm.ci.code.InstalledCode;
36 import jdk.vm.ci.code.InvalidInstalledCodeException;
37 import jdk.vm.ci.code.stack.InspectedFrame;
38 import jdk.vm.ci.code.stack.StackIntrospection;
39 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
40 import jdk.vm.ci.meta.ResolvedJavaMethod;
41
42 /**
43 * Create a single object which is referenced from a local, the expression stack and the lock state
44 * and then ensure that identity is maintained when the frame is forced to be materialized by
45 * {@link InspectedFrame#materializeVirtualObjects(boolean)}.
46 */
47 public class HotSpotStackIntrospectionTest extends HotSpotGraalCompilerTest {
48
49 @Rule public TestRule timeout = createTimeoutSeconds(20);
50
63 public static void testSnippet(Function<Void, Void> f) {
64 Object a = new Object();
65 testOnStack(a, forceFrameState(a, f), a);
66 }
67
68 private static void testOnStack(Object a, Object a2, Object a3) {
69 if (a != a2 || a != a3) {
70 throw new InternalError();
71 }
72 }
73
74 private static Object forceFrameState(Object a, Function<Void, Void> f) {
75 // Use a volatile store to ensure a FrameState is captured after this point.
76 v++;
77 f.apply(null);
78 return a;
79 }
80
81 @Test
82 public void run() throws InvalidInstalledCodeException {
83 // The JDK9 bits are currently broken
84 Assume.assumeTrue(GraalTest.Java8OrEarlier);
85 test("testSnippet");
86 }
87
88 @Test
89 public void runSynchronized() throws InvalidInstalledCodeException {
90 // The JDK9 bits are currently broken
91 Assume.assumeTrue(GraalTest.Java8OrEarlier);
92 test("testSynchronizedSnippet");
93 }
94
95 private void test(String name) throws InvalidInstalledCodeException {
96 ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(getMethod(name));
97 Function<Void, Void> f = o -> {
98 stackIntrospection.iterateFrames(null, null, 0, frame -> {
99 if (frame.getMethod().equals(method)) {
100 frame.materializeVirtualObjects(true);
101 }
102 return null;
103 });
104 return null;
105 };
106 InstalledCode code = getCode(method);
107 code.executeVarargs(f);
108 }
109
110 }
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.hotspot.test;
26
27 import java.util.function.Function;
28
29 import org.junit.Rule;
30 import org.junit.Test;
31 import org.junit.rules.TestRule;
32
33 import jdk.vm.ci.code.InstalledCode;
34 import jdk.vm.ci.code.InvalidInstalledCodeException;
35 import jdk.vm.ci.code.stack.InspectedFrame;
36 import jdk.vm.ci.code.stack.StackIntrospection;
37 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
38 import jdk.vm.ci.meta.ResolvedJavaMethod;
39
40 /**
41 * Create a single object which is referenced from a local, the expression stack and the lock state
42 * and then ensure that identity is maintained when the frame is forced to be materialized by
43 * {@link InspectedFrame#materializeVirtualObjects(boolean)}.
44 */
45 public class HotSpotStackIntrospectionTest extends HotSpotGraalCompilerTest {
46
47 @Rule public TestRule timeout = createTimeoutSeconds(20);
48
61 public static void testSnippet(Function<Void, Void> f) {
62 Object a = new Object();
63 testOnStack(a, forceFrameState(a, f), a);
64 }
65
66 private static void testOnStack(Object a, Object a2, Object a3) {
67 if (a != a2 || a != a3) {
68 throw new InternalError();
69 }
70 }
71
72 private static Object forceFrameState(Object a, Function<Void, Void> f) {
73 // Use a volatile store to ensure a FrameState is captured after this point.
74 v++;
75 f.apply(null);
76 return a;
77 }
78
79 @Test
80 public void run() throws InvalidInstalledCodeException {
81 test("testSnippet");
82 }
83
84 @Test
85 public void runSynchronized() throws InvalidInstalledCodeException {
86 test("testSynchronizedSnippet");
87 }
88
89 private void test(String name) throws InvalidInstalledCodeException {
90 ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(getMethod(name));
91 Function<Void, Void> f = o -> {
92 stackIntrospection.iterateFrames(null, null, 0, frame -> {
93 if (frame.getMethod().equals(method)) {
94 frame.materializeVirtualObjects(true);
95 }
96 return null;
97 });
98 return null;
99 };
100 InstalledCode code = getCode(method);
101 code.executeVarargs(f);
102 }
103
104 }
|