# HG changeset patch # User Thomas Wuerthinger # Date 1382701582 -7200 # Node ID 5310cc81f7e4876e6f78ccdb25064d3853c598a0 # Parent 48bc171026d19d0cfff377281a02eca521719bc5# Parent 3b178baf3edbe2bf5a2b14ec79460b068b025bac Merge. diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatSqrtTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatSqrtTest.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatSqrtTest.java Fri Oct 25 13:46:22 2013 +0200 @@ -27,9 +27,7 @@ import org.junit.*; -import com.oracle.graal.compiler.hsail.*; import com.oracle.graal.compiler.hsail.test.infra.*; -import com.oracle.graal.graph.*; /** * Tests floating point square root. @@ -58,10 +56,7 @@ dispatchMethodKernel(64, input, output); } - /** - * Requires {@link HSAILLIRGenerator#emitDirectCall} to be implemented. - */ - @Test(expected = GraalInternalError.class) + @Test public void test() { testGeneratedHsail(); } diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticNBodySpillTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticNBodySpillTest.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticNBodySpillTest.java Fri Oct 25 13:46:22 2013 +0200 @@ -27,9 +27,7 @@ import org.junit.*; -import com.oracle.graal.compiler.hsail.*; import com.oracle.graal.compiler.hsail.test.infra.*; -import com.oracle.graal.graph.*; /** * This version of NBody causes Graal to generate register spilling code. @@ -98,10 +96,7 @@ } // Marked to only run on hardware until simulator spill bug is fixed. - /** - * Requires {@link HSAILLIRGenerator#emitDirectCall} to be implemented. - */ - @Test(expected = GraalInternalError.class) + @Test public void test() { testGeneratedHsail(); } diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticNBodyTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticNBodyTest.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticNBodyTest.java Fri Oct 25 13:46:22 2013 +0200 @@ -29,7 +29,6 @@ import com.oracle.graal.compiler.hsail.*; import com.oracle.graal.compiler.hsail.test.infra.*; -import com.oracle.graal.graph.*; /** * Unit test of NBody demo app. @@ -100,7 +99,7 @@ /** * Requires {@link HSAILLIRGenerator#emitDirectCall} to be implemented. */ - @Test(expected = GraalInternalError.class) + @Test public void test() { testGeneratedHsail(); } diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java Fri Oct 25 13:46:22 2013 +0200 @@ -60,6 +60,12 @@ } @Override + public void completeInitialization() { + HSAILHotSpotForeignCallsProvider foreignCalls = (HSAILHotSpotForeignCallsProvider) getProviders().getForeignCalls(); + foreignCalls.initialize(getProviders(), getRuntime().getConfig()); + } + + @Override public boolean shouldAllocateRegisters() { return true; } diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackendFactory.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackendFactory.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackendFactory.java Fri Oct 25 13:46:22 2013 +0200 @@ -41,13 +41,13 @@ HotSpotMetaAccessProvider metaAccess = host.getMetaAccess(); HSAILHotSpotCodeCacheProvider codeCache = new HSAILHotSpotCodeCacheProvider(runtime, createTarget()); ConstantReflectionProvider constantReflection = host.getConstantReflection(); - HotSpotForeignCallsProvider foreignCalls = new HSAILHotSpotForeignCallsProvider(host.getForeignCalls()); + HotSpotForeignCallsProvider foreignCalls = new HSAILHotSpotForeignCallsProvider(runtime, metaAccess, codeCache); LoweringProvider lowerer = new HSAILHotSpotLoweringProvider(host.getLowerer()); // Replacements cannot have speculative optimizations since they have // to be valid for the entire run of the VM. Assumptions assumptions = new Assumptions(false); Providers p = new Providers(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, null); - Replacements replacements = new HSAILHotSpotReplacementsImpl(p, assumptions); + Replacements replacements = new HSAILHotSpotReplacementsImpl(p, assumptions, host.getReplacements()); HotSpotDisassemblerProvider disassembler = host.getDisassembler(); HotSpotSuitesProvider suites = host.getSuites(); HotSpotRegisters registers = new HotSpotRegisters(Register.None, Register.None, Register.None); diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotForeignCallsProvider.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotForeignCallsProvider.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotForeignCallsProvider.java Fri Oct 25 13:46:22 2013 +0200 @@ -22,36 +22,34 @@ */ package com.oracle.graal.hotspot.hsail; +import static com.oracle.graal.api.meta.LocationIdentity.*; +import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.Transition.*; +import static com.oracle.graal.java.GraphBuilderPhase.RuntimeCalls.*; + import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; -import com.oracle.graal.graph.*; +import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.meta.*; -public class HSAILHotSpotForeignCallsProvider implements HotSpotForeignCallsProvider { +public class HSAILHotSpotForeignCallsProvider extends HotSpotForeignCallsProviderImpl { - private final ForeignCallsProvider host; - - public HSAILHotSpotForeignCallsProvider(ForeignCallsProvider host) { - this.host = host; + public HSAILHotSpotForeignCallsProvider(HotSpotGraalRuntime runtime, MetaAccessProvider metaAccess, CodeCacheProvider codeCache) { + super(runtime, metaAccess, codeCache); } - public boolean isReexecutable(ForeignCallDescriptor descriptor) { - return host.isReexecutable(descriptor); - } - - public LocationIdentity[] getKilledLocations(ForeignCallDescriptor descriptor) { - return host.getKilledLocations(descriptor); - } - - public boolean canDeoptimize(ForeignCallDescriptor descriptor) { - return host.canDeoptimize(descriptor); - } - - public ForeignCallLinkage lookupForeignCall(ForeignCallDescriptor descriptor) { - throw GraalInternalError.unimplemented(); + @Override + public HotSpotForeignCallLinkage lookupForeignCall(ForeignCallDescriptor descriptor) { + return super.lookupForeignCall(descriptor); } public Value[] getNativeABICallerSaveRegisters() { - throw GraalInternalError.unimplemented(); + // TODO is this correct? + return new Value[0]; + } + + public void initialize(HotSpotProviders providers, HotSpotVMConfig c) { + // TODO are these correct? what other foreign calls are supported on HSAIL? + linkForeignCall(providers, CREATE_NULL_POINTER_EXCEPTION, c.createNullPointerExceptionAddress, PREPEND_THREAD, NOT_LEAF, REEXECUTABLE, ANY_LOCATION); + linkForeignCall(providers, CREATE_OUT_OF_BOUNDS_EXCEPTION, c.createOutOfBoundsExceptionAddress, PREPEND_THREAD, NOT_LEAF, REEXECUTABLE, ANY_LOCATION); } } diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotReplacementsImpl.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotReplacementsImpl.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotReplacementsImpl.java Fri Oct 25 13:46:22 2013 +0200 @@ -22,38 +22,33 @@ */ package com.oracle.graal.hotspot.hsail; -import java.lang.reflect.*; - import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.spi.*; import com.oracle.graal.phases.util.*; import com.oracle.graal.replacements.*; /** - * Filters the substitutions and snippets supported by HSAIL. + * The substitutions and snippets supported by HSAIL. */ public class HSAILHotSpotReplacementsImpl extends ReplacementsImpl { - public HSAILHotSpotReplacementsImpl(Providers providers, Assumptions assumptions) { + private final Replacements host; + + public HSAILHotSpotReplacementsImpl(Providers providers, Assumptions assumptions, Replacements host) { super(providers, assumptions); + this.host = host; } @Override - protected ResolvedJavaMethod registerMethodSubstitution(Member originalMethod, Method substituteMethod) { - // TODO decide here what methods substitutions are supported - return null; - } - - @Override - public Class getMacroSubstitution(ResolvedJavaMethod method) { - // TODO decide here what macro substitutions are supported - return null; - } - - @Override - public StructuredGraph getSnippet(ResolvedJavaMethod method) { - // TODO must work in cooperation with HSAILHotSpotLoweringProvider - return null; + public StructuredGraph getMethodSubstitution(ResolvedJavaMethod original) { + StructuredGraph m = super.getMethodSubstitution(original); + if (m == null) { + if (original.getDeclaringClass().equals(providers.getMetaAccess().lookupJavaType(Math.class))) { + return host.getMethodSubstitution(original); + } + } + return m; } } diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotForeignCallsProviderImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotForeignCallsProviderImpl.java Fri Oct 25 13:46:22 2013 +0200 @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2013, 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.meta; + +import static com.oracle.graal.api.code.CallingConvention.Type.*; +import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.RegisterEffect.*; +import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.Transition.*; + +import java.util.*; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.hotspot.*; +import com.oracle.graal.hotspot.HotSpotForeignCallLinkage.RegisterEffect; +import com.oracle.graal.hotspot.HotSpotForeignCallLinkage.Transition; +import com.oracle.graal.hotspot.stubs.*; +import com.oracle.graal.word.*; + +/** + * HotSpot implementation of {@link HotSpotForeignCallsProvider}. + */ +public abstract class HotSpotForeignCallsProviderImpl implements HotSpotForeignCallsProvider { + + public static final ForeignCallDescriptor OSR_MIGRATION_END = new ForeignCallDescriptor("OSR_migration_end", void.class, long.class); + public static final ForeignCallDescriptor IDENTITY_HASHCODE = new ForeignCallDescriptor("identity_hashcode", int.class, Object.class); + public static final ForeignCallDescriptor VERIFY_OOP = new ForeignCallDescriptor("verify_oop", Object.class, Object.class); + public static final ForeignCallDescriptor LOAD_AND_CLEAR_EXCEPTION = new ForeignCallDescriptor("load_and_clear_exception", Object.class, Word.class); + + protected final HotSpotGraalRuntime runtime; + + protected final Map foreignCalls = new HashMap<>(); + protected final MetaAccessProvider metaAccess; + protected final CodeCacheProvider codeCache; + + public HotSpotForeignCallsProviderImpl(HotSpotGraalRuntime runtime, MetaAccessProvider metaAccess, CodeCacheProvider codeCache) { + this.runtime = runtime; + this.metaAccess = metaAccess; + this.codeCache = codeCache; + } + + /** + * Registers the linkage for a foreign call. + */ + protected HotSpotForeignCallLinkage register(HotSpotForeignCallLinkage linkage) { + assert !foreignCalls.containsKey(linkage.getDescriptor()) : "already registered linkage for " + linkage.getDescriptor(); + foreignCalls.put(linkage.getDescriptor(), linkage); + return linkage; + } + + /** + * Creates and registers the details for linking a foreign call to a {@link Stub}. + * + * @param descriptor the signature of the call to the stub + * @param reexecutable specifies if the stub call can be re-executed without (meaningful) side + * effects. Deoptimization will not return to a point before a stub call that cannot + * be re-executed. + * @param transition specifies if this is a {@linkplain Transition#LEAF leaf} call + * @param killedLocations the memory locations killed by the stub call + */ + protected HotSpotForeignCallLinkage registerStubCall(ForeignCallDescriptor descriptor, boolean reexecutable, Transition transition, LocationIdentity... killedLocations) { + return register(HotSpotForeignCallLinkage.create(metaAccess, codeCache, this, descriptor, 0L, PRESERVES_REGISTERS, JavaCall, JavaCallee, transition, reexecutable, killedLocations)); + } + + /** + * Creates and registers the linkage for a foreign call. + * + * @param descriptor the signature of the foreign call + * @param address the address of the code to call + * @param outgoingCcType outgoing (caller) calling convention type + * @param effect specifies if the call destroys or preserves all registers (apart from + * temporaries which are always destroyed) + * @param transition specifies if this is a {@linkplain Transition#LEAF leaf} call + * @param reexecutable specifies if the foreign call can be re-executed without (meaningful) + * side effects. Deoptimization will not return to a point before a foreign call that + * cannot be re-executed. + * @param killedLocations the memory locations killed by the foreign call + */ + protected HotSpotForeignCallLinkage registerForeignCall(ForeignCallDescriptor descriptor, long address, CallingConvention.Type outgoingCcType, RegisterEffect effect, Transition transition, + boolean reexecutable, LocationIdentity... killedLocations) { + Class resultType = descriptor.getResultType(); + assert transition == LEAF || resultType.isPrimitive() || Word.class.isAssignableFrom(resultType) : "non-leaf foreign calls must return objects in thread local storage: " + descriptor; + return register(HotSpotForeignCallLinkage.create(metaAccess, codeCache, this, descriptor, address, effect, outgoingCcType, null, transition, reexecutable, killedLocations)); + } + + /** + * Creates a {@linkplain ForeignCallStub stub} for a foreign call. + * + * @param descriptor the signature of the call to the stub + * @param address the address of the foreign code to call + * @param prependThread true if the JavaThread value for the current thread is to be prepended + * to the arguments for the call to {@code address} + * @param transition specifies if this is a {@linkplain Transition#LEAF leaf} call + * @param reexecutable specifies if the foreign call can be re-executed without (meaningful) + * side effects. Deoptimization will not return to a point before a foreign call that + * cannot be re-executed. + * @param killedLocations the memory locations killed by the foreign call + */ + protected void linkForeignCall(HotSpotProviders providers, ForeignCallDescriptor descriptor, long address, boolean prependThread, Transition transition, boolean reexecutable, + LocationIdentity... killedLocations) { + ForeignCallStub stub = new ForeignCallStub(providers, address, descriptor, prependThread, transition, reexecutable, killedLocations); + HotSpotForeignCallLinkage linkage = stub.getLinkage(); + HotSpotForeignCallLinkage targetLinkage = stub.getTargetLinkage(); + linkage.setCompiledStub(stub); + register(linkage); + register(targetLinkage); + } + + public static final boolean PREPEND_THREAD = true; + public static final boolean DONT_PREPEND_THREAD = !PREPEND_THREAD; + + public static final boolean REEXECUTABLE = true; + public static final boolean NOT_REEXECUTABLE = !REEXECUTABLE; + + public static final LocationIdentity[] NO_LOCATIONS = {}; + + public HotSpotForeignCallLinkage lookupForeignCall(ForeignCallDescriptor descriptor) { + HotSpotForeignCallLinkage callTarget = foreignCalls.get(descriptor); + assert foreignCalls != null : descriptor; + callTarget.finalizeAddress(runtime.getHostBackend()); + return callTarget; + } + + @Override + public boolean isReexecutable(ForeignCallDescriptor descriptor) { + assert foreignCalls.containsKey(descriptor) : "unknown foreign call: " + descriptor; + return foreignCalls.get(descriptor).isReexecutable(); + } + + public boolean canDeoptimize(ForeignCallDescriptor descriptor) { + assert foreignCalls.containsKey(descriptor) : "unknown foreign call: " + descriptor; + return foreignCalls.get(descriptor).canDeoptimize(); + } + + public LocationIdentity[] getKilledLocations(ForeignCallDescriptor descriptor) { + assert foreignCalls.containsKey(descriptor) : "unknown foreign call: " + descriptor; + return foreignCalls.get(descriptor).getKilledLocations(); + } +} diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotHostForeignCallsProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotHostForeignCallsProvider.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotHostForeignCallsProvider.java Fri Oct 25 13:46:22 2013 +0200 @@ -48,117 +48,24 @@ import static com.oracle.graal.replacements.Log.*; import static com.oracle.graal.replacements.MathSubstitutionsX86.*; -import java.util.*; - import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.HotSpotForeignCallLinkage.RegisterEffect; -import com.oracle.graal.hotspot.HotSpotForeignCallLinkage.Transition; import com.oracle.graal.hotspot.stubs.*; -import com.oracle.graal.word.*; /** * HotSpot implementation of {@link ForeignCallsProvider}. */ -public abstract class HotSpotHostForeignCallsProvider implements HotSpotForeignCallsProvider { - - public static final ForeignCallDescriptor OSR_MIGRATION_END = new ForeignCallDescriptor("OSR_migration_end", void.class, long.class); - public static final ForeignCallDescriptor IDENTITY_HASHCODE = new ForeignCallDescriptor("identity_hashcode", int.class, Object.class); - public static final ForeignCallDescriptor VERIFY_OOP = new ForeignCallDescriptor("verify_oop", Object.class, Object.class); - public static final ForeignCallDescriptor LOAD_AND_CLEAR_EXCEPTION = new ForeignCallDescriptor("load_and_clear_exception", Object.class, Word.class); - - protected final HotSpotGraalRuntime runtime; - - private final Map foreignCalls = new HashMap<>(); - private final MetaAccessProvider metaAccess; - private final CodeCacheProvider codeCache; +public abstract class HotSpotHostForeignCallsProvider extends HotSpotForeignCallsProviderImpl { public HotSpotHostForeignCallsProvider(HotSpotGraalRuntime runtime, MetaAccessProvider metaAccess, CodeCacheProvider codeCache) { - this.runtime = runtime; - this.metaAccess = metaAccess; - this.codeCache = codeCache; - } - - /** - * Registers the linkage for a foreign call. - */ - protected HotSpotForeignCallLinkage register(HotSpotForeignCallLinkage linkage) { - assert !foreignCalls.containsKey(linkage.getDescriptor()) : "already registered linkage for " + linkage.getDescriptor(); - foreignCalls.put(linkage.getDescriptor(), linkage); - return linkage; - } - - /** - * Creates and registers the details for linking a foreign call to a {@link Stub}. - * - * @param descriptor the signature of the call to the stub - * @param reexecutable specifies if the stub call can be re-executed without (meaningful) side - * effects. Deoptimization will not return to a point before a stub call that cannot - * be re-executed. - * @param transition specifies if this is a {@linkplain Transition#LEAF leaf} call - * @param killedLocations the memory locations killed by the stub call - */ - protected HotSpotForeignCallLinkage registerStubCall(ForeignCallDescriptor descriptor, boolean reexecutable, Transition transition, LocationIdentity... killedLocations) { - return register(HotSpotForeignCallLinkage.create(metaAccess, codeCache, this, descriptor, 0L, PRESERVES_REGISTERS, JavaCall, JavaCallee, transition, reexecutable, killedLocations)); - } - - /** - * Creates and registers the linkage for a foreign call. - * - * @param descriptor the signature of the foreign call - * @param address the address of the code to call - * @param outgoingCcType outgoing (caller) calling convention type - * @param effect specifies if the call destroys or preserves all registers (apart from - * temporaries which are always destroyed) - * @param transition specifies if this is a {@linkplain Transition#LEAF leaf} call - * @param reexecutable specifies if the foreign call can be re-executed without (meaningful) - * side effects. Deoptimization will not return to a point before a foreign call that - * cannot be re-executed. - * @param killedLocations the memory locations killed by the foreign call - */ - protected HotSpotForeignCallLinkage registerForeignCall(ForeignCallDescriptor descriptor, long address, CallingConvention.Type outgoingCcType, RegisterEffect effect, Transition transition, - boolean reexecutable, LocationIdentity... killedLocations) { - Class resultType = descriptor.getResultType(); - assert transition == LEAF || resultType.isPrimitive() || Word.class.isAssignableFrom(resultType) : "non-leaf foreign calls must return objects in thread local storage: " + descriptor; - return register(HotSpotForeignCallLinkage.create(metaAccess, codeCache, this, descriptor, address, effect, outgoingCcType, null, transition, reexecutable, killedLocations)); + super(runtime, metaAccess, codeCache); } private static void link(Stub stub) { stub.getLinkage().setCompiledStub(stub); } - /** - * Creates a {@linkplain ForeignCallStub stub} for a foreign call. - * - * @param descriptor the signature of the call to the stub - * @param address the address of the foreign code to call - * @param prependThread true if the JavaThread value for the current thread is to be prepended - * to the arguments for the call to {@code address} - * @param transition specifies if this is a {@linkplain Transition#LEAF leaf} call - * @param reexecutable specifies if the foreign call can be re-executed without (meaningful) - * side effects. Deoptimization will not return to a point before a foreign call that - * cannot be re-executed. - * @param killedLocations the memory locations killed by the foreign call - */ - private void linkForeignCall(HotSpotProviders providers, ForeignCallDescriptor descriptor, long address, boolean prependThread, Transition transition, boolean reexecutable, - LocationIdentity... killedLocations) { - ForeignCallStub stub = new ForeignCallStub(providers, address, descriptor, prependThread, transition, reexecutable, killedLocations); - HotSpotForeignCallLinkage linkage = stub.getLinkage(); - HotSpotForeignCallLinkage targetLinkage = stub.getTargetLinkage(); - linkage.setCompiledStub(stub); - register(linkage); - register(targetLinkage); - } - - public static final boolean PREPEND_THREAD = true; - public static final boolean DONT_PREPEND_THREAD = !PREPEND_THREAD; - - public static final boolean REEXECUTABLE = true; - public static final boolean NOT_REEXECUTABLE = !REEXECUTABLE; - - public static final LocationIdentity[] NO_LOCATIONS = {}; - public void initialize(HotSpotProviders providers, HotSpotVMConfig c) { TargetDescription target = providers.getCodeCache().getTarget(); @@ -203,29 +110,4 @@ linkForeignCall(providers, G1WBPOSTCALL, c.writeBarrierPostAddress, PREPEND_THREAD, LEAF, REEXECUTABLE, NO_LOCATIONS); linkForeignCall(providers, VALIDATE_OBJECT, c.validateObject, PREPEND_THREAD, LEAF, REEXECUTABLE, NO_LOCATIONS); } - - public HotSpotForeignCallLinkage lookupForeignCall(ForeignCallDescriptor descriptor) { - HotSpotForeignCallLinkage callTarget = foreignCalls.get(descriptor); - assert foreignCalls != null : descriptor; - callTarget.finalizeAddress(runtime.getHostBackend()); - return callTarget; - } - - @Override - public boolean isReexecutable(ForeignCallDescriptor descriptor) { - return foreignCalls.get(descriptor).isReexecutable(); - } - - public boolean canDeoptimize(ForeignCallDescriptor descriptor) { - return foreignCalls.get(descriptor).canDeoptimize(); - } - - public LocationIdentity[] getKilledLocations(ForeignCallDescriptor descriptor) { - return foreignCalls.get(descriptor).getKilledLocations(); - } - - /** - * Gets the registers that must be saved across a foreign call into the runtime. - */ - public abstract Value[] getNativeABICallerSaveRegisters(); } diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotHostLoweringProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotHostLoweringProvider.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotHostLoweringProvider.java Fri Oct 25 13:46:22 2013 +0200 @@ -186,7 +186,7 @@ } else if (n instanceof CompareAndSwapNode) { // Separate out GC barrier semantics CompareAndSwapNode cas = (CompareAndSwapNode) n; - LocationNode location = IndexedLocationNode.create(ANY_LOCATION, cas.expected().kind(), cas.displacement(), cas.offset(), graph, 1); + LocationNode location = IndexedLocationNode.create(cas.getLocationIdentity(), cas.expected().kind(), cas.displacement(), cas.offset(), graph, 1); LoweredCompareAndSwapNode atomicNode = graph.add(new LoweredCompareAndSwapNode(cas.object(), location, cas.expected(), cas.newValue(), getCompareAndSwapBarrier(cas), cas.expected().kind() == Kind.Object)); atomicNode.setStateAfter(cas.stateAfter()); diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRegisters.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRegisters.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRegisters.java Fri Oct 25 13:46:22 2013 +0200 @@ -37,14 +37,17 @@ } public Register getThreadRegister() { + assert !threadRegister.equals(Register.None) : "thread register is not defined"; return threadRegister; } public Register getHeapBaseRegister() { + assert !heapBaseRegister.equals(Register.None) : "heap base register is not defined"; return heapBaseRegister; } public Register getStackPointerRegister() { + assert !stackPointerRegister.equals(Register.None) : "stack pointer register is not defined"; return stackPointerRegister; } } diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeArrayCopySnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeArrayCopySnippets.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeArrayCopySnippets.java Fri Oct 25 13:46:22 2013 +0200 @@ -31,6 +31,7 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.asm.*; +import com.oracle.graal.hotspot.phases.*; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.phases.util.*; import com.oracle.graal.replacements.*; @@ -38,16 +39,15 @@ import com.oracle.graal.replacements.SnippetTemplate.AbstractTemplates; import com.oracle.graal.replacements.SnippetTemplate.Arguments; import com.oracle.graal.replacements.SnippetTemplate.SnippetInfo; +import com.oracle.graal.replacements.nodes.*; import com.oracle.graal.word.*; /** * As opposed to {@link ArrayCopySnippets}, these Snippets do not perform store checks. */ public class UnsafeArrayCopySnippets implements Snippets { - private static final boolean supportsUnalignedMemoryAccess = runtime().getTarget().arch.supportsUnalignedMemoryAccess(); - // TODO: make vector kind architecture dependent private static final Kind VECTOR_KIND = Kind.Long; private static final long VECTOR_SIZE = arrayIndexScale(VECTOR_KIND); @@ -139,52 +139,82 @@ @Snippet public static void arraycopyByte(byte[] src, int srcPos, byte[] dest, int destPos, int length) { - vectorizedCopy(src, srcPos, dest, destPos, length, Kind.Byte, getArrayLocation(Kind.Byte)); + Kind kind = Kind.Byte; + vectorizedCopy(src, srcPos, dest, destPos, length, kind, getArrayLocation(kind)); } @Snippet public static void arraycopyBoolean(boolean[] src, int srcPos, boolean[] dest, int destPos, int length) { - vectorizedCopy(src, srcPos, dest, destPos, length, Kind.Byte, getArrayLocation(Kind.Boolean)); + Kind kind = Kind.Boolean; + vectorizedCopy(src, srcPos, dest, destPos, length, kind, getArrayLocation(kind)); } @Snippet public static void arraycopyChar(char[] src, int srcPos, char[] dest, int destPos, int length) { - vectorizedCopy(src, srcPos, dest, destPos, length, Kind.Char, getArrayLocation(Kind.Char)); + Kind kind = Kind.Char; + vectorizedCopy(src, srcPos, dest, destPos, length, kind, getArrayLocation(kind)); } @Snippet public static void arraycopyShort(short[] src, int srcPos, short[] dest, int destPos, int length) { - vectorizedCopy(src, srcPos, dest, destPos, length, Kind.Short, getArrayLocation(Kind.Short)); + Kind kind = Kind.Short; + vectorizedCopy(src, srcPos, dest, destPos, length, kind, getArrayLocation(kind)); } @Snippet public static void arraycopyInt(int[] src, int srcPos, int[] dest, int destPos, int length) { - vectorizedCopy(src, srcPos, dest, destPos, length, Kind.Int, getArrayLocation(Kind.Int)); + Kind kind = Kind.Int; + vectorizedCopy(src, srcPos, dest, destPos, length, kind, getArrayLocation(kind)); } @Snippet public static void arraycopyFloat(float[] src, int srcPos, float[] dest, int destPos, int length) { - vectorizedCopy(src, srcPos, dest, destPos, length, Kind.Float, getArrayLocation(Kind.Float)); + Kind kind = Kind.Float; + vectorizedCopy(src, srcPos, dest, destPos, length, kind, getArrayLocation(kind)); } @Snippet public static void arraycopyLong(long[] src, int srcPos, long[] dest, int destPos, int length) { - vectorizedCopy(src, srcPos, dest, destPos, length, Kind.Long, getArrayLocation(Kind.Long)); + Kind kind = Kind.Long; + vectorizedCopy(src, srcPos, dest, destPos, length, kind, getArrayLocation(kind)); } @Snippet public static void arraycopyDouble(double[] src, int srcPos, double[] dest, int destPos, int length) { + Kind kind = Kind.Double; /* * TODO atomicity problem on 32-bit architectures: The JVM spec requires double values to be * copied atomically, but not long values. For example, on Intel 32-bit this code is not * atomic as long as the vector kind remains Kind.Long. */ - vectorizedCopy(src, srcPos, dest, destPos, length, Kind.Double, getArrayLocation(Kind.Double)); + vectorizedCopy(src, srcPos, dest, destPos, length, kind, getArrayLocation(kind)); } + /** + * For this kind, Object, we want to avoid write barriers between writes, but instead have them + * at the end of the snippet. This is done by using {@link DirectObjectStoreNode}, and rely on + * {@link WriteBarrierAdditionPhase} to put write barriers after the {@link UnsafeArrayCopyNode} + * with kind Object. + */ @Snippet public static void arraycopyObject(Object[] src, int srcPos, Object[] dest, int destPos, int length) { - vectorizedCopy(src, srcPos, dest, destPos, length, Kind.Object, getArrayLocation(Kind.Object)); + Kind kind = Kind.Object; + final int scale = arrayIndexScale(kind); + int arrayBaseOffset = arrayBaseOffset(kind); + LocationIdentity arrayLocation = getArrayLocation(kind); + if (src == dest && srcPos < destPos) { // bad aliased case + long start = (long) (length - 1) * scale; + for (long i = start; i >= 0; i -= scale) { + Object a = UnsafeLoadNode.load(src, arrayBaseOffset + i + (long) srcPos * scale, kind, arrayLocation); + DirectObjectStoreNode.storeObject(dest, arrayBaseOffset, i + (long) destPos * scale, a, getArrayLocation(kind)); + } + } else { + long end = (long) length * scale; + for (long i = 0; i < end; i += scale) { + Object a = UnsafeLoadNode.load(src, arrayBaseOffset + i + (long) srcPos * scale, kind, arrayLocation); + DirectObjectStoreNode.storeObject(dest, arrayBaseOffset, i + (long) destPos * scale, a, getArrayLocation(kind)); + } + } } @Snippet diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java Fri Oct 25 13:46:22 2013 +0200 @@ -442,7 +442,7 @@ public static void validateObject(Object parent, Object child) { if (verifyOops() && child != null && !validateOop(VALIDATE_OBJECT, parent, child)) { log(true, "Verification ERROR, Parent: %p Child: %p\n", Word.fromObject(parent).rawValue(), Word.fromObject(child).rawValue()); - DirectObjectStoreNode.storeWord(null, 0, 0, Word.zero()); + DirectObjectStoreNode.storeObject(null, 0, 0, null, LocationIdentity.ANY_LOCATION); } } diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetCounter.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetCounter.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetCounter.java Fri Oct 25 13:46:22 2013 +0200 @@ -24,13 +24,14 @@ //JaCoCo Exclude -import static com.oracle.graal.graph.FieldIntrospection.*; +import static com.oracle.graal.graph.UnsafeAccess.*; import java.io.*; import java.util.*; +import com.oracle.graal.api.meta.*; import com.oracle.graal.graph.*; -import com.oracle.graal.replacements.Snippet.*; +import com.oracle.graal.replacements.Snippet.Fold; import com.oracle.graal.replacements.nodes.*; /** @@ -133,7 +134,8 @@ */ public void inc() { if (group != null) { - DirectObjectStoreNode.storeLong(this, countOffset(), 0, value + 1); + // TODO: instead of ANY_LOCATION we should actually use the location for the field "value". + DirectObjectStoreNode.storeLong(this, countOffset(), 0, value + 1, LocationIdentity.ANY_LOCATION); } } diff -r 48bc171026d1 -r 5310cc81f7e4 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/DirectObjectStoreNode.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/DirectObjectStoreNode.java Fri Oct 25 12:12:49 2013 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/DirectObjectStoreNode.java Fri Oct 25 13:46:22 2013 +0200 @@ -22,15 +22,12 @@ */ package com.oracle.graal.replacements.nodes; -import static com.oracle.graal.api.meta.LocationIdentity.*; - import com.oracle.graal.api.meta.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.HeapAccess.BarrierType; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; -import com.oracle.graal.word.*; /** * A special purpose store node that differs from {@link UnsafeStoreNode} in that it is not a @@ -42,30 +39,26 @@ @Input private ValueNode value; @Input private ValueNode offset; private final int displacement; + private final LocationIdentity locationIdentity; - public DirectObjectStoreNode(ValueNode object, int displacement, ValueNode offset, ValueNode value) { + public DirectObjectStoreNode(ValueNode object, int displacement, ValueNode offset, ValueNode value, LocationIdentity locationIdentity) { super(StampFactory.forVoid()); this.object = object; this.value = value; this.offset = offset; this.displacement = displacement; + this.locationIdentity = locationIdentity; } @NodeIntrinsic - public static native void storeObject(Object obj, @ConstantNodeParameter int displacement, long offset, Object value); + public static native void storeObject(Object obj, @ConstantNodeParameter int displacement, long offset, Object value, @ConstantNodeParameter LocationIdentity locationIdentity); @NodeIntrinsic - public static native void storeLong(Object obj, @ConstantNodeParameter int displacement, long offset, long value); - - @NodeIntrinsic - public static native void storeWord(Object obj, @ConstantNodeParameter int displacement, long offset, Word value); - - @NodeIntrinsic - public static native void storeInt(Object obj, @ConstantNodeParameter int displacement, long offset, int value); + public static native void storeLong(Object obj, @ConstantNodeParameter int displacement, long offset, long value, @ConstantNodeParameter LocationIdentity locationIdenity); @Override public void lower(LoweringTool tool) { - IndexedLocationNode location = IndexedLocationNode.create(ANY_LOCATION, value.kind(), displacement, offset, graph(), 1); + IndexedLocationNode location = IndexedLocationNode.create(locationIdentity, value.kind(), displacement, offset, graph(), 1); WriteNode write = graph().add(new WriteNode(object, value, location, BarrierType.NONE, value.kind() == Kind.Object)); graph().replaceFixedWithFixed(this, write); } diff -r 48bc171026d1 -r 5310cc81f7e4 mx/commands.py --- a/mx/commands.py Fri Oct 25 12:12:49 2013 +0200 +++ b/mx/commands.py Fri Oct 25 13:46:22 2013 +0200 @@ -327,7 +327,7 @@ jvmCfgLines += ['-original KNOWN\n'] else: # skip lines which we cannot parse (e.g. '-hotspot ALIASED_TO -client') - pass + mx.log("WARNING: skipping not parsable line \"" + line + "\"") else: jvmCfgLines += [line]