# HG changeset patch # User Doug Simon # Date 1339683954 -7200 # Node ID 46f8a4c46b6a895ce2703e1b057c30401a1e9433 # Parent dbd82d1edce6535e0c9674728062b4768c123660# Parent a9b615da0cba85a20307d2d9302ed494cc1bc533 Merge. diff -r a9b615da0cba -r 46f8a4c46b6a graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java Thu Jun 14 15:46:45 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java Thu Jun 14 16:25:54 2012 +0200 @@ -974,8 +974,6 @@ @Override public void emitRuntimeCall(RuntimeCallNode x) { - // TODO Merge with emitCallToRuntime() method above. - Value resultOperand = resultOperandFor(x.kind()); CallingConvention cc = frameMap.registerConfig.getCallingConvention(RuntimeCall, x.call().arguments, target(), false); frameMap.callsMethod(cc, RuntimeCall); @@ -996,6 +994,11 @@ // TODO is it correct here that the pointerSlots are not passed to the oop map generation? info = stateFor(stateBeforeReturn, -1); + } else { + // Every runtime call needs an info + // TODO This is conservative. It's not needed for RuntimeCalls that are implemented purely in a stub + // that does not trash any registers and does not call into the runtime. + info = state(); } emitCall(x.call(), resultOperand, argList, Constant.forLong(0), info, null); diff -r a9b615da0cba -r 46f8a4c46b6a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Thu Jun 14 15:46:45 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Thu Jun 14 16:25:54 2012 +0200 @@ -154,7 +154,7 @@ final CodeInfo[] info = Debug.isDumpEnabled() ? new CodeInfo[1] : null; compiler.getRuntime().installMethod(method, tm, info); if (info != null) { - Debug.dump(info[0], "After code installation"); + Debug.dump(new Object[] {tm, info[0]}, "After code installation"); } } diff -r a9b615da0cba -r 46f8a4c46b6a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Thu Jun 14 15:46:45 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Thu Jun 14 16:25:54 2012 +0200 @@ -41,6 +41,7 @@ public boolean useFastLocking; public boolean useFastNewObjectArray; public boolean useFastNewTypeArray; + public boolean useTLAB; // offsets, ... public int vmPageSize; diff -r a9b615da0cba -r 46f8a4c46b6a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Thu Jun 14 15:46:45 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Thu Jun 14 16:25:54 2012 +0200 @@ -75,7 +75,7 @@ installer.install(CheckCastSnippets.class); installer.install(NewInstanceSnippets.class); checkcastSnippets = new CheckCastSnippets.Templates(this); - newInstanceSnippets = new NewInstanceSnippets.Templates(this); + newInstanceSnippets = new NewInstanceSnippets.Templates(this, config.useTLAB); } diff -r a9b615da0cba -r 46f8a4c46b6a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/NewInstanceStubCall.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/NewInstanceStubCall.java Thu Jun 14 15:46:45 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/NewInstanceStubCall.java Thu Jun 14 16:25:54 2012 +0200 @@ -49,7 +49,8 @@ public void generate(LIRGenerator gen) { Variable result = gen.newVariable(Kind.Object); gen.emitMove(gen.operand(hub), AMD64.rdx.asValue()); - AMD64NewInstanceStubCallOp op = new AMD64NewInstanceStubCallOp(result, AMD64.rdx.asValue()); + LIRDebugInfo info = gen.state(); + AMD64NewInstanceStubCallOp op = new AMD64NewInstanceStubCallOp(result, AMD64.rdx.asValue(), info); gen.append(op); gen.setResult(this, result); } diff -r a9b615da0cba -r 46f8a4c46b6a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewInstanceSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewInstanceSnippets.java Thu Jun 14 15:46:45 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewInstanceSnippets.java Thu Jun 14 16:25:54 2012 +0200 @@ -61,28 +61,43 @@ * Type test used when the type being tested against is a final type. */ @Snippet - public static Object newInstance(@Parameter("hub") Object hub, @ConstantParameter("size") int size, @ConstantParameter("checkInit") boolean checkInit, @ConstantParameter("logType") String logType) { + public static Object newInstance( + @Parameter("hub") Object hub, + @ConstantParameter("size") int size, + @ConstantParameter("checkInit") boolean checkInit, + @ConstantParameter("useTLAB") boolean useTLAB, + @ConstantParameter("logType") String logType) { + if (checkInit) { int klassState = load(hub, 0, klassStateOffset(), Kind.Int); if (klassState != klassStateFullyInitialized()) { - Object instance = NewInstanceStubCall.call(hub); - return formatInstance(hub, size, instance, logType); + if (logType != null) { + Log.print(logType); + Log.println(" - uninitialized"); + } + return NewInstanceStubCall.call(hub); } } - Word thread = asWord(register(r15, wordKind())); - Word top = loadWord(thread, threadTlabTopOffset()); - Word end = loadWord(thread, threadTlabEndOffset()); - Word newTop = top.plus(size); - Object instance; - if (newTop.cmp(BE, end)) { - instance = cast(top, Object.class); - store(thread, 0, threadTlabTopOffset(), newTop); + if (useTLAB) { + Word thread = asWord(register(r15, wordKind())); + Word top = loadWord(thread, threadTlabTopOffset()); + Word end = loadWord(thread, threadTlabEndOffset()); + Word newTop = top.plus(size); + if (newTop.cmp(BE, end)) { + Object instance = cast(top, Object.class); + store(thread, 0, threadTlabTopOffset(), newTop); + return formatInstance(hub, size, instance, logType); + } else { + if (logType != null) { + Log.print(logType); + Log.println(" - stub allocate"); + } + return NewInstanceStubCall.call(hub); + } } else { - instance = NewInstanceStubCall.call(hub); + return NewInstanceStubCall.call(hub); } - - return formatInstance(hub, size, instance, logType); } private static Word asWord(Object object) { @@ -158,12 +173,14 @@ private final Cache cache; private final ResolvedJavaMethod newInstance; private final CodeCacheProvider runtime; + private final boolean useTLAB; - public Templates(CodeCacheProvider runtime) { + public Templates(CodeCacheProvider runtime, boolean useTLAB) { this.runtime = runtime; this.cache = new Cache(runtime); + this.useTLAB = useTLAB; try { - newInstance = runtime.getResolvedJavaMethod(NewInstanceSnippets.class.getDeclaredMethod("newInstance", Object.class, int.class, boolean.class, String.class)); + newInstance = runtime.getResolvedJavaMethod(NewInstanceSnippets.class.getDeclaredMethod("newInstance", Object.class, int.class, boolean.class, boolean.class, String.class)); } catch (NoSuchMethodException e) { throw new GraalInternalError(e); } @@ -178,10 +195,11 @@ HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) newInstanceNode.instanceClass(); HotSpotKlassOop hub = type.klassOop(); int instanceSize = type.instanceSize(); - Key key = new Key(newInstance).add("size", instanceSize).add("checkInit", !type.isInitialized()).add("logType", LOG_ALLOCATION ? type.name() : null); + Key key = new Key(newInstance).add("size", instanceSize).add("checkInit", !type.isInitialized()).add("useTLAB", useTLAB).add("logType", LOG_ALLOCATION ? type.name() : null); Arguments arguments = arguments("hub", hub); SnippetTemplate template = cache.get(key); Debug.log("Lowering newInstance in %s: node=%s, template=%s, arguments=%s", graph, newInstanceNode, template, arguments); + //System.out.printf("Lowering newInstance in %s: node=%s, template=%s, arguments=%s%n", graph, newInstanceNode, template, arguments); template.instantiate(runtime, newInstanceNode, newInstanceNode, arguments); new DeadCodeEliminationPhase().apply(graph); } diff -r a9b615da0cba -r 46f8a4c46b6a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/AMD64NewInstanceStubCallOp.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/AMD64NewInstanceStubCallOp.java Thu Jun 14 15:46:45 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/AMD64NewInstanceStubCallOp.java Thu Jun 14 16:25:54 2012 +0200 @@ -29,6 +29,7 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.graph.*; import com.oracle.graal.hotspot.*; +import com.oracle.graal.lir.*; import com.oracle.graal.lir.amd64.*; import com.oracle.graal.lir.asm.*; import com.oracle.max.asm.target.amd64.*; @@ -38,8 +39,8 @@ * and implemented in Runtime1::generate_code_for() which is located in c1_Runtime1_x86.cpp. */ public class AMD64NewInstanceStubCallOp extends AMD64LIRInstruction { - public AMD64NewInstanceStubCallOp(Value result, Value hub) { - super("NEW_INSTANCE", new Value[] {result}, null, new Value[] {hub}, NO_OPERANDS, NO_OPERANDS); + public AMD64NewInstanceStubCallOp(Value result, Value hub, LIRDebugInfo info) { + super("NEW_INSTANCE", new Value[] {result}, info, new Value[] {hub}, NO_OPERANDS, NO_OPERANDS); } @Override @@ -50,7 +51,7 @@ // rdx: (in) hub // rax: (out) result assert asRegister(hub) == AMD64.rdx; - AMD64Call.directCall(tasm, masm, HotSpotGraalRuntime.getInstance().getConfig().newInstanceStub, null); + AMD64Call.directCall(tasm, masm, HotSpotGraalRuntime.getInstance().getConfig().newInstanceStub, info); if (asRegister(result) != AMD64.rax) { masm.movq(asRegister(result), AMD64.rax); } diff -r a9b615da0cba -r 46f8a4c46b6a graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraalCompilerTest.java --- a/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraalCompilerTest.java Thu Jun 14 15:46:45 2012 +0200 +++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraalCompilerTest.java Thu Jun 14 16:25:54 2012 +0200 @@ -147,6 +147,10 @@ private static int compilationId = 0; + protected void assertEquals(Object expected, Object actual) { + Assert.assertEquals(expected, actual); + } + protected void test(String name, Object... args) { Method method = getMethod(name); Object expect = null; @@ -171,7 +175,7 @@ } } else { Object actual = compiledMethod.executeVarargs(args); - Assert.assertEquals(expect, actual); + assertEquals(expect, actual); } } diff -r a9b615da0cba -r 46f8a4c46b6a graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/NewInstanceTest.java --- a/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/NewInstanceTest.java Thu Jun 14 15:46:45 2012 +0200 +++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/NewInstanceTest.java Thu Jun 14 16:25:54 2012 +0200 @@ -26,25 +26,35 @@ import org.junit.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.nodes.*; - /** * Tests the implementation of {@code NEW}. */ -public class NewInstanceTest extends TypeCheckTest { +public class NewInstanceTest extends GraalCompilerTest { @Override - protected void replaceProfile(StructuredGraph graph, JavaTypeProfile profile) { + protected void assertEquals(Object expected, Object actual) { + Assert.assertTrue(expected != null); + Assert.assertTrue(actual != null); + super.assertEquals(expected.getClass(), actual.getClass()); } @Test public void test1() { + test("newObject"); + test("newBigObject"); test("newEmptyString"); test("newString", "value"); test("newHashMap", 31); } + public static Object newObject() { + return new Object(); + } + + public static BigObject newBigObject() { + return new BigObject(); + } + public static String newEmptyString() { return new String(); } @@ -56,4 +66,51 @@ public static HashMap newHashMap(int initialCapacity) { return new HashMap(initialCapacity); } + + static class BigObject { + Object f01; + Object f02; + Object f03; + Object f04; + Object f05; + Object f06; + Object f07; + Object f08; + Object f09; + Object f10; + Object f12; + Object f13; + Object f14; + Object f15; + Object f16; + Object f17; + Object f18; + Object f19; + Object f20; + Object f21; + Object f22; + Object f23; + Object f24; + Object f25; + Object f26; + Object f27; + Object f28; + Object f29; + Object f30; + Object f31; + Object f32; + Object f33; + Object f34; + Object f35; + Object f36; + Object f37; + Object f38; + Object f39; + Object f40; + Object f41; + Object f42; + Object f43; + Object f44; + Object f45; + } } diff -r a9b615da0cba -r 46f8a4c46b6a src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Thu Jun 14 15:46:45 2012 +0200 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Thu Jun 14 16:25:54 2012 +0200 @@ -785,6 +785,7 @@ set_boolean(env, config, "useFastLocking", UseFastLocking); set_boolean(env, config, "useFastNewObjectArray", UseFastNewObjectArray); set_boolean(env, config, "useFastNewTypeArray", UseFastNewTypeArray); + set_boolean(env, config, "useTLAB", UseTLAB); set_int(env, config, "codeEntryAlignment", CodeEntryAlignment); set_int(env, config, "vmPageSize", os::vm_page_size()); set_int(env, config, "stackShadowPages", StackShadowPages);