# HG changeset patch # User Chris Seaton # Date 1407273763 -3600 # Node ID e0be8b8a9a85df1e3c2c2825ec29f672aa6e25e8 # Parent 6de97968e3ef9d07a1ad61e846e0c569e4e0376c# Parent bd6b44b04143f69cbc14f2f0bcd8bc52bd6a8541 Merge. diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.asm.hsail/src/com/oracle/graal/asm/hsail/HSAILAssembler.java --- a/graal/com.oracle.graal.asm.hsail/src/com/oracle/graal/asm/hsail/HSAILAssembler.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.asm.hsail/src/com/oracle/graal/asm/hsail/HSAILAssembler.java Tue Aug 05 22:22:43 2014 +0100 @@ -324,7 +324,11 @@ } public static String mapAddress(HSAILAddress addr) { - return "[$d" + addr.getBase().encoding() + " + " + addr.getDisplacement() + "]"; + if (addr.getBase().encoding() < 0) { + return "[0x" + Long.toHexString(addr.getDisplacement()) + "]"; + } else { + return "[$d" + addr.getBase().encoding() + " + " + addr.getDisplacement() + "]"; + } } private static String doubleToString(double dval) { diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.compiler.hsail.test.infra/src/com/oracle/graal/compiler/hsail/test/infra/GraalKernelTester.java --- a/graal/com.oracle.graal.compiler.hsail.test.infra/src/com/oracle/graal/compiler/hsail/test/infra/GraalKernelTester.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.compiler.hsail.test.infra/src/com/oracle/graal/compiler/hsail/test/infra/GraalKernelTester.java Tue Aug 05 22:22:43 2014 +0100 @@ -131,6 +131,13 @@ } /** + * Determines if we are running CQE tests (via a -D flag) + */ + public boolean runningCQETests() { + return Boolean.getBoolean("com.amd.CQE"); + } + + /** * Determines if the JVM supports the required typeProfileWidth. */ public boolean typeProfileWidthAtLeast(int val) { diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleCosTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleCosTest.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleCosTest.java Tue Aug 05 22:22:43 2014 +0100 @@ -38,6 +38,12 @@ }); } + // internally allocates a Rempiostruct, escape analysis not catching it + @Override + protected boolean supportsRequiredCapabilities() { + return (canHandleObjectAllocation()); + } + @Test public void testUsingLambdaMethod() { testGeneratedHsailUsingLambdaMethod(); diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleNextAfterTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleNextAfterTest.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleNextAfterTest.java Tue Aug 05 22:22:43 2014 +0100 @@ -39,6 +39,11 @@ }); } + @Override + protected boolean supportsRequiredCapabilities() { + return (runningOnSimulator() || runningCQETests()); + } + @Test public void testUsingLambdaMethod() { testGeneratedHsailUsingLambdaMethod(); diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleNextUpTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleNextUpTest.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleNextUpTest.java Tue Aug 05 22:22:43 2014 +0100 @@ -38,6 +38,11 @@ }); } + @Override + protected boolean supportsRequiredCapabilities() { + return (runningOnSimulator() || runningCQETests()); + } + @Test public void testUsingLambdaMethod() { testGeneratedHsailUsingLambdaMethod(); diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleSinTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleSinTest.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleSinTest.java Tue Aug 05 22:22:43 2014 +0100 @@ -38,6 +38,12 @@ }); } + // internally allocates a Rempiostruct, escape analysis not catching it + @Override + protected boolean supportsRequiredCapabilities() { + return (canHandleObjectAllocation()); + } + @Test public void testUsingLambdaMethod() { testGeneratedHsailUsingLambdaMethod(); diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleTanTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleTanTest.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleTanTest.java Tue Aug 05 22:22:43 2014 +0100 @@ -38,6 +38,12 @@ }); } + // internally allocates a Rempiostruct, escape analysis not catching it + @Override + protected boolean supportsRequiredCapabilities() { + return (canHandleObjectAllocation()); + } + @Test public void testUsingLambdaMethod() { testGeneratedHsailUsingLambdaMethod(); diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatCosTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatCosTest.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatCosTest.java Tue Aug 05 22:22:43 2014 +0100 @@ -38,6 +38,12 @@ }); } + // internally allocates a Rempiostruct, escape analysis not catching it + @Override + protected boolean supportsRequiredCapabilities() { + return (canHandleObjectAllocation()); + } + @Test public void testUsingLambdaMethod() { testGeneratedHsailUsingLambdaMethod(); diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatNextAfterTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatNextAfterTest.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatNextAfterTest.java Tue Aug 05 22:22:43 2014 +0100 @@ -39,6 +39,11 @@ }); } + @Override + protected boolean supportsRequiredCapabilities() { + return (runningOnSimulator() || runningCQETests()); + } + @Test public void testUsingLambdaMethod() { testGeneratedHsailUsingLambdaMethod(); diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatNextUpTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatNextUpTest.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatNextUpTest.java Tue Aug 05 22:22:43 2014 +0100 @@ -38,6 +38,11 @@ }); } + @Override + protected boolean supportsRequiredCapabilities() { + return (runningOnSimulator() || runningCQETests()); + } + @Test public void testUsingLambdaMethod() { testGeneratedHsailUsingLambdaMethod(); diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatSinTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatSinTest.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatSinTest.java Tue Aug 05 22:22:43 2014 +0100 @@ -38,6 +38,12 @@ }); } + // internally allocates a Rempiostruct, escape analysis not catching it + @Override + protected boolean supportsRequiredCapabilities() { + return (canHandleObjectAllocation()); + } + @Test public void testUsingLambdaMethod() { testGeneratedHsailUsingLambdaMethod(); diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatTanTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatTanTest.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatTanTest.java Tue Aug 05 22:22:43 2014 +0100 @@ -38,6 +38,12 @@ }); } + // internally allocates a Rempiostruct, escape analysis not catching it + @Override + protected boolean supportsRequiredCapabilities() { + return (canHandleObjectAllocation()); + } + @Test public void testUsingLambdaMethod() { testGeneratedHsailUsingLambdaMethod(); diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringBuilderTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringBuilderTest.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringBuilderTest.java Tue Aug 05 22:22:43 2014 +0100 @@ -47,7 +47,7 @@ @Override protected boolean supportsRequiredCapabilities() { - return (canHandleObjectAllocation()); + return (canHandleObjectAllocation() && (runningOnSimulator() || runningCQETests())); } @Test diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MemoryUsageBenchmark.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MemoryUsageBenchmark.java Tue Aug 05 22:20:06 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2011, 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.compiler.test; - -import static com.oracle.graal.debug.internal.MemUseTrackerImpl.*; - -import java.lang.reflect.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.nodes.*; - -/** - * Used to benchmark memory usage during Graal compilation. - */ -public class MemoryUsageBenchmark extends GraalCompilerTest { - - public static int simple(int a, int b) { - return a + b; - } - - public static int complex(CharSequence cs) { - if (cs instanceof String) { - return cs.hashCode(); - } - int[] hash = {0}; - cs.chars().forEach(c -> hash[0] += c); - return hash[0]; - } - - static class MemoryUsageCloseable implements AutoCloseable { - - private final long start; - private final String name; - - public MemoryUsageCloseable(String name) { - this.name = name; - this.start = getCurrentThreadAllocatedBytes(); - } - - @Override - public void close() { - long end = getCurrentThreadAllocatedBytes(); - long allocated = end - start; - System.out.println(name + ": " + allocated); - } - } - - public static void main(String[] args) { - new MemoryUsageBenchmark().run(); - } - - private void doCompilation(StructuredGraph graph) { - CompilationResult compResult = super.compile(graph.method(), graph); - addMethod(graph.method(), compResult); - } - - private void compileAndTime(String methodName) { - Method method = getMethod(methodName); - StructuredGraph graph = parse(method); - - try (MemoryUsageCloseable c = new MemoryUsageCloseable(methodName + "[cold]")) { - doCompilation(graph); - } - - // Warm up compiler for this compilation - for (int i = 0; i < 10; i++) { - doCompilation(graph); - } - - try (MemoryUsageCloseable c = new MemoryUsageCloseable(methodName + "[warm]")) { - doCompilation(graph); - } - } - - public void run() { - compileAndTime("simple"); - compileAndTime("complex"); - } -} diff -r 6de97968e3ef -r e0be8b8a9a85 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 Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java Tue Aug 05 22:22:43 2014 +0100 @@ -686,7 +686,9 @@ String iterationObjArgReg = HSAIL.mapRegister(cc.getArgument(nonConstantParamCount - 1)); /* * iterationObjArgReg will be the highest $d register in use (it is the last parameter) - * so tempReg can be the next higher $d register + * so tempReg can be the next higher $d register. As of 1.0 spec, we cannot use + * ld_global_u32 $dxx, [addr]; so we need a temporary $s register. We can use + * workItemReg+1; */ String tmpReg = "$d" + (asRegister(cc.getArgument(nonConstantParamCount - 1)).encoding() + 1); // Convert gid to long. @@ -699,9 +701,13 @@ asm.emitString("add_u64 " + tmpReg + ", " + tmpReg + ", " + iterationObjArgReg + "; // Add to array ref ptr"); // Load the object into the parameter reg. if (useCompressedOops) { + int workItemRegEncoding = asRegister(cc.getArgument(nonConstantParamCount)).encoding(); + String tmpReg32 = "$s" + Integer.toString(workItemRegEncoding + 1); - // Load u32 into the d 64 reg since it will become an object address - asm.emitString("ld_global_u32 " + tmpReg + ", " + "[" + tmpReg + "]" + "; // Load compressed ptr from array"); + // Load u32 into the temporary $s reg since it will become an object address + + asm.emitString("ld_global_u32 " + tmpReg32 + ", " + "[" + tmpReg + "]" + "; // Load compressed ptr from array"); + asm.emitString("cvt_u64_u32 " + tmpReg + ", " + tmpReg32 + "; // cvt to 64 bits"); long narrowOopBase = config.narrowOopBase; long narrowOopShift = config.narrowOopShift; diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.hotspot.jdk8.test/src/com/oracle/graal/hotspot/jdk8/test/CRC32UpdateByteBufferSubstitutionTest.java --- a/graal/com.oracle.graal.hotspot.jdk8.test/src/com/oracle/graal/hotspot/jdk8/test/CRC32UpdateByteBufferSubstitutionTest.java Tue Aug 05 22:20:06 2014 +0100 +++ /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.hotspot.jdk8.test; - -import java.io.*; -import java.nio.*; -import java.util.zip.*; - -import org.junit.*; - -import com.oracle.graal.compiler.test.*; - -/** - * Tests compiled call to {@link CRC32#updateByteBuffer(int, long, int, int)}. - */ -@SuppressWarnings("javadoc") -public class CRC32UpdateByteBufferSubstitutionTest extends GraalCompilerTest { - - public static long updateByteBuffer(ByteBuffer buffer) { - CRC32 crc = new CRC32(); - buffer.rewind(); - crc.update(buffer); - return crc.getValue(); - } - - @Test - public void test1() throws Throwable { - String classfileName = CRC32UpdateByteBufferSubstitutionTest.class.getSimpleName().replace('.', '/') + ".class"; - InputStream s = CRC32UpdateByteBufferSubstitutionTest.class.getResourceAsStream(classfileName); - byte[] buf = new byte[s.available()]; - new DataInputStream(s).readFully(buf); - - ByteBuffer directBuf = ByteBuffer.allocateDirect(buf.length); - directBuf.put(buf); - ByteBuffer heapBuf = ByteBuffer.wrap(buf); - - test("updateByteBuffer", directBuf); - test("updateByteBuffer", heapBuf); - } -} diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/CRC32SubstitutionsTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/CRC32SubstitutionsTest.java Tue Aug 05 22:20:06 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/CRC32SubstitutionsTest.java Tue Aug 05 22:22:43 2014 +0100 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.test; import java.io.*; +import java.nio.*; import java.util.zip.*; import org.junit.*; @@ -74,4 +75,26 @@ } } + public static long updateByteBuffer(ByteBuffer buffer) { + CRC32 crc = new CRC32(); + buffer.rewind(); + crc.update(buffer); + return crc.getValue(); + } + + @Test + public void test4() throws Throwable { + String classfileName = CRC32SubstitutionsTest.class.getSimpleName().replace('.', '/') + ".class"; + InputStream s = CRC32SubstitutionsTest.class.getResourceAsStream(classfileName); + byte[] buf = new byte[s.available()]; + new DataInputStream(s).readFully(buf); + + ByteBuffer directBuf = ByteBuffer.allocateDirect(buf.length); + directBuf.put(buf); + ByteBuffer heapBuf = ByteBuffer.wrap(buf); + + test("updateByteBuffer", directBuf); + test("updateByteBuffer", heapBuf); + } + } diff -r 6de97968e3ef -r e0be8b8a9a85 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java Tue Aug 05 22:22:43 2014 +0100 @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2011, 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.test; + +import static com.oracle.graal.debug.internal.MemUseTrackerImpl.*; +import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; +import static com.oracle.graal.nodes.StructuredGraph.*; + +import com.oracle.graal.compiler.test.*; +import com.oracle.graal.debug.*; +import com.oracle.graal.debug.internal.*; +import com.oracle.graal.hotspot.*; +import com.oracle.graal.hotspot.meta.*; +import com.oracle.graal.printer.*; + +/** + * Used to benchmark memory usage during Graal compilation. Run with: + * + *
+ *     mx vm -XX:-UseGraalClassLoader -cp @com.oracle.graal.hotspot.test com.oracle.graal.hotspot.test.MemoryUsageBenchmark
+ * 
+ */ +public class MemoryUsageBenchmark extends GraalCompilerTest { + + public static int simple(int a, int b) { + return a + b; + } + + public static int complex(CharSequence cs) { + if (cs instanceof String) { + return cs.hashCode(); + } + + if (cs instanceof StringBuffer) { + int[] hash = {0}; + cs.chars().forEach(c -> hash[0] += c); + return hash[0]; + } + + int res = 0; + + // Exercise lock elimination + synchronized (cs) { + res = cs.length(); + } + synchronized (cs) { + res = cs.hashCode() ^ 31; + } + + for (int i = 0; i < cs.length(); i++) { + res *= cs.charAt(i); + } + return res; + } + + static class MemoryUsageCloseable implements AutoCloseable { + + private final long start; + private final String name; + + public MemoryUsageCloseable(String name) { + this.name = name; + this.start = getCurrentThreadAllocatedBytes(); + } + + @Override + public void close() { + long end = getCurrentThreadAllocatedBytes(); + long allocated = end - start; + System.out.println(name + ": " + allocated); + } + } + + public static void main(String[] args) { + // Ensure a debug configuration for this thread is initialized + if (Debug.isEnabled() && DebugScope.getConfig() == null) { + DebugEnvironment.initialize(System.out); + } + new MemoryUsageBenchmark().run(); + } + + private void doCompilation(String methodName) { + HotSpotResolvedJavaMethod method = (HotSpotResolvedJavaMethod) getMetaAccess().lookupJavaMethod(getMethod(methodName)); + HotSpotBackend backend = runtime().getHostBackend(); + int id = method.allocateCompileId(INVOCATION_ENTRY_BCI); + long ctask = 0L; + CompilationTask task = new CompilationTask(backend, method, INVOCATION_ENTRY_BCI, ctask, id); + task.runCompilation(); + + // invalidate the compiled code + method.reprofile(); + } + + private static final boolean verbose = Boolean.getBoolean("verbose"); + + private void compileAndTime(String methodName) { + // Warm up and initialize compiler phases used by this compilation + for (int i = 0; i < 10; i++) { + try (MemoryUsageCloseable c = verbose ? new MemoryUsageCloseable(methodName + "[" + i + "]") : null) { + doCompilation(methodName); + } + } + + try (MemoryUsageCloseable c = new MemoryUsageCloseable(methodName + "[warm]")) { + doCompilation(methodName); + } + } + + public void run() { + compileAndTime("complex"); + compileAndTime("simple"); + } +} diff -r 6de97968e3ef -r e0be8b8a9a85 mx/projects --- a/mx/projects Tue Aug 05 22:20:06 2014 +0100 +++ b/mx/projects Tue Aug 05 22:22:43 2014 +0100 @@ -318,14 +318,6 @@ project@com.oracle.graal.hotspot.test@javaCompliance=1.8 project@com.oracle.graal.hotspot.test@workingSets=Graal,HotSpot,Test -# graal.hotspot.jdk8.test -project@com.oracle.graal.hotspot.jdk8.test@subDir=graal -project@com.oracle.graal.hotspot.jdk8.test@sourceDirs=src -project@com.oracle.graal.hotspot.jdk8.test@dependencies=com.oracle.graal.compiler.test -project@com.oracle.graal.hotspot.jdk8.test@checkstyle=com.oracle.graal.graph -project@com.oracle.graal.hotspot.jdk8.test@javaCompliance=1.8 -project@com.oracle.graal.hotspot.jdk8.test@workingSets=Graal,HotSpot,Test - # graal.hotspot.amd64.test project@com.oracle.graal.hotspot.amd64.test@subDir=graal project@com.oracle.graal.hotspot.amd64.test@sourceDirs=src