# HG changeset patch # User Doug Simon # Date 1332965858 -7200 # Node ID 597eade2394ea9c4310b675c9af61aa7a38d4ba4 # Parent 20f8a3215fa8a0f16cd918b59474fdda02eef472# Parent 8d18583cf5f7b182c18de1fc8fede8717020f471 Merge. diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java Wed Mar 28 22:17:38 2012 +0200 @@ -22,28 +22,12 @@ */ package com.oracle.graal.compiler.gen; +import static com.oracle.graal.lir.ValueUtil.*; import static com.oracle.max.cri.ci.CiCallingConvention.Type.*; import static com.oracle.max.cri.ci.CiValue.*; -import static com.oracle.max.cri.ci.CiValueUtil.*; -import static com.oracle.max.cri.util.MemoryBarriers.*; -import static com.oracle.graal.lir.ValueUtil.*; import java.util.*; -import com.oracle.max.asm.*; -import com.oracle.max.cri.ci.*; -import com.oracle.max.cri.ci.CiTargetMethod.Mark; -import com.oracle.max.cri.ri.*; -import com.oracle.max.cri.ri.RiType.Representation; -import com.oracle.max.cri.xir.CiXirAssembler.XirConstant; -import com.oracle.max.cri.xir.CiXirAssembler.XirInstruction; -import com.oracle.max.cri.xir.CiXirAssembler.XirMark; -import com.oracle.max.cri.xir.CiXirAssembler.XirOperand; -import com.oracle.max.cri.xir.CiXirAssembler.XirParameter; -import com.oracle.max.cri.xir.CiXirAssembler.XirRegister; -import com.oracle.max.cri.xir.CiXirAssembler.XirTemp; -import com.oracle.max.cri.xir.*; -import com.oracle.max.criutils.*; import com.oracle.graal.compiler.*; import com.oracle.graal.compiler.util.*; import com.oracle.graal.debug.*; @@ -62,6 +46,20 @@ import com.oracle.graal.nodes.java.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.virtual.*; +import com.oracle.max.asm.*; +import com.oracle.max.cri.ci.*; +import com.oracle.max.cri.ci.CiTargetMethod.Mark; +import com.oracle.max.cri.ri.*; +import com.oracle.max.cri.ri.RiType.Representation; +import com.oracle.max.cri.xir.CiXirAssembler.XirConstant; +import com.oracle.max.cri.xir.CiXirAssembler.XirInstruction; +import com.oracle.max.cri.xir.CiXirAssembler.XirMark; +import com.oracle.max.cri.xir.CiXirAssembler.XirOperand; +import com.oracle.max.cri.xir.CiXirAssembler.XirParameter; +import com.oracle.max.cri.xir.CiXirAssembler.XirRegister; +import com.oracle.max.cri.xir.CiXirAssembler.XirTemp; +import com.oracle.max.cri.xir.*; +import com.oracle.max.criutils.*; /** * This class traverses the HIR instructions and generates LIR instructions from them. @@ -498,14 +496,6 @@ } @Override - public void visitArrayLength(ArrayLengthNode x) { - XirArgument array = toXirArgument(x.array()); - XirSnippet snippet = xir.genArrayLength(site(x, x.array()), array); - emitXir(snippet, x, state(), true); - operand(x); - } - - @Override public void visitCheckCast(CheckCastNode x) { if (x.emitCode()) { XirSnippet snippet = xir.genCheckCast(site(x, x.object()), toXirArgument(x.object()), toXirArgument(x.targetClassInstruction()), x.targetClass(), x.hints(), x.hintsExact()); @@ -560,54 +550,6 @@ } @Override - public void visitLoadField(LoadFieldNode x) { - RiField field = x.field(); - LIRDebugInfo info = state(); - if (x.isVolatile()) { - emitMembar(JMM_PRE_VOLATILE_READ); - } - XirArgument receiver = toXirArgument(x.object()); - XirSnippet snippet = x.isStatic() ? xir.genGetStatic(site(x, x.object()), receiver, field) : xir.genGetField(site(x, x.object()), receiver, field); - emitXir(snippet, x, info, true); - if (x.isVolatile()) { - emitMembar(JMM_POST_VOLATILE_READ); - } - } - - @Override - public void visitStoreField(StoreFieldNode x) { - RiField field = x.field(); - LIRDebugInfo info = state(); - if (x.isVolatile()) { - emitMembar(JMM_PRE_VOLATILE_WRITE); - } - XirArgument receiver = toXirArgument(x.object()); - XirArgument value = toXirArgument(x.value()); - XirSnippet snippet = x.isStatic() ? xir.genPutStatic(site(x, x.object()), receiver, field, value) : xir.genPutField(site(x, x.object()), receiver, field, value); - emitXir(snippet, x, info, true); - if (x.isVolatile()) { - emitMembar(JMM_POST_VOLATILE_WRITE); - } - } - - @Override - public void visitLoadIndexed(LoadIndexedNode x) { - XirArgument array = toXirArgument(x.array()); - XirArgument index = toXirArgument(x.index()); - XirSnippet snippet = xir.genArrayLoad(site(x, x.array()), array, index, x.elementKind(), null); - emitXir(snippet, x, state(), true); - } - - @Override - public void visitStoreIndexed(StoreIndexedNode x) { - XirArgument array = toXirArgument(x.array()); - XirArgument index = toXirArgument(x.index()); - XirArgument value = toXirArgument(x.value()); - XirSnippet snippet = xir.genArrayStore(site(x, x.array()), array, index, value, x.elementKind(), null); - emitXir(snippet, x, state(), true); - } - - @Override public void visitNewInstance(NewInstanceNode x) { XirSnippet snippet = xir.genNewInstance(site(x), x.instanceClass()); emitXir(snippet, x, state(), true); @@ -660,21 +602,6 @@ protected abstract void emitReturn(CiValue input); - @SuppressWarnings("unused") - protected void postGCWriteBarrier(CiValue addr, CiValue newVal) { - XirSnippet writeBarrier = xir.genWriteBarrier(toXirArgument(addr)); - if (writeBarrier != null) { - emitXir(writeBarrier, null, null, false); - } - } - - @SuppressWarnings("unused") - protected void preGCWriteBarrier(CiValue addrOpr, boolean patch, LIRDebugInfo info) { - // TODO (thomaswue): Implement this. - } - - - @Override public void visitMerge(MergeNode x) { } diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/amd64/AMD64LIRGenerator.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/amd64/AMD64LIRGenerator.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/amd64/AMD64LIRGenerator.java Wed Mar 28 22:17:38 2012 +0200 @@ -566,10 +566,6 @@ append(new NullCheckOp(value, info)); } - // TODO (cwimmer) The CompareAndSwapNode in its current form needs to be lowered to several Nodes before code generation to separate three parts: - // * The write barriers (and possibly read barriers) when accessing an object field - // * The distinction of returning a boolean value (semantic similar to a BooleanNode to be used as a condition?) or the old value being read - // * The actual compare-and-swap @Override public void visitCompareAndSwap(CompareAndSwapNode node) { CiKind kind = node.newValue().kind(); @@ -586,25 +582,12 @@ address = new CiAddress(kind, load(operand(node.object())), load(index), CiAddress.Scale.Times1, 0); } - if (kind == CiKind.Object) { - address = new CiAddress(kind, emitLea(address)); - preGCWriteBarrier(address.base, false, null); - } - CiRegisterValue rax = AMD64.rax.asValue(kind); emitMove(expected, rax); append(new CompareAndSwapOp(rax, address, rax, newValue)); Variable result = newVariable(node.kind()); - if (node.directResult()) { - emitMove(rax, result); - } else { - append(new CondMoveOp(result, Condition.EQ, load(CiConstant.TRUE), CiConstant.FALSE)); - } + append(new CondMoveOp(result, Condition.EQ, load(CiConstant.TRUE), CiConstant.FALSE)); setResult(node, result); - - if (kind == CiKind.Object) { - postGCWriteBarrier(address.base, newValue); - } } } diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfig.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfig.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfig.java Wed Mar 28 22:17:38 2012 +0200 @@ -26,10 +26,27 @@ public interface DebugConfig { + /** + * @see Debug#log(String, Object...) + */ boolean isLogEnabled(); + + /** + * @see Debug#metric(String) + */ boolean isMeterEnabled(); + + /** + * @see Debug#dump(Object, String, Object...) + */ boolean isDumpEnabled(); + + /** + * @see Debug#timer(String) + */ boolean isTimeEnabled(); + RuntimeException interceptException(Throwable e); + Collection dumpHandlers(); } diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotDebugConfig.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotDebugConfig.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotDebugConfig.java Wed Mar 28 22:17:38 2012 +0200 @@ -54,6 +54,7 @@ this.methodFilter = new MethodFilter[filters.length]; for (int i = 0; i < filters.length; i++) { this.methodFilter[i] = new MethodFilter(filters[i]); + // TTY.println(this.methodFilter[i].toString()); } } if (GraalOptions.PrintIdealGraphFile) { diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/MethodFilter.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/MethodFilter.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/MethodFilter.java Wed Mar 28 22:17:38 2012 +0200 @@ -98,7 +98,7 @@ if (pattern.contains(".")) { return Pattern.compile(createGlobString(pattern)); } else { - return Pattern.compile("([^\\.]\\.])*" + createGlobString(pattern)); + return Pattern.compile("([^\\.]\\.)*" + createGlobString(pattern)); } } @@ -125,4 +125,22 @@ return true; } + @Override + public String toString() { + StringBuilder buf = new StringBuilder("MethodFilter["); + String sep = ""; + if (clazz != null) { + buf.append(sep).append("clazz=").append(clazz); + sep = ", "; + } + if (methodName != null) { + buf.append(sep).append("methodName=").append(methodName); + sep = ", "; + } + if (signature != null) { + buf.append(sep).append("signature=").append(signature); + sep = ", "; + } + return buf.append("]").toString(); + } } diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Wed Mar 28 22:17:38 2012 +0200 @@ -80,6 +80,13 @@ public void startCompiler() throws Throwable { // Make sure TTY is initialized here such that the correct System.out is used for TTY. TTY.initialize(); + + if (GraalOptions.Log == null && GraalOptions.Meter == null && GraalOptions.Time == null && GraalOptions.Dump == null) { + if (GraalOptions.MethodFilter != null) { + TTY.println("WARNING: Ignoring MethodFilter option since Log, Meter, Time and Dump options are all null"); + } + } + if (GraalOptions.Debug) { Debug.enable(); HotSpotDebugConfig hotspotDebugConfig = new HotSpotDebugConfig(GraalOptions.Log, GraalOptions.Meter, GraalOptions.Time, GraalOptions.Dump, GraalOptions.MethodFilter); diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ArrayWriteBarrier.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ArrayWriteBarrier.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ArrayWriteBarrier.java Wed Mar 28 22:17:38 2012 +0200 @@ -47,7 +47,7 @@ @Override public void generate(LIRGeneratorTool gen) { - CiValue obj = gen.emitLea(gen.makeAddress(location(), object())); - generateBarrier(obj, gen); + CiValue addr = gen.emitLea(gen.makeAddress(location(), object())); + generateBarrier(addr, gen); } } diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrier.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrier.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrier.java Wed Mar 28 22:17:38 2012 +0200 @@ -34,9 +34,9 @@ super(StampFactory.illegal()); } - protected void generateBarrier(CiValue obj, LIRGeneratorTool gen) { + protected void generateBarrier(CiValue adr, LIRGeneratorTool gen) { HotSpotVMConfig config = CompilerImpl.getInstance().getConfig(); - CiValue base = gen.emitUShr(obj, CiConstant.forInt(config.cardtableShift)); + CiValue base = gen.emitUShr(adr, CiConstant.forInt(config.cardtableShift)); long startAddress = config.cardtableStartAddress; int displacement = 0; diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotRuntime.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotRuntime.java Wed Mar 28 22:17:38 2012 +0200 @@ -22,6 +22,8 @@ */ package com.oracle.graal.hotspot.ri; +import static com.oracle.max.cri.util.MemoryBarriers.*; + import java.lang.reflect.*; import java.util.*; @@ -223,27 +225,52 @@ safeReadArrayLength.lower(tool); } else if (n instanceof LoadFieldNode) { LoadFieldNode field = (LoadFieldNode) n; - if (field.isVolatile()) { - return; - } int displacement = ((HotSpotField) field.field()).offset(); assert field.kind() != CiKind.Illegal; ReadNode memoryRead = graph.add(new ReadNode(field.object(), LocationNode.create(field.field(), field.field().kind(true), displacement, graph), field.stamp())); memoryRead.setGuard((GuardNode) tool.createGuard(graph.unique(new NullCheckNode(field.object(), false)), RiDeoptReason.NullCheckException, RiDeoptAction.InvalidateReprofile, StructuredGraph.INVALID_GRAPH_ID)); graph.replaceFixedWithFixed(field, memoryRead); + if (field.isVolatile()) { + MembarNode preMembar = graph.add(new MembarNode(JMM_PRE_VOLATILE_READ)); + graph.addBeforeFixed(memoryRead, preMembar); + MembarNode postMembar = graph.add(new MembarNode(JMM_POST_VOLATILE_READ)); + graph.addAfterFixed(memoryRead, postMembar); + } } else if (n instanceof StoreFieldNode) { StoreFieldNode storeField = (StoreFieldNode) n; - if (storeField.isVolatile()) { - return; - } HotSpotField field = (HotSpotField) storeField.field(); WriteNode memoryWrite = graph.add(new WriteNode(storeField.object(), storeField.value(), LocationNode.create(storeField.field(), storeField.field().kind(true), field.offset(), graph))); memoryWrite.setGuard((GuardNode) tool.createGuard(graph.unique(new NullCheckNode(storeField.object(), false)), RiDeoptReason.NullCheckException, RiDeoptAction.InvalidateReprofile, StructuredGraph.INVALID_GRAPH_ID)); memoryWrite.setStateAfter(storeField.stateAfter()); graph.replaceFixedWithFixed(storeField, memoryWrite); + FixedWithNextNode last = memoryWrite; if (field.kind(true) == CiKind.Object && !memoryWrite.value().isNullConstant()) { - graph.addAfterFixed(memoryWrite, graph.add(new FieldWriteBarrier(memoryWrite.object()))); + FieldWriteBarrier writeBarrier = graph.add(new FieldWriteBarrier(memoryWrite.object())); + graph.addAfterFixed(memoryWrite, writeBarrier); + last = writeBarrier; + } + if (storeField.isVolatile()) { + MembarNode preMembar = graph.add(new MembarNode(JMM_PRE_VOLATILE_WRITE)); + graph.addBeforeFixed(memoryWrite, preMembar); + MembarNode postMembar = graph.add(new MembarNode(JMM_POST_VOLATILE_WRITE)); + graph.addAfterFixed(last, postMembar); + } + } else if (n instanceof CompareAndSwapNode) { + // Separate out GC barrier semantics + CompareAndSwapNode cas = (CompareAndSwapNode) n; + ValueNode expected = cas.expected(); + if (expected.kind() == CiKind.Object && !cas.newValue().isNullConstant()) { + RiResolvedType declaredType = cas.object().declaredType(); + if (declaredType != null && !declaredType.isArrayClass() && declaredType.toJava() != Object.class) { + // Use a field write barrier since it's not an array store + FieldWriteBarrier writeBarrier = graph.add(new FieldWriteBarrier(cas.object())); + graph.addAfterFixed(cas, writeBarrier); + } else { + // This may be an array store so use an array write barrier + LocationNode location = IndexedLocationNode.create(LocationNode.ANY_LOCATION, cas.expected().kind(), 0, cas.offset(), graph, false); + graph.addAfterFixed(cas, graph.add(new ArrayWriteBarrier(cas.object(), location))); + } } } else if (n instanceof LoadIndexedNode) { LoadIndexedNode loadIndexed = (LoadIndexedNode) n; diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotXirGenerator.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotXirGenerator.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotXirGenerator.java Wed Mar 28 22:17:38 2012 +0200 @@ -38,7 +38,6 @@ import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ci.CiRegister.RegisterFlag; import com.oracle.max.cri.ri.*; -import com.oracle.max.cri.ri.RiType.Representation; import com.oracle.max.cri.xir.*; import com.oracle.max.cri.xir.CiXirAssembler.XirConstant; import com.oracle.max.cri.xir.CiXirAssembler.XirLabel; @@ -414,62 +413,6 @@ } }; - private KindTemplates getFieldTemplates = new KindTemplates(NULL_CHECK) { - - @Override - protected XirTemplate create(CiXirAssembler asm, long flags, CiKind kind) { - XirOperand result = asm.restart(kind); - XirParameter object = asm.createInputParameter("object", CiKind.Object); - - XirParameter fieldOffset = asm.createConstantInputParameter("fieldOffset", CiKind.Int); - if (is(NULL_CHECK, flags)) { - asm.mark(MARK_IMPLICIT_NULL); - } - asm.pload(kind, result, object, fieldOffset, is(NULL_CHECK, flags)); - return asm.finishTemplate("getfield<" + kind + ">"); - } - }; - - private KindTemplates writeBarrierTemplate = new KindTemplates() { - - @Override - protected XirTemplate create(CiXirAssembler asm, long flags, CiKind kind) { - asm.restart(CiKind.Void); - XirParameter object = asm.createInputParameter("object", CiKind.Object); - - // Need temp operand, because the write barrier destroys the object pointer. - XirOperand temp = asm.createTemp("temp", target.wordKind); - asm.mov(temp, object); - - writeBarrier(asm, temp); - return asm.finishTemplate("writeBarrier"); - } - }; - - private KindTemplates putFieldTemplates = new KindTemplates(WRITE_BARRIER, NULL_CHECK) { - - @Override - protected XirTemplate create(CiXirAssembler asm, long flags, CiKind kind) { - asm.restart(CiKind.Void); - XirParameter object = asm.createInputParameter("object", CiKind.Object); - XirParameter value = asm.createInputParameter("value", kind); - XirParameter fieldOffset = asm.createConstantInputParameter("fieldOffset", CiKind.Int); - if (kind == CiKind.Object) { - verifyPointer(asm, value); - } - if (is(NULL_CHECK, flags)) { - asm.mark(MARK_IMPLICIT_NULL); - } - asm.pstore(kind, object, fieldOffset, value, is(NULL_CHECK, flags)); - if (is(WRITE_BARRIER, flags) && kind == CiKind.Object) { - XirOperand temp = asm.createTemp("temp", target.wordKind); - asm.mov(temp, object); - writeBarrier(asm, temp); - } - return asm.finishTemplate("putfield<" + kind + ">"); - } - }; - private final IndexTemplates newInstanceTemplates = new IndexTemplates() { @Override @@ -523,26 +466,6 @@ } }; - private SimpleTemplates newObjectArrayCloneTemplates = new SimpleTemplates() { - - @Override - protected XirTemplate create(CiXirAssembler asm, long flags) { - XirOperand result = asm.restart(CiKind.Object); - XirParameter lengthParam = asm.createInputParameter("length", CiKind.Int, true); - XirParameter src = asm.createInputParameter("src", CiKind.Object); - - // Set up length and hub. - XirOperand length = asm.createRegisterTemp("length", CiKind.Int, AMD64.rbx); - XirOperand hub = asm.createRegisterTemp("hub", CiKind.Object, AMD64.rdx); - asm.pload(CiKind.Object, hub, src, asm.i(config.hubOffset), false); - asm.mov(length, lengthParam); - - useRegisters(asm, AMD64.rsi, AMD64.rcx, AMD64.rdi, AMD64.rax); - asm.callRuntime(config.newObjectArrayStub, result); - return asm.finishTemplate("objectArrayClone"); - } - }; - private SimpleTemplates newObjectArrayTemplates = new SimpleTemplates() { @Override @@ -852,89 +775,6 @@ } }; - private XirOperand genArrayLength(CiXirAssembler asm, XirOperand array, boolean implicitNullException) { - XirOperand length = asm.createTemp("length", CiKind.Int); - genArrayLength(asm, length, array, implicitNullException); - return length; - } - - private void genArrayLength(CiXirAssembler asm, XirOperand length, XirOperand array, boolean implicitNullException) { - if (implicitNullException) { - asm.mark(MARK_IMPLICIT_NULL); - } - asm.pload(CiKind.Int, length, array, asm.i(config.arrayLengthOffset), implicitNullException); - } - - private KindTemplates arrayLoadTemplates = new KindTemplates(NULL_CHECK, READ_BARRIER, BOUNDS_CHECK, GIVEN_LENGTH) { - - @Override - protected XirTemplate create(CiXirAssembler asm, long flags, CiKind kind) { - XirOperand result = asm.restart(kind); - XirParameter array = asm.createInputParameter("array", CiKind.Object); - XirParameter index = asm.createInputParameter("index", CiKind.Int, true); - XirLabel failBoundsCheck = null; - // if the length is known the array cannot be null - boolean implicitNullException = is(NULL_CHECK, flags); - - if (is(BOUNDS_CHECK, flags)) { - // load the array length and check the index - failBoundsCheck = asm.createOutOfLineLabel("failBoundsCheck"); - XirOperand length; - if (is(GIVEN_LENGTH, flags)) { - length = asm.createInputParameter("length", CiKind.Int, true); - } else { - length = genArrayLength(asm, array, implicitNullException); - } - asm.jugteq(failBoundsCheck, index, length); - implicitNullException = false; - } - int elemSize = target.sizeInBytes(kind); - if (implicitNullException) { - asm.mark(MARK_IMPLICIT_NULL); - } - asm.pload(kind, result, array, index, config.getArrayOffset(kind), Scale.fromInt(elemSize), implicitNullException); - if (is(BOUNDS_CHECK, flags)) { - asm.bindOutOfLine(failBoundsCheck); - XirOperand scratch = asm.createRegisterTemp("scratch", target.wordKind, AMD64.r10); - asm.mov(scratch, wordConst(asm, compiler.getRuntime().encodeDeoptActionAndReason(RiDeoptAction.None, RiDeoptReason.BoundsCheckException))); - asm.callRuntime(CiRuntimeCall.Deoptimize, null); - asm.shouldNotReachHere(); - } - return asm.finishTemplate("arrayload<" + kind + ">"); - } - }; - - private SimpleTemplates getClassTemplates = new SimpleTemplates() { - @Override - protected XirTemplate create(CiXirAssembler asm, long flags) { - XirOperand result = asm.restart(CiKind.Object); - XirOperand object = asm.createInputParameter("object", CiKind.Object); - asm.pload(CiKind.Object, result, object, asm.i(config.hubOffset), is(NULL_CHECK, flags)); - asm.pload(CiKind.Object, result, result, asm.i(config.classMirrorOffset), false); - return asm.finishTemplate("getClass"); - } - }; - - private SimpleTemplates currentThreadTemplates = new SimpleTemplates() { - @Override - protected XirTemplate create(CiXirAssembler asm, long flags) { - XirOperand result = asm.restart(CiKind.Object); - XirOperand thread = asm.createRegisterTemp("thread", target.wordKind, AMD64.r15); - asm.pload(CiKind.Object, result, thread, asm.i(config.threadObjectOffset), false); - return asm.finishTemplate("currentThread"); - } - }; - - @Override - public XirSnippet genCurrentThread(XirSite site) { - return new XirSnippet(currentThreadTemplates.get(site)); - } - - @Override - public XirSnippet genGetClass(XirSite site, XirArgument object) { - return new XirSnippet(getClassTemplates.get(site), object); - } - private KindTemplates arrayCopyTemplates = new KindTemplates() { @Override @@ -1095,111 +935,6 @@ } }; - private KindTemplates arrayStoreTemplates = new KindTemplates(NULL_CHECK, WRITE_BARRIER, BOUNDS_CHECK, STORE_CHECK, GIVEN_LENGTH) { - - @Override - protected XirTemplate create(CiXirAssembler asm, long flags, CiKind kind) { - asm.restart(CiKind.Void); - XirParameter array = asm.createInputParameter("array", CiKind.Object); - XirParameter index = asm.createInputParameter("index", CiKind.Int, true); - XirParameter value = asm.createInputParameter("value", kind, kind != CiKind.Object); - XirOperand temp = asm.createTemp("temp", target.wordKind); - XirOperand valueHub = null; - XirOperand compHub = null; - XirLabel store = asm.createInlineLabel("store"); - XirLabel failBoundsCheck = null; - XirLabel slowStoreCheck = null; - // if the length is known the array cannot be null - boolean implicitNullException = is(NULL_CHECK, flags); - - if (is(BOUNDS_CHECK, flags)) { - // load the array length and check the index - failBoundsCheck = asm.createOutOfLineLabel("failBoundsCheck"); - XirOperand length; - if (is(GIVEN_LENGTH, flags)) { - length = asm.createInputParameter("length", CiKind.Int); - } else { - length = asm.createTemp("length", CiKind.Int); - if (implicitNullException) { - asm.mark(MARK_IMPLICIT_NULL); - } - asm.pload(CiKind.Int, length, array, asm.i(config.arrayLengthOffset), implicitNullException); - implicitNullException = false; - } - asm.jugteq(failBoundsCheck, index, length); - - } - if (is(STORE_CHECK, flags) && kind == CiKind.Object) { - slowStoreCheck = asm.createOutOfLineLabel("slowStoreCheck"); - asm.jeq(store, value, asm.o(null)); // first check if value is null - valueHub = asm.createTemp("valueHub", CiKind.Object); - compHub = asm.createTemp("compHub", CiKind.Object); - if (implicitNullException) { - asm.mark(MARK_IMPLICIT_NULL); - } - asm.pload(CiKind.Object, compHub, array, asm.i(config.hubOffset), implicitNullException); - asm.pload(CiKind.Object, compHub, compHub, asm.i(config.arrayClassElementOffset), false); - asm.pload(CiKind.Object, valueHub, value, asm.i(config.hubOffset), false); - asm.jneq(slowStoreCheck, compHub, valueHub); // then check component hub matches value hub - - implicitNullException = false; - } - asm.bindInline(store); - int elemSize = target.sizeInBytes(kind); - - if (implicitNullException) { - asm.mark(MARK_IMPLICIT_NULL); - } - int disp = config.getArrayOffset(kind); - Scale scale = Scale.fromInt(elemSize); - if (kind == CiKind.Object) { - verifyPointer(asm, value); - } - if (is(WRITE_BARRIER, flags) && kind == CiKind.Object) { - asm.lea(temp, array, index, disp, scale); - asm.pstore(kind, temp, value, implicitNullException); - writeBarrier(asm, temp); - } else { - asm.pstore(kind, array, index, value, disp, scale, implicitNullException); - } - - // -- out of line ------------------------------------------------------- - if (is(BOUNDS_CHECK, flags)) { - asm.bindOutOfLine(failBoundsCheck); - XirOperand scratch = asm.createRegisterTemp("scratch", target.wordKind, AMD64.r10); - asm.mov(scratch, wordConst(asm, compiler.getRuntime().encodeDeoptActionAndReason(RiDeoptAction.None, RiDeoptReason.BoundsCheckException))); - asm.callRuntime(CiRuntimeCall.Deoptimize, null); - asm.shouldNotReachHere(); - } - if (is(STORE_CHECK, flags) && kind == CiKind.Object) { - useRegisters(asm, AMD64.rax); - asm.bindOutOfLine(slowStoreCheck); - checkSubtype(asm, temp, valueHub, compHub); - asm.jneq(store, temp, wordConst(asm, 0)); - XirOperand scratch = asm.createRegisterTemp("scratch", target.wordKind, AMD64.r10); - asm.mov(scratch, wordConst(asm, compiler.getRuntime().encodeDeoptActionAndReason(RiDeoptAction.None, RiDeoptReason.ArrayStoreException))); - asm.callRuntime(CiRuntimeCall.Deoptimize, null); - asm.shouldNotReachHere(); - } - return asm.finishTemplate("arraystore<" + kind + ">"); - } - }; - - private SimpleTemplates arrayLengthTemplates = new SimpleTemplates(NULL_CHECK) { - - @Override - protected XirTemplate create(CiXirAssembler asm, long flags) { - XirOperand result = asm.restart(CiKind.Int); - XirParameter object = asm.createInputParameter("object", CiKind.Object); - if (is(NULL_CHECK, flags)) { - asm.mark(MARK_IMPLICIT_NULL); - } - verifyPointer(asm, object); - asm.pload(CiKind.Int, result, object, asm.i(config.arrayLengthOffset), true); - return asm.finishTemplate("arrayLength"); - } - }; - private SimpleTemplates typeCheckTemplates = new SimpleTemplates(NULL_CHECK) { @Override protected XirTemplate create(CiXirAssembler asm, long flags) { @@ -1244,16 +979,6 @@ } @Override - public XirSnippet genResolveClass(XirSite site, RiType type, Representation rep) { - throw new CiBailout("Xir ResolveClass not available"); - } - - @Override - public XirSnippet genIntrinsic(XirSite site, XirArgument[] arguments, RiMethod method) { - return null; - } - - @Override public XirSnippet genInvokeInterface(XirSite site, XirArgument receiver, RiMethod method) { return new XirSnippet(invokeInterfaceTemplates.get(site), receiver, wordArg(0)); } @@ -1296,31 +1021,6 @@ } @Override - public XirSnippet genGetField(XirSite site, XirArgument object, RiField field) { - return new XirSnippet(getFieldTemplates.get(site, field.kind(false)), object, XirArgument.forInt(((HotSpotField) field).offset())); - } - - @Override - public XirSnippet genWriteBarrier(XirArgument object) { - return new XirSnippet(writeBarrierTemplate.get(null, CiKind.Void), object); - } - - @Override - public XirSnippet genPutField(XirSite site, XirArgument object, RiField field, XirArgument value) { - return new XirSnippet(putFieldTemplates.get(site, field.kind(false)), object, value, XirArgument.forInt(((HotSpotField) field).offset())); - } - - @Override - public XirSnippet genGetStatic(XirSite site, XirArgument object, RiField field) { - return new XirSnippet(getFieldTemplates.get(site, field.kind(false)), object, XirArgument.forInt(((HotSpotField) field).offset())); - } - - @Override - public XirSnippet genPutStatic(XirSite site, XirArgument object, RiField field, XirArgument value) { - return new XirSnippet(putFieldTemplates.get(site, field.kind(false)), object, value, XirArgument.forInt(((HotSpotField) field).offset())); - } - - @Override public XirSnippet genNewInstance(XirSite site, RiType type) { int instanceSize = ((HotSpotTypeResolved) type).instanceSize(); return new XirSnippet(newInstanceTemplates.get(site, instanceSize), XirArgument.forObject(type)); @@ -1339,11 +1039,6 @@ } @Override - public XirSnippet genNewObjectArrayClone(XirSite site, XirArgument newLength, XirArgument referenceArray) { - return new XirSnippet(newObjectArrayCloneTemplates.get(site), newLength, referenceArray); - } - - @Override public XirSnippet genNewMultiArray(XirSite site, XirArgument[] lengths, RiType type) { XirArgument[] params = Arrays.copyOf(lengths, lengths.length + 1); params[lengths.length] = XirArgument.forObject(type); @@ -1410,16 +1105,6 @@ } @Override - public XirSnippet genArrayLoad(XirSite site, XirArgument array, XirArgument index, CiKind elementKind, RiType elementType) { - return new XirSnippet(arrayLoadTemplates.get(site, elementKind), array, index); - } - - @Override - public XirSnippet genArrayStore(XirSite site, XirArgument array, XirArgument index, XirArgument value, CiKind elementKind, RiType elementType) { - return new XirSnippet(arrayStoreTemplates.get(site, elementKind), array, index, value); - } - - @Override public XirSnippet genArrayCopy(XirSite site, XirArgument src, XirArgument srcPos, XirArgument dest, XirArgument destPos, XirArgument length, RiType elementType, boolean inputsSame, boolean inputsDifferent) { if (elementType == null) { return null; @@ -1437,11 +1122,6 @@ } @Override - public XirSnippet genArrayLength(XirSite site, XirArgument array) { - return new XirSnippet(arrayLengthTemplates.get(site), array); - } - - @Override public XirSnippet genTypeBranch(XirSite site, XirArgument thisHub, XirArgument otherHub, RiType type) { assert type instanceof RiResolvedType; return new XirSnippet(typeCheckTemplates.get(site), thisHub, otherHub); @@ -1452,17 +1132,6 @@ this.globalAsm = asm; } - private void verifyPointer(CiXirAssembler asm, XirOperand pointer) { - if (config.verifyPointers) { - // The verify pointer stub wants the argument in a fixed register. - XirOperand fixed = asm.createRegisterTemp("fixed", CiKind.Object, AMD64.r13); - asm.push(fixed); - asm.mov(fixed, pointer); - asm.callRuntime(config.verifyPointerStub, null); - asm.pop(fixed); - } - } - private void checkSubtype(CiXirAssembler asm, XirOperand result, XirOperand objHub, XirOperand hub) { asm.push(objHub); asm.push(hub); @@ -1479,11 +1148,6 @@ } } - private void writeBarrier(CiXirAssembler asm, XirOperand base) { - asm.shr(base, base, asm.i(config.cardtableShift)); - asm.pstore(CiKind.Boolean, wordConst(asm, config.cardtableStartAddress), base, asm.b(false), false); - } - public boolean is(TemplateFlag check, long flags) { return (flags & check.bits()) == check.bits(); } diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ArrayCopySnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ArrayCopySnippets.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ArrayCopySnippets.java Wed Mar 28 22:17:38 2012 +0200 @@ -42,6 +42,8 @@ if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > src.length || destPos + length > dest.length) { throw new IndexOutOfBoundsException(); } + + // TODO remainder if (src == dest && srcPos < destPos) { // bad aliased case if ((length & 0x01) == 0) { if ((length & 0x02) == 0) { diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_putfield.java --- a/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_putfield.java Wed Mar 28 17:46:14 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2007, 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.jtt.bytecode; - -import org.junit.*; - -/* - */ -public class BC_putfield { - - private static BC_putfield object = new BC_putfield(); - - private int field; - - public static int test(int arg) { - object.field = arg; - return object.field; - } - - @Test - public void run0() throws Throwable { - Assert.assertEquals(0, test(0)); - } - - @Test - public void run1() throws Throwable { - Assert.assertEquals(1, test(1)); - } - - @Test - public void run2() throws Throwable { - Assert.assertEquals(2, test(2)); - } - - @Test - public void run3() throws Throwable { - Assert.assertEquals(-4, test(-4)); - } - -} diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_putfield_01.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_putfield_01.java Wed Mar 28 22:17:38 2012 +0200 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2007, 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.jtt.bytecode; + +import org.junit.*; + +/* + */ +public class BC_putfield_01 { + + private static BC_putfield_01 object = new BC_putfield_01(); + + private int field; + + public static int test(int arg) { + object.field = arg; + return object.field; + } + + @Test + public void run0() throws Throwable { + Assert.assertEquals(0, test(0)); + } + + @Test + public void run1() throws Throwable { + Assert.assertEquals(1, test(1)); + } + + @Test + public void run2() throws Throwable { + Assert.assertEquals(2, test(2)); + } + + @Test + public void run3() throws Throwable { + Assert.assertEquals(-4, test(-4)); + } + +} diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_putfield_02.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_putfield_02.java Wed Mar 28 22:17:38 2012 +0200 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2007, 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.jtt.bytecode; + +import org.junit.*; + +/* + */ +public class BC_putfield_02 { + + private static BC_putfield_02 object = new BC_putfield_02(); + + private Object field; + + public static Object test(Object arg) { + object.field = arg; + return object.field; + } + + @Test + public void run0() throws Throwable { + Assert.assertEquals("0", test("0")); + } + + @Test + public void run1() throws Throwable { + Assert.assertEquals(null, test(null)); + } + + @Test + public void run2() throws Throwable { + Assert.assertEquals("string", test("string")); + } + + @Test + public void run3() throws Throwable { + Assert.assertEquals("-4", test("-4")); + } + +} diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_putfield_03.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_putfield_03.java Wed Mar 28 22:17:38 2012 +0200 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2007, 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.jtt.bytecode; + +import org.junit.*; + +/* + */ +public class BC_putfield_03 { + + private static BC_putfield_03 object = new BC_putfield_03(); + + private volatile int field; + + public static int test(int arg) { + object.field = arg; + return object.field; + } + + @Test + public void run0() throws Throwable { + Assert.assertEquals(0, test(0)); + } + + @Test + public void run1() throws Throwable { + Assert.assertEquals(1, test(1)); + } + + @Test + public void run2() throws Throwable { + Assert.assertEquals(2, test(2)); + } + + @Test + public void run3() throws Throwable { + Assert.assertEquals(-4, test(-4)); + } + +} diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_putfield_04.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_putfield_04.java Wed Mar 28 22:17:38 2012 +0200 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2007, 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.jtt.bytecode; + +import org.junit.*; + +/* + */ +public class BC_putfield_04 { + + private static BC_putfield_04 object = new BC_putfield_04(); + + private volatile Object field; + + public static Object test(Object arg) { + object.field = arg; + return object.field; + } + + @Test + public void run0() throws Throwable { + Assert.assertEquals("0", test("0")); + } + + @Test + public void run1() throws Throwable { + Assert.assertEquals(null, test(null)); + } + + @Test + public void run2() throws Throwable { + Assert.assertEquals("string", test("string")); + } + + @Test + public void run3() throws Throwable { + Assert.assertEquals("-4", test("-4")); + } + +} diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/UnsafeAccess01.java --- a/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/UnsafeAccess01.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/UnsafeAccess01.java Wed Mar 28 22:17:38 2012 +0200 @@ -35,7 +35,7 @@ @SuppressWarnings("unused") private int field = 42; - public static int test() throws SecurityException, NoSuchFieldException, IllegalAccessException { + public static int test() throws SecurityException, NoSuchFieldException { final Unsafe unsafe = getUnsafe(); final UnsafeAccess01 object = new UnsafeAccess01(); @@ -45,10 +45,14 @@ return value; } - private static Unsafe getUnsafe() throws NoSuchFieldException, IllegalAccessException { - final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); - unsafeField.setAccessible(true); - return (Unsafe) unsafeField.get(null); + static Unsafe getUnsafe() { + try { + final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); + unsafeField.setAccessible(true); + return (Unsafe) unsafeField.get(null); + } catch (Exception e) { + throw new Error(e); + } } @Test diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/Unsafe_compareAndSwap.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/Unsafe_compareAndSwap.java Wed Mar 28 22:17:38 2012 +0200 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2008, 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.jtt.jdk; + +import org.junit.*; + +import sun.misc.*; + +public class Unsafe_compareAndSwap { + static final Unsafe unsafe = UnsafeAccess01.getUnsafe(); + static final long valueOffset; + static { + try { + valueOffset = unsafe.objectFieldOffset(Unsafe_compareAndSwap.class.getDeclaredField("value")); + } catch (Exception ex) { throw new Error(ex); } + } + + public static void test(Unsafe_compareAndSwap u, Object o, String expected, String newValue) { + // First arg is not an array - can use a field write barrier + unsafe.compareAndSwapObject(u, valueOffset, expected, newValue); + // Not known if first arg is an array - different write barrier may be used + unsafe.compareAndSwapObject(o, valueOffset, expected, newValue); + } + + private String value = "a"; + + @Test + public void run0() throws Throwable { + Unsafe_compareAndSwap u = new Unsafe_compareAndSwap(); + test(u, u, "a", "b"); + Assert.assertEquals(u.value, "b"); + } +} diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/LocationNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/LocationNode.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/LocationNode.java Wed Mar 28 22:17:38 2012 +0200 @@ -41,7 +41,12 @@ return "ANY_LOCATION"; } }; - public static final Object FINAL_LOCATION = new Object(); + public static final Object FINAL_LOCATION = new Object() { + @Override + public String toString() { + return "FINAL_LOCATION"; + } + }; public static Object getArrayLocation(CiKind elementKind) { return elementKind; diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/MembarNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/MembarNode.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/MembarNode.java Wed Mar 28 22:17:38 2012 +0200 @@ -25,14 +25,18 @@ import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; +import com.oracle.max.cri.util.*; /** - * Cretes a memory barrier. + * Creates a memory barrier. */ public class MembarNode extends AbstractStateSplit implements LIRLowerable, MemoryCheckpoint { private final int barriers; + /** + * @param barriers a mask of the barrier constants defined in {@link MemoryBarriers} + */ public MembarNode(int barriers) { super(StampFactory.illegal()); this.barriers = barriers; diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/ArrayLengthNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/ArrayLengthNode.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/ArrayLengthNode.java Wed Mar 28 22:17:38 2012 +0200 @@ -32,7 +32,7 @@ /** * The {@code ArrayLength} instruction gets the length of an array. */ -public final class ArrayLengthNode extends FixedWithNextNode implements Canonicalizable, Lowerable, LIRLowerable { +public final class ArrayLengthNode extends FixedWithNextNode implements Canonicalizable, Lowerable { @Input private ValueNode array; @@ -46,11 +46,6 @@ } @Override - public void generate(LIRGeneratorTool gen) { - gen.visitArrayLength(this); - } - - @Override public ValueNode canonical(CanonicalizerTool tool) { if (array() instanceof NewArrayNode) { ValueNode length = ((NewArrayNode) array()).dimension(0); diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CompareAndSwapNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CompareAndSwapNode.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CompareAndSwapNode.java Wed Mar 28 22:17:38 2012 +0200 @@ -23,22 +23,22 @@ package com.oracle.graal.nodes.java; import com.oracle.max.cri.ci.*; +import com.oracle.graal.cri.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; /** - * Represents an atomic compare-and-swap operation. If {@link #directResult} is true then the value read from the memory location is produced. - * Otherwise the result is a boolean that contains whether the value matched the expected value. + * Represents an atomic compare-and-swap operation + * The result is a boolean that contains whether the value matched the expected value. */ -public class CompareAndSwapNode extends AbstractStateSplit implements LIRLowerable, MemoryCheckpoint { +public class CompareAndSwapNode extends AbstractStateSplit implements LIRLowerable, Lowerable, MemoryCheckpoint { @Input private ValueNode object; @Input private ValueNode offset; @Input private ValueNode expected; @Input private ValueNode newValue; - @Data private final boolean directResult; public ValueNode object() { return object; @@ -56,22 +56,13 @@ return newValue; } - public boolean directResult() { - return directResult; - } - public CompareAndSwapNode(ValueNode object, ValueNode offset, ValueNode expected, ValueNode newValue) { - this(object, offset, expected, newValue, false); - } - - public CompareAndSwapNode(ValueNode object, ValueNode offset, ValueNode expected, ValueNode newValue, boolean directResult) { - super(StampFactory.forKind(directResult ? expected.kind().stackKind() : CiKind.Boolean.stackKind())); + super(StampFactory.forKind(CiKind.Boolean.stackKind())); assert expected.kind() == newValue.kind(); this.object = object; this.offset = offset; this.expected = expected; this.newValue = newValue; - this.directResult = directResult; } @Override @@ -79,6 +70,11 @@ gen.visitCompareAndSwap(this); } + @Override + public void lower(CiLoweringTool tool) { + tool.getRuntime().lower(this, tool); + } + // specialized on value type until boxing/unboxing is sorted out in intrinsification @SuppressWarnings("unused") @NodeIntrinsic diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadFieldNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadFieldNode.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadFieldNode.java Wed Mar 28 22:17:38 2012 +0200 @@ -32,7 +32,7 @@ /** * The {@code LoadFieldNode} represents a read of a static or instance field. */ -public final class LoadFieldNode extends AccessFieldNode implements Canonicalizable, LIRLowerable, Node.IterableNodeType { +public final class LoadFieldNode extends AccessFieldNode implements Canonicalizable, Node.IterableNodeType { /** * Creates a new LoadFieldNode instance. @@ -55,11 +55,6 @@ } @Override - public void generate(LIRGeneratorTool gen) { - gen.visitLoadField(this); - } - - @Override public boolean needsStateAfter() { return false; } diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadIndexedNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadIndexedNode.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadIndexedNode.java Wed Mar 28 22:17:38 2012 +0200 @@ -32,7 +32,7 @@ /** * The {@code LoadIndexedNode} represents a read from an element of an array. */ -public final class LoadIndexedNode extends AccessIndexedNode implements Lowerable, LIRLowerable, Node.IterableNodeType { +public final class LoadIndexedNode extends AccessIndexedNode implements Lowerable, Node.IterableNodeType { /** * Creates a new LoadIndexedNode. @@ -54,11 +54,6 @@ } @Override - public void generate(LIRGeneratorTool gen) { - gen.visitLoadIndexed(this); - } - - @Override public boolean needsStateAfter() { return false; } diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/StoreFieldNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/StoreFieldNode.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/StoreFieldNode.java Wed Mar 28 22:17:38 2012 +0200 @@ -22,15 +22,14 @@ */ package com.oracle.graal.nodes.java; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.type.*; import com.oracle.max.cri.ri.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.nodes.type.*; /** * The {@code StoreFieldNode} represents a write to a static or instance field. */ -public final class StoreFieldNode extends AccessFieldNode implements LIRLowerable { +public final class StoreFieldNode extends AccessFieldNode { @Input private ValueNode value; @@ -48,9 +47,4 @@ super(StampFactory.illegal(), object, field); this.value = value; } - - @Override - public void generate(LIRGeneratorTool gen) { - gen.visitStoreField(this); - } } diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/StoreIndexedNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/StoreIndexedNode.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/StoreIndexedNode.java Wed Mar 28 22:17:38 2012 +0200 @@ -31,7 +31,7 @@ /** * The {@code StoreIndexedNode} represents a write to an array element. */ -public final class StoreIndexedNode extends AccessIndexedNode implements Lowerable, LIRLowerable { +public final class StoreIndexedNode extends AccessIndexedNode implements Lowerable { @Input private ValueNode value; @@ -53,11 +53,6 @@ } @Override - public void generate(LIRGeneratorTool gen) { - gen.visitStoreIndexed(this); - } - - @Override public void lower(CiLoweringTool tool) { tool.getRuntime().lower(this, tool); } diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/LIRGeneratorTool.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/LIRGeneratorTool.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/LIRGeneratorTool.java Wed Mar 28 22:17:38 2012 +0200 @@ -106,14 +106,9 @@ // Functionality that is currently implemented in XIR. // These methods will go away eventually when lowering is done via snippets in the front end. - public abstract void visitArrayLength(ArrayLengthNode i); public abstract void visitCheckCast(CheckCastNode i); public abstract void visitMonitorEnter(MonitorEnterNode i); public abstract void visitMonitorExit(MonitorExitNode i); - public abstract void visitLoadField(LoadFieldNode i); - public abstract void visitStoreField(StoreFieldNode i); - public abstract void visitLoadIndexed(LoadIndexedNode i); - public abstract void visitStoreIndexed(StoreIndexedNode i); public abstract void visitNewInstance(NewInstanceNode i); public abstract void visitNewTypeArray(NewTypeArrayNode i); public abstract void visitNewObjectArray(NewObjectArrayNode i); diff -r 8d18583cf5f7 -r 597eade2394e graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/RiXirGenerator.java --- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/RiXirGenerator.java Wed Mar 28 17:46:14 2012 +0200 +++ b/graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/RiXirGenerator.java Wed Mar 28 22:17:38 2012 +0200 @@ -45,10 +45,6 @@ XirSnippet genExceptionObject(XirSite site); - XirSnippet genResolveClass(XirSite site, RiType type, Representation representation); - - XirSnippet genIntrinsic(XirSite site, XirArgument[] arguments, RiMethod method); - XirSnippet genInvokeInterface(XirSite site, XirArgument receiver, RiMethod method); XirSnippet genInvokeVirtual(XirSite site, XirArgument receiver, RiMethod method, boolean megamorph); @@ -61,20 +57,10 @@ XirSnippet genMonitorExit(XirSite site, XirArgument receiver, XirArgument lockAddress); - XirSnippet genGetField(XirSite site, XirArgument receiver, RiField field); - - XirSnippet genPutField(XirSite site, XirArgument receiver, RiField field, XirArgument value); - - XirSnippet genGetStatic(XirSite site, XirArgument staticTuple, RiField field); - - XirSnippet genPutStatic(XirSite site, XirArgument staticTuple, RiField field, XirArgument value); - XirSnippet genNewInstance(XirSite site, RiType type); XirSnippet genNewArray(XirSite site, XirArgument length, CiKind elementKind, RiType componentType, RiType arrayType); - XirSnippet genNewObjectArrayClone(XirSite site, XirArgument newLength, XirArgument referenceArray); - XirSnippet genNewMultiArray(XirSite site, XirArgument[] lengths, RiType type); XirSnippet genCheckCast(XirSite site, XirArgument receiver, XirArgument hub, RiType type, RiResolvedType[] hints, boolean hintsExact); @@ -83,20 +69,8 @@ XirSnippet genMaterializeInstanceOf(XirSite site, XirArgument receiver, XirArgument hub, XirArgument trueValue, XirArgument falseValue, RiType type, RiResolvedType[] hints, boolean hintsExact); - XirSnippet genArrayLoad(XirSite site, XirArgument array, XirArgument index, CiKind elementKind, RiType elementType); - - XirSnippet genArrayStore(XirSite site, XirArgument array, XirArgument index, XirArgument value, CiKind elementKind, RiType elementType); - - XirSnippet genArrayLength(XirSite site, XirArgument array); - - XirSnippet genWriteBarrier(XirArgument object); - XirSnippet genArrayCopy(XirSite site, XirArgument src, XirArgument srcPos, XirArgument dest, XirArgument destPos, XirArgument length, RiType elementType, boolean inputsSame, boolean inputsDifferent); - XirSnippet genCurrentThread(XirSite site); - - XirSnippet genGetClass(XirSite site, XirArgument xirArgument); - /** * Generates code that checks that the {@linkplain Representation#ObjectHub hub} of * an object is identical to a given hub constant. In pseudo code: diff -r 8d18583cf5f7 -r 597eade2394e mxtool/mx.py --- a/mxtool/mx.py Wed Mar 28 17:46:14 2012 +0200 +++ b/mxtool/mx.py Wed Mar 28 22:17:38 2012 +0200 @@ -1138,7 +1138,6 @@ jdtArgs = [java().java, '-Xmx1g', '-jar', jdtJar, '-' + args.compliance, '-cp', cp, '-g', '-enableJavadoc', - '-warn:-unusedImport,-unchecked', '-d', outputDir] jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs') if not exists(jdtProperties):