# HG changeset patch # User Doug Simon # Date 1368478670 -7200 # Node ID cd77bc78c40970a91aa2040e24de166e6135c592 # Parent a54720257b7665786ef36abb0729663725ca508b# Parent ed6202820ecf754986672b8b570c035b1966502f Merge. diff -r ed6202820ecf -r cd77bc78c409 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 Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Mon May 13 22:57:50 2013 +0200 @@ -42,19 +42,14 @@ import static com.oracle.graal.hotspot.nodes.WriteBarrierPreStubCall.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.IDENTITY_HASHCODE; import static com.oracle.graal.hotspot.replacements.SystemSubstitutions.*; -import static com.oracle.graal.hotspot.stubs.CreateNullPointerExceptionStub.*; -import static com.oracle.graal.hotspot.stubs.CreateOutOfBoundsExceptionStub.*; import static com.oracle.graal.hotspot.stubs.ExceptionHandlerStub.*; import static com.oracle.graal.hotspot.stubs.LogObjectStub.*; import static com.oracle.graal.hotspot.stubs.LogPrimitiveStub.*; import static com.oracle.graal.hotspot.stubs.LogPrintfStub.*; -import static com.oracle.graal.hotspot.stubs.MonitorEnterStub.*; -import static com.oracle.graal.hotspot.stubs.MonitorExitStub.*; import static com.oracle.graal.hotspot.stubs.NewArrayStub.*; import static com.oracle.graal.hotspot.stubs.NewInstanceStub.*; import static com.oracle.graal.hotspot.stubs.NewMultiArrayStub.*; import static com.oracle.graal.hotspot.stubs.OSRMigrationEndStub.*; -import static com.oracle.graal.hotspot.stubs.RegisterFinalizerStub.*; import static com.oracle.graal.hotspot.stubs.StubUtil.*; import static com.oracle.graal.hotspot.stubs.ThreadIsInterruptedStub.*; import static com.oracle.graal.hotspot.stubs.UnwindExceptionToCallerStub.*; @@ -255,14 +250,6 @@ /* ret */ ret(word), /* arg0: thread */ nativeCallingConvention(word, /* arg1: returnAddress */ word)); - addStubCall(REGISTER_FINALIZER, - /* ret */ ret(Kind.Void), - /* arg0: object */ javaCallingConvention(Kind.Object)); - - addCRuntimeCall(REGISTER_FINALIZER_C, config.registerFinalizerAddress, - /* ret */ ret(Kind.Void), - /* arg0: thread */ nativeCallingConvention(word, - /* arg1: object */ Kind.Object)); addStubCall(NEW_ARRAY, /* ret */ ret(Kind.Object), @@ -386,44 +373,6 @@ /* temps */ null, /* ret */ ret(Kind.Void)); - addStubCall(MONITORENTER, - /* ret */ ret(Kind.Void), - /* arg0: object */ javaCallingConvention(Kind.Object, - /* arg1: lock */ word)); - - addCRuntimeCall(MONITORENTER_C, config.monitorenterAddress, - /* ret */ ret(Kind.Void), - /* arg0: thread */ nativeCallingConvention(word, - /* arg1: object */ Kind.Object, - /* arg1: lock */ word)); - - addStubCall(MONITOREXIT, - /* ret */ ret(Kind.Void), - /* arg0: object */ javaCallingConvention(Kind.Object, - /* arg1: lock */ word)); - - addCRuntimeCall(MONITOREXIT_C, config.monitorexitAddress, - /* ret */ ret(Kind.Void), - /* arg0: thread */ nativeCallingConvention(word, - /* arg1: object */ Kind.Object, - /* arg1: lock */ word)); - - addStubCall(CREATE_NULL_POINTER_EXCEPTION, - /* ret */ ret(Kind.Object)); - - addCRuntimeCall(CREATE_NULL_POINTER_EXCEPTION_C, config.createNullPointerExceptionAddress, - /* ret */ ret(Kind.Void), - /* arg0: thread */ nativeCallingConvention(word)); - - addStubCall(CREATE_OUT_OF_BOUNDS_EXCEPTION, - /* ret */ ret(Kind.Object), - /* arg0: index */ javaCallingConvention(Kind.Int)); - - addCRuntimeCall(CREATE_OUT_OF_BOUNDS_C, config.createOutOfBoundsExceptionAddress, - /* ret */ ret(Kind.Void), - /* arg0: thread */ nativeCallingConvention(word, - /* arg1: index */ Kind.Int)); - addStubCall(VM_ERROR, /* ret */ ret(Kind.Void), /* arg0: where */ javaCallingConvention(Kind.Object, @@ -570,16 +519,11 @@ link(new NewInstanceStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(NEW_INSTANCE))); link(new NewArrayStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(NEW_ARRAY))); link(new NewMultiArrayStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(NEW_MULTI_ARRAY))); - link(new RegisterFinalizerStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(REGISTER_FINALIZER))); link(new ThreadIsInterruptedStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(THREAD_IS_INTERRUPTED))); link(new ExceptionHandlerStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(EXCEPTION_HANDLER))); link(new UnwindExceptionToCallerStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(UNWIND_EXCEPTION_TO_CALLER))); link(new VerifyOopStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(VERIFY_OOP))); link(new OSRMigrationEndStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(OSR_MIGRATION_END))); - link(new MonitorEnterStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(MONITORENTER))); - link(new MonitorExitStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(MONITOREXIT))); - link(new CreateNullPointerExceptionStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(CREATE_NULL_POINTER_EXCEPTION))); - link(new CreateOutOfBoundsExceptionStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(CREATE_OUT_OF_BOUNDS_EXCEPTION))); link(new LogPrimitiveStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(LOG_PRIMITIVE))); link(new LogObjectStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(LOG_OBJECT))); link(new LogPrintfStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(LOG_PRINTF))); @@ -587,15 +531,20 @@ link(new WriteBarrierPreStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(WRITE_BARRIER_PRE))); link(new WriteBarrierPostStub(this, replacements, graalRuntime.getTarget(), runtimeCalls.get(WRITE_BARRIER_POST))); - CompilerToVM c2vm = graalRuntime.getCompilerToVM(); - link(new RuntimeCallStub(config.identityHashCodeAddress, IDENTITY_HASHCODE, true, this, replacements, globalStubRegConfig, c2vm)); + linkRuntimeCall(IDENTITY_HASHCODE, config.identityHashCodeAddress, replacements); + linkRuntimeCall(REGISTER_FINALIZER, config.registerFinalizerAddress, replacements); + linkRuntimeCall(CREATE_NULL_POINTER_EXCEPTION, config.createNullPointerExceptionAddress, replacements); + linkRuntimeCall(CREATE_OUT_OF_BOUNDS_EXCEPTION, config.createOutOfBoundsExceptionAddress, replacements); + linkRuntimeCall(MONITORENTER, config.monitorenterAddress, replacements); + linkRuntimeCall(MONITOREXIT, config.monitorexitAddress, replacements); } private static void link(Stub stub) { stub.getLinkage().setStub(stub); } - private void link(RuntimeCallStub stub) { + private void linkRuntimeCall(Descriptor descriptor, long address, Replacements replacements) { + RuntimeCallStub stub = new RuntimeCallStub(address, descriptor, true, this, replacements, globalStubRegConfig, graalRuntime.getCompilerToVM()); HotSpotRuntimeCallTarget linkage = stub.getLinkage(); HotSpotRuntimeCallTarget targetLinkage = stub.getTargetLinkage(); linkage.setStub(stub); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/MonitorEnterStubCall.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/MonitorEnterStubCall.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/MonitorEnterStubCall.java Mon May 13 22:57:50 2013 +0200 @@ -31,7 +31,7 @@ import com.oracle.graal.word.*; /** - * Node implementing a call to HotSpot's {@code graal_monitorenter} stub. + * Node implementing a call to {@code GraalRuntime::monitorenter}. */ public class MonitorEnterStubCall extends DeoptimizingStubCall implements LIRGenLowerable { @@ -52,5 +52,5 @@ } @NodeIntrinsic - public static native void call(Object hub, Word lock); + public static native void call(Object object, Word lock); } diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/MonitorExitStubCall.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/MonitorExitStubCall.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/MonitorExitStubCall.java Mon May 13 22:57:50 2013 +0200 @@ -32,7 +32,7 @@ import com.oracle.graal.word.*; /** - * Node implementing a call to HotSpot's {@code graal_monitorexit} stub. + * Node implementing a call to {@code GraalRuntime::monitorexit}. */ public class MonitorExitStubCall extends DeoptimizingStubCall implements LIRGenLowerable { @@ -56,5 +56,5 @@ } @NodeIntrinsic - public static native void call(Object hub, @ConstantNodeParameter int lockDepth); + public static native void call(Object object, @ConstantNodeParameter int lockDepth); } diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/CreateNullPointerExceptionStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/CreateNullPointerExceptionStub.java Mon May 13 21:59:17 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2012, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.stubs; - -import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.code.RuntimeCallTarget.*; -import com.oracle.graal.graph.Node.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.replacements.*; -import com.oracle.graal.word.*; - -/** - * Stub called to create a {@link NullPointerException}. - */ -public class CreateNullPointerExceptionStub extends CRuntimeStub { - - public CreateNullPointerExceptionStub(final HotSpotRuntime runtime, Replacements replacements, TargetDescription target, HotSpotRuntimeCallTarget linkage) { - super(runtime, replacements, target, linkage); - } - - @Snippet - private static Object createNullPointerException() { - createNullPointerExceptionC(CREATE_NULL_POINTER_EXCEPTION_C, thread()); - StubUtil.handlePendingException(true); - return StubUtil.verifyObject(getAndClearObjectResult(thread())); - } - - public static final Descriptor CREATE_NULL_POINTER_EXCEPTION_C = StubUtil.descriptorFor(CreateNullPointerExceptionStub.class, "createNullPointerExceptionC", false); - - @NodeIntrinsic(CRuntimeCall.class) - public static native void createNullPointerExceptionC(@ConstantNodeParameter Descriptor createNullPointerExceptionC, Word thread); - -} diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/CreateOutOfBoundsExceptionStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/CreateOutOfBoundsExceptionStub.java Mon May 13 21:59:17 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2012, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.stubs; - -import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.code.RuntimeCallTarget.*; -import com.oracle.graal.graph.Node.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.replacements.*; -import com.oracle.graal.word.*; - -/** - * Stub called to create a {@link ArrayIndexOutOfBoundsException}. - */ -public class CreateOutOfBoundsExceptionStub extends CRuntimeStub { - - public CreateOutOfBoundsExceptionStub(final HotSpotRuntime runtime, Replacements replacements, TargetDescription target, HotSpotRuntimeCallTarget linkage) { - super(runtime, replacements, target, linkage); - } - - @Snippet - private static Object createOutOfBoundsException(int index) { - createOutOfBoundsExceptionC(CREATE_OUT_OF_BOUNDS_C, thread(), index); - StubUtil.handlePendingException(true); - return StubUtil.verifyObject(getAndClearObjectResult(thread())); - } - - public static final Descriptor CREATE_OUT_OF_BOUNDS_C = StubUtil.descriptorFor(CreateOutOfBoundsExceptionStub.class, "createOutOfBoundsExceptionC", false); - - @NodeIntrinsic(CRuntimeCall.class) - public static native void createOutOfBoundsExceptionC(@ConstantNodeParameter Descriptor createOutOfBoundsExceptionC, Word thread, int index); - -} diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ExceptionHandlerStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ExceptionHandlerStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ExceptionHandlerStub.java Mon May 13 22:57:50 2013 +0200 @@ -25,6 +25,7 @@ import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; import static com.oracle.graal.hotspot.nodes.PatchReturnAddressNode.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.code.*; @@ -70,11 +71,11 @@ writeExceptionOop(thread(), exception); writeExceptionPc(thread(), exceptionPc); if (logging()) { - StubUtil.printf("handling exception %p (", Word.fromObject(exception).rawValue()); - StubUtil.decipher(Word.fromObject(exception).rawValue()); - StubUtil.printf(") at %p (", Word.fromObject(exception).rawValue(), exceptionPc.rawValue()); - StubUtil.decipher(exceptionPc.rawValue()); - StubUtil.printf(")\n"); + printf("handling exception %p (", Word.fromObject(exception).rawValue()); + decipher(Word.fromObject(exception).rawValue()); + printf(") at %p (", Word.fromObject(exception).rawValue(), exceptionPc.rawValue()); + decipher(exceptionPc.rawValue()); + printf(")\n"); } // patch throwing pc into return address so that deoptimization finds the right debug info @@ -83,9 +84,9 @@ Word handlerPc = exceptionHandlerForPc(EXCEPTION_HANDLER_FOR_PC, thread()); if (logging()) { - StubUtil.printf("handler for exception %p at %p is at %p (", Word.fromObject(exception).rawValue(), exceptionPc.rawValue(), handlerPc.rawValue()); - StubUtil.decipher(handlerPc.rawValue()); - StubUtil.printf(")\n"); + printf("handler for exception %p at %p is at %p (", Word.fromObject(exception).rawValue(), exceptionPc.rawValue(), handlerPc.rawValue()); + decipher(handlerPc.rawValue()); + printf(")\n"); } // patch the return address so that this stub returns to the exception handler @@ -96,18 +97,18 @@ if (enabled) { Object currentException = readExceptionOop(thread()); if (currentException != null) { - StubUtil.fatal("exception object in thread must be null, not %p", Word.fromObject(currentException).rawValue()); + fatal("exception object in thread must be null, not %p", Word.fromObject(currentException).rawValue()); } Word currentExceptionPc = readExceptionPc(thread()); if (currentExceptionPc.notEqual(Word.zero())) { - StubUtil.fatal("exception PC in thread must be zero, not %p", currentExceptionPc.rawValue()); + fatal("exception PC in thread must be zero, not %p", currentExceptionPc.rawValue()); } } } static void checkExceptionNotNull(boolean enabled, Object exception) { if (enabled && exception == null) { - StubUtil.fatal("exception must not be null"); + fatal("exception must not be null"); } } @@ -124,7 +125,7 @@ return enabled || graalRuntime().getConfig().cAssertions; } - public static final Descriptor EXCEPTION_HANDLER_FOR_PC = StubUtil.descriptorFor(ExceptionHandlerStub.class, "exceptionHandlerForPc", false); + public static final Descriptor EXCEPTION_HANDLER_FOR_PC = descriptorFor(ExceptionHandlerStub.class, "exceptionHandlerForPc", false); @NodeIntrinsic(value = CRuntimeCall.class, setStampFromReturnType = true) public static native Word exceptionHandlerForPc(@ConstantNodeParameter Descriptor exceptionHandlerForPc, Word thread); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/LogObjectStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/LogObjectStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/LogObjectStub.java Mon May 13 22:57:50 2013 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.stubs; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.code.*; @@ -49,7 +50,7 @@ logObjectC(LOG_OBJECT_C, thread(), object, flags); } - public static final Descriptor LOG_OBJECT_C = StubUtil.descriptorFor(LogObjectStub.class, "logObjectC", false); + public static final Descriptor LOG_OBJECT_C = descriptorFor(LogObjectStub.class, "logObjectC", false); @NodeIntrinsic(CRuntimeCall.class) public static native void logObjectC(@ConstantNodeParameter Descriptor logObjectC, Word thread, Object object, int flags); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/LogPrimitiveStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/LogPrimitiveStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/LogPrimitiveStub.java Mon May 13 22:57:50 2013 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.stubs; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.code.*; @@ -49,7 +50,7 @@ logPrimitivefC(LOG_PRIMITIVE_C, thread(), typeChar, value, newline); } - public static final Descriptor LOG_PRIMITIVE_C = StubUtil.descriptorFor(LogPrimitiveStub.class, "logPrimitivefC", false); + public static final Descriptor LOG_PRIMITIVE_C = descriptorFor(LogPrimitiveStub.class, "logPrimitivefC", false); @NodeIntrinsic(CRuntimeCall.class) public static native void logPrimitivefC(@ConstantNodeParameter Descriptor logPrimitivefC, Word thread, char typeChar, long value, boolean newline); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/LogPrintfStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/LogPrintfStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/LogPrintfStub.java Mon May 13 22:57:50 2013 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.stubs; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.code.*; @@ -49,7 +50,7 @@ logPrintfC(LOG_PRINTF_C, thread(), format, v1, v2, v3); } - public static final Descriptor LOG_PRINTF_C = StubUtil.descriptorFor(LogPrintfStub.class, "logPrintfC", false); + public static final Descriptor LOG_PRINTF_C = descriptorFor(LogPrintfStub.class, "logPrintfC", false); @NodeIntrinsic(CRuntimeCall.class) public static native void logPrintfC(@ConstantNodeParameter Descriptor logPrintfC, Word thread, String format, long v1, long v2, long v3); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/MonitorEnterStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/MonitorEnterStub.java Mon May 13 21:59:17 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2012, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.stubs; - -import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; - -import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; -import com.oracle.graal.api.code.*; -import com.oracle.graal.graph.Node.ConstantNodeParameter; -import com.oracle.graal.graph.Node.NodeIntrinsic; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.replacements.*; -import com.oracle.graal.word.*; - -/** - * Stub called from {@link MonitorEnterStubCall}. - */ -public class MonitorEnterStub extends CRuntimeStub { - - public MonitorEnterStub(final HotSpotRuntime runtime, Replacements replacements, TargetDescription target, HotSpotRuntimeCallTarget linkage) { - super(runtime, replacements, target, linkage); - } - - @Snippet - private static void monitorenter(Object object, Word lock) { - monitorenterC(MONITORENTER_C, thread(), object, lock); - StubUtil.handlePendingException(false); - } - - public static final Descriptor MONITORENTER_C = StubUtil.descriptorFor(MonitorEnterStub.class, "monitorenterC", false); - - @NodeIntrinsic(CRuntimeCall.class) - public static native void monitorenterC(@ConstantNodeParameter Descriptor monitorenterC, Word thread, Object object, Word lock); -} diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/MonitorExitStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/MonitorExitStub.java Mon May 13 21:59:17 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2012, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.stubs; - -import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; - -import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; -import com.oracle.graal.api.code.*; -import com.oracle.graal.graph.Node.ConstantNodeParameter; -import com.oracle.graal.graph.Node.NodeIntrinsic; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.replacements.*; -import com.oracle.graal.word.*; - -/** - * Stub called from {@link MonitorExitStubCall}. - */ -public class MonitorExitStub extends CRuntimeStub { - - public MonitorExitStub(final HotSpotRuntime runtime, Replacements replacements, TargetDescription target, HotSpotRuntimeCallTarget linkage) { - super(runtime, replacements, target, linkage); - } - - @Snippet - private static void monitorexit(Object object, Word lock) { - monitorexitC(MONITOREXIT_C, thread(), object, lock); - } - - public static final Descriptor MONITOREXIT_C = StubUtil.descriptorFor(MonitorExitStub.class, "monitorexitC", false); - - @NodeIntrinsic(CRuntimeCall.class) - public static native void monitorexitC(@ConstantNodeParameter Descriptor monitorexitC, Word thread, Object object, Word lock); -} diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java Mon May 13 22:57:50 2013 +0200 @@ -22,24 +22,25 @@ */ package com.oracle.graal.hotspot.stubs; -import static com.oracle.graal.api.code.DeoptimizationAction.*; -import static com.oracle.graal.api.meta.DeoptimizationReason.*; import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; import static com.oracle.graal.hotspot.replacements.NewObjectSnippets.*; import static com.oracle.graal.hotspot.stubs.NewInstanceStub.*; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; -import com.oracle.graal.graph.Node.*; +import com.oracle.graal.graph.Node.ConstantNodeParameter; +import com.oracle.graal.graph.Node.NodeIntrinsic; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.hotspot.nodes.*; import com.oracle.graal.hotspot.replacements.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.replacements.*; -import com.oracle.graal.replacements.Snippet.*; +import com.oracle.graal.replacements.Snippet.ConstantParameter; +import com.oracle.graal.replacements.Snippet.Fold; import com.oracle.graal.replacements.SnippetTemplate.Arguments; import com.oracle.graal.replacements.SnippetTemplate.SnippetInfo; import com.oracle.graal.word.*; @@ -94,10 +95,10 @@ int elementKind = (layoutHelper >> layoutHelperElementTypeShift()) & layoutHelperElementTypeMask(); int sizeInBytes = computeArrayAllocationSize(length, wordSize(), headerSize, log2ElementSize); if (logging()) { - StubUtil.printf("newArray: element kind %d\n", elementKind); - StubUtil.printf("newArray: array length %d\n", length); - StubUtil.printf("newArray: array size %d\n", sizeInBytes); - StubUtil.printf("newArray: hub=%p\n", hub.rawValue()); + printf("newArray: element kind %d\n", elementKind); + printf("newArray: array length %d\n", length); + printf("newArray: array size %d\n", sizeInBytes); + printf("newArray: hub=%p\n", hub.rawValue()); } // check that array length is small enough for fast path. @@ -105,29 +106,22 @@ Word memory = refillAllocate(intArrayHub, sizeInBytes, logging()); if (memory.notEqual(0)) { if (logging()) { - StubUtil.printf("newArray: allocated new array at %p\n", memory.rawValue()); + printf("newArray: allocated new array at %p\n", memory.rawValue()); } formatArray(hub, sizeInBytes, length, headerSize, memory, Word.unsigned(arrayPrototypeMarkWord()), true); - return StubUtil.verifyObject(memory.toObject()); + return verifyObject(memory.toObject()); } } if (logging()) { - StubUtil.printf("newArray: calling new_array_c\n"); + printf("newArray: calling new_array_c\n"); } newArrayC(NEW_ARRAY_C, thread(), hub, length); - - if (clearPendingException(thread())) { - if (logging()) { - StubUtil.printf("newArray: deoptimizing to caller\n"); - } - getAndClearObjectResult(thread()); - DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint); - } - return StubUtil.verifyObject(getAndClearObjectResult(thread())); + handlePendingException(true); + return verifyObject(getAndClearObjectResult(thread())); } - public static final Descriptor NEW_ARRAY_C = StubUtil.descriptorFor(NewArrayStub.class, "newArrayC", false); + public static final Descriptor NEW_ARRAY_C = descriptorFor(NewArrayStub.class, "newArrayC", false); @NodeIntrinsic(CRuntimeCall.class) public static native void newArrayC(@ConstantNodeParameter Descriptor newArrayC, Word thread, Word hub, int length); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java Mon May 13 22:57:50 2013 +0200 @@ -22,12 +22,11 @@ */ package com.oracle.graal.hotspot.stubs; -import static com.oracle.graal.api.code.DeoptimizationAction.*; -import static com.oracle.graal.api.meta.DeoptimizationReason.*; import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; import static com.oracle.graal.hotspot.nodes.DirectCompareAndSwapNode.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; import static com.oracle.graal.hotspot.replacements.NewObjectSnippets.*; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.code.*; @@ -98,25 +97,18 @@ for (int offset = 2 * wordSize(); offset < sizeInBytes; offset += wordSize()) { memory.writeWord(offset, Word.zero(), ANY_LOCATION); } - return StubUtil.verifyObject(memory.toObject()); + return verifyObject(memory.toObject()); } } } if (logging()) { - StubUtil.printf("newInstance: calling new_instance_c\n"); + printf("newInstance: calling new_instance_c\n"); } newInstanceC(NEW_INSTANCE_C, thread(), hub); - - if (clearPendingException(thread())) { - if (logging()) { - StubUtil.printf("newInstance: deoptimizing to caller\n"); - } - getAndClearObjectResult(thread()); - DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint); - } - return StubUtil.verifyObject(getAndClearObjectResult(thread())); + handlePendingException(true); + return verifyObject(getAndClearObjectResult(thread())); } /** @@ -143,10 +135,10 @@ Word tlabFreeSpaceInBytes = end.subtract(top); if (log) { - StubUtil.printf("refillTLAB: thread=%p\n", thread.rawValue()); - StubUtil.printf("refillTLAB: top=%p\n", top.rawValue()); - StubUtil.printf("refillTLAB: end=%p\n", end.rawValue()); - StubUtil.printf("refillTLAB: tlabFreeSpaceInBytes=%d\n", tlabFreeSpaceInBytes.rawValue()); + printf("refillTLAB: thread=%p\n", thread.rawValue()); + printf("refillTLAB: top=%p\n", top.rawValue()); + printf("refillTLAB: end=%p\n", end.rawValue()); + printf("refillTLAB: tlabFreeSpaceInBytes=%d\n", tlabFreeSpaceInBytes.rawValue()); } Word tlabFreeSpaceInWords = tlabFreeSpaceInBytes.unsignedShiftRight(log2WordSize()); @@ -159,12 +151,12 @@ // increment number of refills thread.writeInt(tlabNumberOfRefillsOffset(), thread.readInt(tlabNumberOfRefillsOffset(), TLAB_NOF_REFILLS_LOCATION) + 1, TLAB_NOF_REFILLS_LOCATION); if (log) { - StubUtil.printf("thread: %p -- number_of_refills %d\n", thread.rawValue(), thread.readInt(tlabNumberOfRefillsOffset(), TLAB_NOF_REFILLS_LOCATION)); + printf("thread: %p -- number_of_refills %d\n", thread.rawValue(), thread.readInt(tlabNumberOfRefillsOffset(), TLAB_NOF_REFILLS_LOCATION)); } // accumulate wastage Word wastage = thread.readWord(tlabFastRefillWasteOffset(), TLAB_FAST_REFILL_WASTE_LOCATION).add(tlabFreeSpaceInWords); if (log) { - StubUtil.printf("thread: %p -- accumulated wastage %d\n", thread.rawValue(), wastage.rawValue()); + printf("thread: %p -- accumulated wastage %d\n", thread.rawValue(), wastage.rawValue()); } thread.writeWord(tlabFastRefillWasteOffset(), wastage, TLAB_FAST_REFILL_WASTE_LOCATION); } @@ -202,7 +194,7 @@ Word newRefillWasteLimit = refillWasteLimit.add(tlabRefillWasteIncrement()); thread.writeWord(tlabRefillWasteLimitOffset(), newRefillWasteLimit, TLAB_REFILL_WASTE_LIMIT_LOCATION); if (log) { - StubUtil.printf("refillTLAB: retaining TLAB - newRefillWasteLimit=%p\n", newRefillWasteLimit.rawValue()); + printf("refillTLAB: retaining TLAB - newRefillWasteLimit=%p\n", newRefillWasteLimit.rawValue()); } if (tlabStats()) { @@ -247,7 +239,7 @@ return Boolean.getBoolean("graal.newInstanceStub.forceSlowPath"); } - public static final Descriptor NEW_INSTANCE_C = StubUtil.descriptorFor(NewInstanceStub.class, "newInstanceC", false); + public static final Descriptor NEW_INSTANCE_C = descriptorFor(NewInstanceStub.class, "newInstanceC", false); @NodeIntrinsic(CRuntimeCall.class) public static native void newInstanceC(@ConstantNodeParameter Descriptor newInstanceC, Word thread, Word hub); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewMultiArrayStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewMultiArrayStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewMultiArrayStub.java Mon May 13 22:57:50 2013 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.stubs; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.code.*; @@ -47,11 +48,11 @@ @Snippet private static Object newMultiArray(Word hub, int rank, Word dims) { newMultiArrayC(NEW_MULTI_ARRAY_C, thread(), hub, rank, dims); - StubUtil.handlePendingException(true); - return getAndClearObjectResult(thread()); + handlePendingException(true); + return verifyObject(getAndClearObjectResult(thread())); } - public static final Descriptor NEW_MULTI_ARRAY_C = StubUtil.descriptorFor(NewMultiArrayStub.class, "newMultiArrayC", false); + public static final Descriptor NEW_MULTI_ARRAY_C = descriptorFor(NewMultiArrayStub.class, "newMultiArrayC", false); @NodeIntrinsic(CRuntimeCall.class) public static native void newMultiArrayC(@ConstantNodeParameter Descriptor newArrayC, Word thread, Word hub, int rank, Word dims); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/OSRMigrationEndStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/OSRMigrationEndStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/OSRMigrationEndStub.java Mon May 13 22:57:50 2013 +0200 @@ -22,6 +22,8 @@ */ package com.oracle.graal.hotspot.stubs; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; + import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.code.*; import com.oracle.graal.graph.Node.ConstantNodeParameter; @@ -48,7 +50,7 @@ osrMigrationEndC(OSR_MIGRATION_END_C, buffer); } - public static final Descriptor OSR_MIGRATION_END_C = StubUtil.descriptorFor(OSRMigrationEndStub.class, "osrMigrationEndC", false); + public static final Descriptor OSR_MIGRATION_END_C = descriptorFor(OSRMigrationEndStub.class, "osrMigrationEndC", false); @NodeIntrinsic(CRuntimeCall.class) public static native void osrMigrationEndC(@ConstantNodeParameter Descriptor osrMigrationEndC, Word buffer); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/RegisterFinalizerStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/RegisterFinalizerStub.java Mon May 13 21:59:17 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2012, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.stubs; - -import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; - -import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; -import com.oracle.graal.api.code.*; -import com.oracle.graal.graph.Node.ConstantNodeParameter; -import com.oracle.graal.graph.Node.NodeIntrinsic; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.nodes.java.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.replacements.*; -import com.oracle.graal.word.*; - -/** - * Stub called from {@link RegisterFinalizerNode}. - */ -public class RegisterFinalizerStub extends CRuntimeStub { - - public RegisterFinalizerStub(final HotSpotRuntime runtime, Replacements replacements, TargetDescription target, HotSpotRuntimeCallTarget linkage) { - super(runtime, replacements, target, linkage); - } - - @Snippet - private static void registerFinalizer(Object object) { - registerFinalizerC(REGISTER_FINALIZER_C, thread(), object); - StubUtil.handlePendingException(false); - } - - public static final Descriptor REGISTER_FINALIZER_C = StubUtil.descriptorFor(RegisterFinalizerStub.class, "registerFinalizerC", false); - - @NodeIntrinsic(CRuntimeCall.class) - public static native void registerFinalizerC(@ConstantNodeParameter Descriptor registerFinalizerC, Word thread, Object object); -} diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/RuntimeCallStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/RuntimeCallStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/RuntimeCallStub.java Mon May 13 22:57:50 2013 +0200 @@ -25,7 +25,7 @@ import static com.oracle.graal.api.meta.MetaUtil.*; import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; -import java.util.*; +import java.lang.reflect.*; import com.oracle.graal.api.code.*; import com.oracle.graal.api.code.CallingConvention.Type; @@ -37,6 +37,7 @@ import com.oracle.graal.hotspot.bridge.*; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.hotspot.nodes.*; +import com.oracle.graal.hotspot.replacements.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.java.*; import com.oracle.graal.nodes.java.MethodCallTargetNode.InvokeKind; @@ -49,7 +50,7 @@ import com.oracle.graal.word.phases.*; /** - * Base class for a stub that calls into a HotSpot C/C++ runtime function using the native + * A stub that calls into a HotSpot C/C++ runtime function using the native * {@link CallingConvention}. */ public class RuntimeCallStub extends Stub { @@ -97,7 +98,11 @@ Class[] argumentTypes = d.getArgumentTypes(); JavaType[] parameterTypes = new JavaType[argumentTypes.length]; for (int i = 0; i < parameterTypes.length; ++i) { - parameterTypes[i] = runtime.lookupJavaType(argumentTypes[i]); + if (WordBase.class.isAssignableFrom(argumentTypes[i])) { + parameterTypes[i] = runtime.lookupJavaType(wordKind().toJavaClass()); + } else { + parameterTypes[i] = runtime.lookupJavaType(argumentTypes[i]); + } } TargetDescription target = graalRuntime().getTarget(); JavaType returnType = runtime.lookupJavaType(d.getResultType()); @@ -149,96 +154,121 @@ }; } + static class GraphBuilder { + + public GraphBuilder(Stub stub) { + this.graph = new StructuredGraph(stub.toString(), null); + graph.replaceFixed(graph.start(), graph.add(new StubStartNode(stub))); + this.lastFixedNode = graph.start(); + } + + final StructuredGraph graph; + private FixedWithNextNode lastFixedNode; + + T add(T node) { + T result = graph.add(node); + assert node == result; + if (result instanceof FixedNode) { + assert lastFixedNode != null; + FixedNode fixed = (FixedNode) result; + assert fixed.predecessor() == null; + graph.addAfterFixed(lastFixedNode, fixed); + if (fixed instanceof FixedWithNextNode) { + lastFixedNode = (FixedWithNextNode) fixed; + } else { + lastFixedNode = null; + } + } + return result; + } + } + @Override protected StructuredGraph getGraph() { Class[] args = linkage.getDescriptor().getArgumentTypes(); - LocalNode[] locals = new LocalNode[args.length]; + boolean isObjectResult = linkage.getCallingConvention().getReturn().getKind() == Kind.Object; + + GraphBuilder builder = new GraphBuilder(this); + + LocalNode[] locals = createLocals(builder, args); + + ReadRegisterNode thread = prependThread || isObjectResult ? builder.add(new ReadRegisterNode(runtime.threadRegister(), true, false)) : null; + ValueNode result = createTargetCall(builder, locals, thread); + createInvoke(builder, StubUtil.class, "handlePendingException", ConstantNode.forBoolean(isObjectResult, builder.graph)); + if (isObjectResult) { + InvokeNode object = createInvoke(builder, HotSpotReplacementsUtil.class, "getAndClearObjectResult", thread); + result = createInvoke(builder, StubUtil.class, "verifyObject", object); + } + builder.add(new ReturnNode(linkage.descriptor.getResultType() == void.class ? null : result)); - StructuredGraph graph = new StructuredGraph(toString(), null); - StubStartNode start = graph.add(new StubStartNode(this)); - graph.replaceFixed(graph.start(), start); + if (Debug.isDumpEnabled()) { + Debug.dump(builder.graph, "Initial stub graph"); + } + + for (InvokeNode invoke : builder.graph.getNodes(InvokeNode.class).snapshot()) { + inline(invoke); + } + assert builder.graph.getNodes(InvokeNode.class).isEmpty(); + if (Debug.isDumpEnabled()) { + Debug.dump(builder.graph, "Stub graph before compilation"); + } + + return builder.graph; + } + + private LocalNode[] createLocals(GraphBuilder builder, Class[] args) { + LocalNode[] locals = new LocalNode[args.length]; ResolvedJavaType accessingClass = runtime.lookupJavaType(getClass()); for (int i = 0; i < args.length; i++) { - JavaType type = runtime.lookupJavaType(args[i]).resolve(accessingClass); + ResolvedJavaType type = runtime.lookupJavaType(args[i]).resolve(accessingClass); Kind kind = type.getKind().getStackKind(); Stamp stamp; if (kind == Kind.Object) { - stamp = StampFactory.declared((ResolvedJavaType) type); + stamp = StampFactory.declared(type); } else { stamp = StampFactory.forKind(kind); } - LocalNode local = graph.unique(new LocalNode(i, stamp)); + LocalNode local = builder.add(new LocalNode(i, stamp)); locals[i] = local; } - - // Create target call - CRuntimeCall call = createTargetCall(locals, graph, start); - - // Create call to handlePendingException - ResolvedJavaMethod hpeMethod = resolveMethod(StubUtil.class, "handlePendingException", boolean.class); - JavaType returnType = hpeMethod.getSignature().getReturnType(null); - ValueNode[] hpeArgs = {ConstantNode.forBoolean(linkage.getCallingConvention().getReturn().getKind() == Kind.Object, graph)}; - MethodCallTargetNode hpeTarget = graph.add(new MethodCallTargetNode(InvokeKind.Static, hpeMethod, hpeArgs, returnType)); - InvokeNode hpeInvoke = graph.add(new InvokeNode(hpeTarget, FrameState.UNKNOWN_BCI)); - List emptyStack = Collections.emptyList(); - hpeInvoke.setStateAfter(graph.add(new FrameState(null, FrameState.INVALID_FRAMESTATE_BCI, new ValueNode[0], emptyStack, new ValueNode[0], false, false))); - graph.addAfterFixed(call, hpeInvoke); - - // Create return node - ReturnNode ret = graph.add(new ReturnNode(linkage.descriptor.getResultType() == void.class ? null : call)); - graph.addAfterFixed(hpeInvoke, ret); - - if (Debug.isDumpEnabled()) { - Debug.dump(graph, "Initial stub graph"); - } - - // Inline call to handlePendingException - inline(hpeInvoke); - - if (Debug.isDumpEnabled()) { - Debug.dump(graph, "Stub graph before compilation"); - } - - return graph; + return locals; } - private CRuntimeCall createTargetCall(LocalNode[] locals, StructuredGraph graph, StubStartNode start) { - CRuntimeCall call; - ValueNode[] targetArguments; + private InvokeNode createInvoke(GraphBuilder builder, Class declaringClass, String name, ValueNode... hpeArgs) { + ResolvedJavaMethod method = null; + for (Method m : declaringClass.getDeclaredMethods()) { + if (Modifier.isStatic(m.getModifiers()) && m.getName().equals(name)) { + assert method == null : "found more than one method in " + declaringClass + " named " + name; + method = runtime.lookupJavaMethod(m); + } + } + assert method != null : "did not find method in " + declaringClass + " named " + name; + JavaType returnType = method.getSignature().getReturnType(null); + MethodCallTargetNode callTarget = builder.add(new MethodCallTargetNode(InvokeKind.Static, method, hpeArgs, returnType)); + InvokeNode invoke = builder.add(new InvokeNode(callTarget, FrameState.UNKNOWN_BCI)); + return invoke; + } + + private CRuntimeCall createTargetCall(GraphBuilder builder, LocalNode[] locals, ReadRegisterNode thread) { if (prependThread) { - ReadRegisterNode thread = graph.add(new ReadRegisterNode(runtime.threadRegister(), true, false)); - graph.addAfterFixed(start, thread); - targetArguments = new ValueNode[1 + locals.length]; + ValueNode[] targetArguments = new ValueNode[1 + locals.length]; targetArguments[0] = thread; System.arraycopy(locals, 0, targetArguments, 1, locals.length); - call = graph.add(new CRuntimeCall(target.descriptor, targetArguments)); - graph.addAfterFixed(thread, call); + return builder.add(new CRuntimeCall(target.descriptor, targetArguments)); } else { - targetArguments = new ValueNode[locals.length]; - System.arraycopy(locals, 0, targetArguments, 0, locals.length); - call = graph.add(new CRuntimeCall(target.descriptor, targetArguments)); - graph.addAfterFixed(start, call); + return builder.add(new CRuntimeCall(target.descriptor, locals)); } - return call; } private void inline(InvokeNode invoke) { StructuredGraph graph = invoke.graph(); ResolvedJavaMethod method = ((MethodCallTargetNode) invoke.callTarget()).targetMethod(); ReplacementsImpl repl = new ReplacementsImpl(runtime, new Assumptions(false), runtime.getTarget()); - StructuredGraph hpeGraph = repl.makeGraph(method, null, null); - InliningUtil.inline(invoke, hpeGraph, false); + StructuredGraph calleeGraph = repl.makeGraph(method, null, null); + InliningUtil.inline(invoke, calleeGraph, false); new NodeIntrinsificationPhase(runtime).apply(graph); new WordTypeRewriterPhase(runtime, wordKind()).apply(graph); new DeadCodeEliminationPhase().apply(graph); } - - private ResolvedJavaMethod resolveMethod(Class declaringClass, String name, Class... parameterTypes) { - try { - return runtime.lookupJavaMethod(declaringClass.getDeclaredMethod(name, parameterTypes)); - } catch (Exception e) { - throw new GraalInternalError(e); - } - } } diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ThreadIsInterruptedStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ThreadIsInterruptedStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ThreadIsInterruptedStub.java Mon May 13 22:57:50 2013 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.stubs; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.code.*; @@ -47,11 +48,11 @@ @Snippet private static boolean threadIsInterrupted(Thread receiverThread, boolean clearIsInterrupted) { boolean result = threadIsInterruptedC(THREAD_IS_INTERRUPTED_C, thread(), receiverThread, clearIsInterrupted); - StubUtil.handlePendingException(false); + handlePendingException(false); return result; } - public static final Descriptor THREAD_IS_INTERRUPTED_C = StubUtil.descriptorFor(ThreadIsInterruptedStub.class, "threadIsInterruptedC", false); + public static final Descriptor THREAD_IS_INTERRUPTED_C = descriptorFor(ThreadIsInterruptedStub.class, "threadIsInterruptedC", false); @NodeIntrinsic(CRuntimeCall.class) public static native boolean threadIsInterruptedC(@ConstantNodeParameter Descriptor threadIsInterruptedC, Word thread, Thread receiverThread, boolean clearIsInterrupted); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/UnwindExceptionToCallerStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/UnwindExceptionToCallerStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/UnwindExceptionToCallerStub.java Mon May 13 22:57:50 2013 +0200 @@ -26,6 +26,7 @@ import static com.oracle.graal.hotspot.nodes.JumpToExceptionHandlerInCallerNode.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; import static com.oracle.graal.hotspot.stubs.ExceptionHandlerStub.*; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.code.*; @@ -63,11 +64,11 @@ private static void unwindExceptionToCaller(Object exception, Word returnAddress) { Pointer exceptionOop = Word.fromObject(exception); if (logging()) { - StubUtil.printf("unwinding exception %p (", exceptionOop.rawValue()); - StubUtil.decipher(exceptionOop.rawValue()); - StubUtil.printf(") at %p (", exceptionOop.rawValue(), returnAddress.rawValue()); - StubUtil.decipher(returnAddress.rawValue()); - StubUtil.printf(")\n"); + printf("unwinding exception %p (", exceptionOop.rawValue()); + decipher(exceptionOop.rawValue()); + printf(") at %p (", exceptionOop.rawValue(), returnAddress.rawValue()); + decipher(returnAddress.rawValue()); + printf(")\n"); } checkNoExceptionInThread(assertionsEnabled()); checkExceptionNotNull(assertionsEnabled(), exception); @@ -75,9 +76,9 @@ Word handlerInCallerPc = exceptionHandlerForReturnAddress(EXCEPTION_HANDLER_FOR_RETURN_ADDRESS, thread(), returnAddress); if (logging()) { - StubUtil.printf("handler for exception %p at return address %p is at %p (", exceptionOop.rawValue(), returnAddress.rawValue(), handlerInCallerPc.rawValue()); - StubUtil.decipher(handlerInCallerPc.rawValue()); - StubUtil.printf(")\n"); + printf("handler for exception %p at return address %p is at %p (", exceptionOop.rawValue(), returnAddress.rawValue(), handlerInCallerPc.rawValue()); + decipher(handlerInCallerPc.rawValue()); + printf(")\n"); } jumpToExceptionHandlerInCaller(handlerInCallerPc, exception, returnAddress); @@ -96,7 +97,7 @@ return enabled || graalRuntime().getConfig().cAssertions; } - public static final Descriptor EXCEPTION_HANDLER_FOR_RETURN_ADDRESS = StubUtil.descriptorFor(UnwindExceptionToCallerStub.class, "exceptionHandlerForReturnAddress", false); + public static final Descriptor EXCEPTION_HANDLER_FOR_RETURN_ADDRESS = descriptorFor(UnwindExceptionToCallerStub.class, "exceptionHandlerForReturnAddress", false); @NodeIntrinsic(value = CRuntimeCall.class, setStampFromReturnType = true) public static native Word exceptionHandlerForReturnAddress(@ConstantNodeParameter Descriptor exceptionHandlerForReturnAddress, Word thread, Word returnAddress); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/VMErrorStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/VMErrorStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/VMErrorStub.java Mon May 13 22:57:50 2013 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.stubs; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.code.*; @@ -49,7 +50,7 @@ vmErrorC(VM_ERROR_C, thread(), where, format, value); } - public static final Descriptor VM_ERROR_C = StubUtil.descriptorFor(VMErrorStub.class, "vmErrorC", false); + public static final Descriptor VM_ERROR_C = descriptorFor(VMErrorStub.class, "vmErrorC", false); @NodeIntrinsic(CRuntimeCall.class) public static native void vmErrorC(@ConstantNodeParameter Descriptor vmErrorC, Word thread, String where, String format, long value); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/VerifyOopStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/VerifyOopStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/VerifyOopStub.java Mon May 13 22:57:50 2013 +0200 @@ -22,6 +22,8 @@ */ package com.oracle.graal.hotspot.stubs; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; + import com.oracle.graal.api.code.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.meta.*; @@ -40,6 +42,6 @@ @Snippet private static Object verifyOop(Object object) { - return StubUtil.verifyObject(object); + return verifyObject(object); } } diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/WriteBarrierPostStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/WriteBarrierPostStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/WriteBarrierPostStub.java Mon May 13 22:57:50 2013 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.stubs; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.code.*; @@ -49,7 +50,7 @@ writeBarrierPostC(WRITE_BARRIER_POST_C, thread(), object, card); } - public static final Descriptor WRITE_BARRIER_POST_C = StubUtil.descriptorFor(WriteBarrierPostStub.class, "writeBarrierPostC", false); + public static final Descriptor WRITE_BARRIER_POST_C = descriptorFor(WriteBarrierPostStub.class, "writeBarrierPostC", false); @NodeIntrinsic(CRuntimeCall.class) public static native void writeBarrierPostC(@ConstantNodeParameter Descriptor vmErrorC, Word thread, Object object, Word card); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/WriteBarrierPreStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/WriteBarrierPreStub.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/WriteBarrierPreStub.java Mon May 13 22:57:50 2013 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.stubs; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.hotspot.stubs.StubUtil.*; import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.code.*; @@ -49,7 +50,7 @@ writeBarrierPreC(WRITE_BARRIER_PRE_C, thread(), object); } - public static final Descriptor WRITE_BARRIER_PRE_C = StubUtil.descriptorFor(WriteBarrierPreStub.class, "writeBarrierPreC", false); + public static final Descriptor WRITE_BARRIER_PRE_C = descriptorFor(WriteBarrierPreStub.class, "writeBarrierPreC", false); @NodeIntrinsic(CRuntimeCall.class) public static native void writeBarrierPreC(@ConstantNodeParameter Descriptor vmErrorC, Word thread, Object object); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Mon May 13 22:57:50 2013 +0200 @@ -26,6 +26,7 @@ import static com.oracle.graal.api.code.TypeCheckHints.*; import static com.oracle.graal.api.meta.DeoptimizationReason.*; import static com.oracle.graal.bytecode.Bytecodes.*; +import static com.oracle.graal.java.GraphBuilderPhase.RuntimeCalls.*; import static java.lang.reflect.Modifier.*; import java.lang.reflect.*; @@ -940,7 +941,7 @@ ValueNode exception = ConstantNode.forObject(cachedNullPointerException, runtime, currentGraph); trueSucc.setNext(handleException(exception, bci())); } else { - RuntimeCallNode call = currentGraph.add(new RuntimeCallNode(RuntimeCalls.CREATE_NULL_POINTER_EXCEPTION)); + RuntimeCallNode call = currentGraph.add(new RuntimeCallNode(CREATE_NULL_POINTER_EXCEPTION)); call.setStateAfter(frameState.create(bci())); trueSucc.setNext(call); call.setNext(handleException(call, bci())); @@ -966,7 +967,7 @@ ValueNode exception = ConstantNode.forObject(cachedArrayIndexOutOfBoundsException, runtime, currentGraph); falseSucc.setNext(handleException(exception, bci())); } else { - RuntimeCallNode call = currentGraph.add(new RuntimeCallNode(RuntimeCalls.CREATE_OUT_OF_BOUNDS_EXCEPTION, index)); + RuntimeCallNode call = currentGraph.add(new RuntimeCallNode(CREATE_OUT_OF_BOUNDS_EXCEPTION, index)); call.setStateAfter(frameState.create(bci())); falseSucc.setNext(call); call.setNext(handleException(call, bci())); diff -r ed6202820ecf -r cd77bc78c409 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java Mon May 13 21:59:17 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java Mon May 13 22:57:50 2013 +0200 @@ -1161,7 +1161,7 @@ StructuredGraph graph = invoke.asNode().graph(); FrameState stateAfter = invoke.stateAfter(); - assert stateAfter.isAlive(); + assert stateAfter == null || stateAfter.isAlive(); IdentityHashMap replacements = new IdentityHashMap<>(); ArrayList nodes = new ArrayList<>(); @@ -1234,39 +1234,40 @@ } } - FrameState outerFrameState = null; - int callerLockDepth = stateAfter.nestedLockDepth(); - for (Node node : duplicates.values()) { - if (node instanceof FrameState) { - FrameState frameState = (FrameState) node; - assert frameState.bci != FrameState.BEFORE_BCI : frameState; - if (frameState.bci == FrameState.AFTER_BCI) { - frameState.replaceAndDelete(stateAfter); - } else if (frameState.bci == FrameState.AFTER_EXCEPTION_BCI) { - if (frameState.isAlive()) { - assert stateAtExceptionEdge != null; - frameState.replaceAndDelete(stateAtExceptionEdge); + if (stateAfter != null) { + FrameState outerFrameState = null; + int callerLockDepth = stateAfter.nestedLockDepth(); + for (Node node : duplicates.values()) { + if (node instanceof FrameState) { + FrameState frameState = (FrameState) node; + assert frameState.bci != FrameState.BEFORE_BCI : frameState; + if (frameState.bci == FrameState.AFTER_BCI) { + frameState.replaceAndDelete(stateAfter); + } else if (frameState.bci == FrameState.AFTER_EXCEPTION_BCI) { + if (frameState.isAlive()) { + assert stateAtExceptionEdge != null; + frameState.replaceAndDelete(stateAtExceptionEdge); + } else { + assert stateAtExceptionEdge == null; + } } else { - assert stateAtExceptionEdge == null; - } - } else { - // only handle the outermost frame states - if (frameState.outerFrameState() == null) { - assert frameState.bci == FrameState.INVALID_FRAMESTATE_BCI || frameState.method() == inlineGraph.method(); - if (outerFrameState == null) { - outerFrameState = stateAfter.duplicateModified(invoke.bci(), stateAfter.rethrowException(), invoke.asNode().kind()); - outerFrameState.setDuringCall(true); + // only handle the outermost frame states + if (frameState.outerFrameState() == null) { + assert frameState.bci == FrameState.INVALID_FRAMESTATE_BCI || frameState.method() == inlineGraph.method(); + if (outerFrameState == null) { + outerFrameState = stateAfter.duplicateModified(invoke.bci(), stateAfter.rethrowException(), invoke.asNode().kind()); + outerFrameState.setDuringCall(true); + } + frameState.setOuterFrameState(outerFrameState); } - frameState.setOuterFrameState(outerFrameState); } } - } - if (callerLockDepth != 0 && node instanceof MonitorReference) { - MonitorReference monitor = (MonitorReference) node; - monitor.setLockDepth(monitor.getLockDepth() + callerLockDepth); + if (callerLockDepth != 0 && node instanceof MonitorReference) { + MonitorReference monitor = (MonitorReference) node; + monitor.setLockDepth(monitor.getLockDepth() + callerLockDepth); + } } } - Node returnValue = null; if (returnNode != null) { if (returnNode.result() instanceof LocalNode) {