src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.jtt/src/org/graalvm/compiler/jtt/backend/LargeConstantSectionTest.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
hotspot Cdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.jtt/src/org/graalvm/compiler/jtt/backend/LargeConstantSectionTest.java
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.jtt/src/org/graalvm/compiler/jtt/backend/LargeConstantSectionTest.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 20,132 ****
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.graalvm.compiler.jtt.backend;
! import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC;
! import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER;
! import static jdk.internal.org.objectweb.asm.Opcodes.ALOAD;
! import static jdk.internal.org.objectweb.asm.Opcodes.IFNE;
! import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESPECIAL;
! import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESTATIC;
! import static jdk.internal.org.objectweb.asm.Opcodes.LADD;
! import static jdk.internal.org.objectweb.asm.Opcodes.LCMP;
! import static jdk.internal.org.objectweb.asm.Opcodes.LCONST_0;
! import static jdk.internal.org.objectweb.asm.Opcodes.LLOAD;
! import static jdk.internal.org.objectweb.asm.Opcodes.LRETURN;
! import static jdk.internal.org.objectweb.asm.Opcodes.RETURN;
! import org.junit.BeforeClass;
! import org.junit.Test;
!
! import org.graalvm.compiler.api.directives.GraalDirectives;
! import org.graalvm.compiler.core.common.GraalOptions;
import org.graalvm.compiler.jtt.JTTTest;
- import org.graalvm.compiler.options.OptionValue;
- import org.graalvm.compiler.options.OptionValue.OverrideScope;
import org.graalvm.compiler.test.ExportingClassLoader;
!
! import jdk.internal.org.objectweb.asm.ClassWriter;
! import jdk.internal.org.objectweb.asm.Label;
! import jdk.internal.org.objectweb.asm.MethodVisitor;
! import jdk.internal.org.objectweb.asm.Opcodes;
! import jdk.internal.org.objectweb.asm.Type;
!
public class LargeConstantSectionTest extends JTTTest {
private static final String NAME = "LargeConstantSection";
private static final long LARGE_CONSTANT = 0xF0F0F0F0F0L;
private static LargeConstantClassLoader LOADER;
! @BeforeClass
! public static void before() {
! LOADER = new LargeConstantClassLoader(LargeConstantSectionTest.class.getClassLoader());
}
!
! public abstract static class LargeConstantAbstract {
! public abstract long run(long i);
}
! public static long test(LargeConstantAbstract a, long i) throws Exception {
! return a.run(GraalDirectives.opaque(i));
}
! public static class LargeConstantClassLoader extends ExportingClassLoader {
public LargeConstantClassLoader(ClassLoader parent) {
super(parent);
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
if (name.equals(NAME)) {
- String graalDirectivesClassName = GraalDirectives.class.getName().replace('.', '/');
- int numberIfBlocks = 1100; // Each if block contains three constants
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
! String abstractClassName = Type.getInternalName(LargeConstantAbstract.class);
! cw.visit(52, ACC_PUBLIC + ACC_SUPER, NAME, null, abstractClassName, null);
!
! mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
! mv.visitCode();
! Label l0 = new Label();
! mv.visitLabel(l0);
! mv.visitVarInsn(ALOAD, 0);
! mv.visitMethodInsn(INVOKESPECIAL, abstractClassName, "<init>", "()V", false);
! mv.visitInsn(RETURN);
! Label l1 = new Label();
! mv.visitLabel(l1);
! mv.visitMaxs(1, 1);
! mv.visitEnd();
! mv = cw.visitMethod(ACC_PUBLIC, "run", "(J)J", null, null);
mv.visitCode();
! Label nextIf = new Label();
! for (int i = 0; i < numberIfBlocks; i++) {
! mv.visitLabel(nextIf);
! mv.visitFrame(Opcodes.F_NEW, 2, new Object[]{abstractClassName, Opcodes.LONG}, 0, new Object[]{});
! mv.visitVarInsn(LLOAD, 1);
mv.visitLdcInsn(new Long(LARGE_CONSTANT + i));
- mv.visitInsn(LCMP);
- nextIf = new Label();
- mv.visitJumpInsn(IFNE, nextIf);
- mv.visitLdcInsn(new Long(LARGE_CONSTANT + i + numberIfBlocks));
- mv.visitMethodInsn(INVOKESTATIC, graalDirectivesClassName, "opaque", "(J)J", false);
- mv.visitLdcInsn(new Long(LARGE_CONSTANT + i + numberIfBlocks * 2));
- mv.visitMethodInsn(INVOKESTATIC, graalDirectivesClassName, "opaque", "(J)J", false);
- mv.visitInsn(LADD);
mv.visitInsn(LRETURN);
}
! mv.visitLabel(nextIf);
! mv.visitFrame(Opcodes.F_NEW, 2, new Object[]{abstractClassName, Opcodes.LONG}, 0, new Object[]{});
! mv.visitInsn(LCONST_0);
mv.visitInsn(LRETURN);
! Label l9 = new Label();
! mv.visitLabel(l9);
! mv.visitMaxs(4, 6);
mv.visitEnd();
-
- cw.visitEnd();
-
byte[] bytes = cw.toByteArray();
return defineClass(name, bytes, 0, bytes.length);
} else {
return super.findClass(name);
}
--- 20,144 ----
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.graalvm.compiler.jtt.backend;
! import static org.objectweb.asm.Opcodes.ACC_FINAL;
! import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
! import static org.objectweb.asm.Opcodes.ACC_STATIC;
! import static org.objectweb.asm.Opcodes.ACC_SUPER;
! import static org.objectweb.asm.Opcodes.ILOAD;
! import static org.objectweb.asm.Opcodes.LRETURN;
!
! import java.lang.reflect.Method;
! import java.util.ArrayList;
! import java.util.Collection;
! import java.util.List;
! import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.jtt.JTTTest;
import org.graalvm.compiler.test.ExportingClassLoader;
! import org.junit.Before;
! import org.junit.Test;
! import org.junit.runner.RunWith;
! import org.junit.runners.Parameterized;
! import org.junit.runners.Parameterized.Parameter;
! import org.junit.runners.Parameterized.Parameters;
! import org.objectweb.asm.ClassWriter;
! import org.objectweb.asm.Label;
! import org.objectweb.asm.MethodVisitor;
! import org.objectweb.asm.Opcodes;
!
! import jdk.vm.ci.meta.ResolvedJavaMethod;
! import junit.framework.AssertionFailedError;
!
! /**
! * This test let the compiler deal with a large amount of constant data in a method. This data is
! * stored typically in the constant section of the native method. Especially on the SPARC platform
! * the backend can address only 8k of memory with an immediate offset. Beyond this barrier, a
! * different addressing mode must be used.
! *
! * In order to do this this test generates a large method containing a large switch statement in
! * form of
! *
! * <code>
! * static long run(long a) {
! * switch(a) {
! * case 1:
! * return 0xF0F0F0F0F0L + 1;
! * case 2:
! * return 0xF0F0F0F0F0L + 2;
! * ....
! * default:
! * return 0;
! * }
! *
! * }
! * </code>
! *
! */
! @RunWith(Parameterized.class)
public class LargeConstantSectionTest extends JTTTest {
private static final String NAME = "LargeConstantSection";
private static final long LARGE_CONSTANT = 0xF0F0F0F0F0L;
private static LargeConstantClassLoader LOADER;
+ @Parameter(value = 0) public int numberBlocks;
! @Parameters(name = "{0}")
! public static Collection<Object[]> data() {
! List<Object[]> parameters = new ArrayList<>();
! for (int i = 4; i < 13; i += 2) {
! parameters.add(new Object[]{1 << i});
}
! return parameters;
}
! @Before
! public void before() {
! LOADER = new LargeConstantClassLoader(LargeConstantSectionTest.class.getClassLoader());
}
! public class LargeConstantClassLoader extends ExportingClassLoader {
public LargeConstantClassLoader(ClassLoader parent) {
super(parent);
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
if (name.equals(NAME)) {
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
! cw.visit(52, ACC_PUBLIC + ACC_SUPER, NAME, null, "java/lang/Object", null);
! mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "run", "(I)J", null, null);
mv.visitCode();
! Label begin = new Label();
! mv.visitLabel(begin);
! mv.visitVarInsn(ILOAD, 0);
! Label[] labels = new Label[numberBlocks];
! int[] keys = new int[numberBlocks];
! for (int i = 0; i < labels.length; i++) {
! labels[i] = new Label();
! keys[i] = i;
! }
! Label defaultLabel = new Label();
! mv.visitLookupSwitchInsn(defaultLabel, keys, labels);
! for (int i = 0; i < labels.length; i++) {
! mv.visitLabel(labels[i]);
! mv.visitFrame(Opcodes.F_NEW, 1, new Object[]{Opcodes.INTEGER}, 0, new Object[]{});
mv.visitLdcInsn(new Long(LARGE_CONSTANT + i));
mv.visitInsn(LRETURN);
}
! mv.visitLabel(defaultLabel);
! mv.visitFrame(Opcodes.F_NEW, 1, new Object[]{Opcodes.INTEGER}, 0, new Object[]{});
! mv.visitLdcInsn(new Long(3L));
mv.visitInsn(LRETURN);
! Label end = new Label();
! mv.visitLabel(end);
! mv.visitLocalVariable("a", "I", null, begin, end, 0);
! mv.visitMaxs(2, 1);
mv.visitEnd();
byte[] bytes = cw.toByteArray();
return defineClass(name, bytes, 0, bytes.length);
} else {
return super.findClass(name);
}
*** 134,143 ****
}
@Test
@SuppressWarnings("try")
public void run0() throws Exception {
! try (OverrideScope os = OptionValue.override(GraalOptions.InlineEverything, true)) {
! runTest("test", LOADER.findClass(NAME).newInstance(), 0L);
}
}
}
--- 146,167 ----
}
@Test
@SuppressWarnings("try")
public void run0() throws Exception {
! test("run", numberBlocks - 3);
! }
!
! @Override
! protected ResolvedJavaMethod getResolvedJavaMethod(String methodName) {
! try {
! for (Method method : LOADER.findClass(NAME).getDeclaredMethods()) {
! if (method.getName().equals(methodName)) {
! return asResolvedJavaMethod(method);
! }
! }
! } catch (ClassNotFoundException e) {
! throw new AssertionFailedError("Cannot find class " + NAME);
}
+ throw GraalError.shouldNotReachHere();
}
}
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.jtt/src/org/graalvm/compiler/jtt/backend/LargeConstantSectionTest.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File