# HG changeset patch # User Michael Van De Vanter # Date 1407204176 25200 # Node ID 6fdfe46660a11eae30f20abe3659996880809557 # Parent 7c8ddb4233cdd210256bb247c0787739159c01ae# Parent 4d0d1dc5db0039a0c7a0a1f127819b222b49a3a1 Merge with 4d0d1dc5db0039a0c7a0a1f127819b222b49a3a1 diff -r 7c8ddb4233cd -r 6fdfe46660a1 .hgignore --- a/.hgignore Mon Aug 04 18:53:21 2014 -0700 +++ b/.hgignore Mon Aug 04 19:02:56 2014 -0700 @@ -71,13 +71,13 @@ .idea/ ^cscope.out ^tags -graal.src.zip* -graal-loader.src.zip* syntax: glob *.bgv core.* *.jar *.jar.* +*.zip +*.zip.* eclipse-build.xml rebuild-launch.out coverage diff -r 7c8ddb4233cd -r 6fdfe46660a1 graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestJavaType.java --- a/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestJavaType.java Mon Aug 04 18:53:21 2014 -0700 +++ b/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestJavaType.java Mon Aug 04 19:02:56 2014 -0700 @@ -24,11 +24,6 @@ import static org.junit.Assert.*; -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.stream.*; - import org.junit.*; import com.oracle.graal.api.meta.*; @@ -50,91 +45,4 @@ assertEquals(expected, actual); } } - - static class A { - A or(A other) { - return other; - } - } - - @Test - public void testResolve() throws ClassNotFoundException { - String classPath = System.getProperty("java.class.path"); - String[] parts = classPath.split(File.pathSeparator); - URL[] urls = Arrays.asList(parts).stream().map(e -> asURL(e)).collect(Collectors.toList()).toArray(new URL[parts.length]); - URLClassLoader clOne = newClassLoader(urls); - URLClassLoader clTwo = newClassLoader(urls); - - String className = getClass().getName() + "$A"; - Class aClassOne = Class.forName(className, true, clOne); - Class aClassTwo = Class.forName(getClass().getName() + "$A", true, clTwo); - - assertNotEquals(aClassOne, aClassTwo); - assertNotEquals(aClassOne.getClassLoader(), aClassTwo.getClassLoader()); - - ResolvedJavaType aTypeOne = metaAccess.lookupJavaType(aClassOne); - ResolvedJavaType aTypeTwo = metaAccess.lookupJavaType(aClassTwo); - - assertNotEquals(aTypeOne, aTypeTwo); - - checkResolveWithoutAccessingClass(aTypeOne); - checkResolveWithoutAccessingClass(aTypeTwo); - - assertEquals(aTypeOne.resolve(aTypeOne), aTypeOne); - assertNotEquals(aTypeOne.resolve(aTypeTwo), aTypeOne); - assertEquals(aTypeOne.resolve(aTypeTwo), aTypeTwo); - - assertEquals(aTypeTwo.resolve(aTypeTwo), aTypeTwo); - assertNotEquals(aTypeTwo.resolve(aTypeOne), aTypeTwo); - assertEquals(aTypeTwo.resolve(aTypeOne), aTypeOne); - - ResolvedJavaMethod m = ResolvedJavaTypeResolveMethodTest.getMethod(aTypeOne, "or"); - JavaType resolvedTypeOne = m.getSignature().getParameterType(0, aTypeOne); - JavaType resolvedTypeTwo = m.getSignature().getReturnType(aTypeOne); - JavaType unresolvedTypeOne = m.getSignature().getParameterType(0, null); - JavaType unresolvedTypeTwo = m.getSignature().getReturnType(null); - - assertTrue(resolvedTypeOne instanceof ResolvedJavaType); - assertTrue(resolvedTypeTwo instanceof ResolvedJavaType); - assertFalse(unresolvedTypeOne instanceof ResolvedJavaType); - assertFalse(unresolvedTypeTwo instanceof ResolvedJavaType); - - assertEquals(resolvedTypeOne.resolve(aTypeOne), aTypeOne); - assertEquals(resolvedTypeOne.resolve(aTypeTwo), aTypeTwo); - assertEquals(resolvedTypeTwo.resolve(aTypeOne), aTypeOne); - assertEquals(resolvedTypeTwo.resolve(aTypeTwo), aTypeTwo); - - checkResolveWithoutAccessingClass(unresolvedTypeOne); - checkResolveWithoutAccessingClass(unresolvedTypeTwo); - - assertEquals(unresolvedTypeOne.resolve(aTypeOne), aTypeOne); - assertEquals(unresolvedTypeOne.resolve(aTypeTwo), aTypeTwo); - } - - private static void checkResolveWithoutAccessingClass(JavaType type) { - try { - type.resolve(null); - fail(); - } catch (NullPointerException e) { - } - } - - private static URLClassLoader newClassLoader(URL[] urls) { - URLClassLoader cl = new URLClassLoader(urls) { - @Override - protected java.lang.Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - boolean callSuper = name.startsWith("java/") || name.startsWith("java."); - return callSuper ? super.loadClass(name, resolve) : super.findClass(name); - } - }; - return cl; - } - - private static URL asURL(String e) { - try { - return new File(e).toURI().toURL(); - } catch (MalformedURLException e1) { - throw new RuntimeException(e1); - } - } } diff -r 7c8ddb4233cd -r 6fdfe46660a1 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Mon Aug 04 18:53:21 2014 -0700 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Mon Aug 04 19:02:56 2014 -0700 @@ -1082,19 +1082,31 @@ static { Set metrics = new HashSet<>(); Set timers = new HashSet<>(); - for (Map.Entry e : System.getProperties().entrySet()) { - String name = e.getKey().toString(); - if (name.startsWith(ENABLE_METRIC_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { - metrics.add(name.substring(ENABLE_METRIC_PROPERTY_NAME_PREFIX.length())); - } - if (name.startsWith(ENABLE_TIMER_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { - timers.add(name.substring(ENABLE_TIMER_PROPERTY_NAME_PREFIX.length())); - } - } + parseMetricAndTimerSystemProperties(metrics, timers); enabledMetrics = metrics.isEmpty() ? null : metrics; enabledTimers = timers.isEmpty() ? null : timers; } + protected static void parseMetricAndTimerSystemProperties(Set metrics, Set timers) { + do { + try { + for (Map.Entry e : System.getProperties().entrySet()) { + String name = e.getKey().toString(); + if (name.startsWith(ENABLE_METRIC_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { + metrics.add(name.substring(ENABLE_METRIC_PROPERTY_NAME_PREFIX.length())); + } + if (name.startsWith(ENABLE_TIMER_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { + timers.add(name.substring(ENABLE_TIMER_PROPERTY_NAME_PREFIX.length())); + } + } + return; + } catch (ConcurrentModificationException e) { + // Iterating over the system properties may race with another thread that is + // updating the system properties. Simply try again in this case. + } + } while (true); + } + /** * Creates a {@linkplain DebugTimer timer} that is enabled iff debugging is * {@linkplain #isEnabled() enabled} or the system property whose name is formed by adding to diff -r 7c8ddb4233cd -r 6fdfe46660a1 graal/com.oracle.graal.hotspot.loader/src/com/oracle/graal/hotspot/loader/Factory.java --- a/graal/com.oracle.graal.hotspot.loader/src/com/oracle/graal/hotspot/loader/Factory.java Mon Aug 04 18:53:21 2014 -0700 +++ b/graal/com.oracle.graal.hotspot.loader/src/com/oracle/graal/hotspot/loader/Factory.java Mon Aug 04 19:02:56 2014 -0700 @@ -40,7 +40,8 @@ @SuppressWarnings("unused") private static ClassLoader newClassLoader() throws MalformedURLException { URL[] urls = {getGraalJarUrl("graal"), getGraalJarUrl("graal-truffle")}; - return URLClassLoader.newInstance(urls); + ClassLoader parent = null; + return URLClassLoader.newInstance(urls, parent); } /** diff -r 7c8ddb4233cd -r 6fdfe46660a1 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/BytecodeVerificationTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/BytecodeVerificationTest.java Mon Aug 04 18:53:21 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2014, 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 java.io.*; - -import jdk.internal.org.objectweb.asm.*; - -import org.junit.*; - -import com.oracle.graal.compiler.test.*; - -/** - * Tests that the Graal API can only be used to access verified bytecode. - */ -public class BytecodeVerificationTest extends GraalCompilerTest { - - @Test(expected = VerifyError.class) - public void test() throws Exception { - BadClassLoader loader = new BadClassLoader(); - String className = BytecodeVerificationTest.class.getName() + "$BadClass"; - Class c = loader.findClass(className); - - // Should fail with a verification error as long as -XX:-BytecodeVerificationRemote is not - // specified on the command line - getMetaAccess().lookupJavaMethod(c.getDeclaredMethod("getValue")).getCode(); - } - - /** - * Class that will be rewritten during loading to be unverifiable. - */ - public static class BadClass { - - public static String value; - - public static String getValue() { - // Re-written to "return 5;" - return value; - } - } - - /** - * Rewrites {@link BadClass#getValue()} to: - * - *
-     * public static String getValue() {
-     *     return 5;
-     * }
-     * 
- */ - private static class BadClassRewriter extends ClassVisitor { - - public BadClassRewriter(ClassWriter cw) { - super(Opcodes.ASM5, cw); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String d, String signature, String[] exceptions) { - MethodVisitor mv = super.visitMethod(access, name, d, signature, exceptions); - if (name.equals("getValue")) { - return new MethodVisitor(Opcodes.ASM5, mv) { - @Override - public void visitFieldInsn(int opcode, String owner, String fieldName, String fieldDesc) { - if (opcode == Opcodes.GETSTATIC) { - visitInsn(Opcodes.ICONST_5); - } else { - super.visitFieldInsn(opcode, owner, name, fieldDesc); - } - } - }; - } - return mv; - } - } - - /** - * Class loader used for loading {@link BadClass}. Using a separate class loader ensure the - * class is treated as "remote" so that it will be subject to verification by default. - */ - private static class BadClassLoader extends ClassLoader { - - @Override - protected Class findClass(final String name) throws ClassNotFoundException { - byte[] classData = null; - try { - InputStream is = BytecodeVerificationTest.class.getResourceAsStream("/" + name.replace('.', '/') + ".class"); - classData = new byte[is.available()]; - new DataInputStream(is).readFully(classData); - } catch (IOException e) { - Assert.fail("can't access class: " + name); - } - - ClassReader cr = new ClassReader(classData); - ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES); - - BadClassRewriter rewriter = new BadClassRewriter(cw); - cr.accept(rewriter, ClassReader.SKIP_FRAMES); - classData = cw.toByteArray(); - return defineClass(null, classData, 0, classData.length); - } - } -} diff -r 7c8ddb4233cd -r 6fdfe46660a1 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/GraalClassLoaderTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/GraalClassLoaderTest.java Mon Aug 04 18:53:21 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2014, 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 org.junit.*; - -import sun.management.*; - -import com.oracle.graal.api.runtime.*; -import com.sun.management.*; - -/** - * Tests that the Graal API is inaccessible when -XX:+UseGraalClassLoader is specified. Execute as - * follows to show class loader based isolation: - * - *
- * mx unittest -XX:+UseGraalClassLoader GraalClassLoaderTest
- * 
- */ -public class GraalClassLoaderTest { - - @Test - public void test() throws Exception { - if (System.getProperty("java.vm.version").contains("graal")) { - HotSpotDiagnosticMXBean diag = ManagementFactoryHelper.getDiagnosticMXBean(); - VMOption option = diag.getVMOption("UseGraalClassLoader"); - if (option.getValue().equals("true")) { - try { - Graal.getRuntime(); - Assert.fail(); - } catch (NoClassDefFoundError e) { - // expected - } - } - } - } - -} \ No newline at end of file diff -r 7c8ddb4233cd -r 6fdfe46660a1 mx/mx_graal.py --- a/mx/mx_graal.py Mon Aug 04 18:53:21 2014 -0700 +++ b/mx/mx_graal.py Mon Aug 04 19:02:56 2014 -0700 @@ -765,7 +765,7 @@ if build is None or len(build) == 0: continue - jdk = _jdk(build, create=True) + jdk = _jdk(build, create=True, installJars=not opts2.java) if vm == 'original': if build != 'product': diff -r 7c8ddb4233cd -r 6fdfe46660a1 mx/projects --- a/mx/projects Mon Aug 04 18:53:21 2014 -0700 +++ b/mx/projects Mon Aug 04 19:02:56 2014 -0700 @@ -82,9 +82,9 @@ library@VECMATH@urls=http://lafo.ssw.uni-linz.ac.at/graal-external-deps/vecmath-1.3.1.jar,http://mirrors.ibiblio.org/pub/mirrors/maven/java3d/jars/vecmath-1.3.1.jar library@VECMATH@sha1=a0ae4f51da409fa0c20fa0ca59e6bbc9413ae71d -distribution@GRAAL@path=graal.jar +distribution@GRAAL@path=build/graal.jar distribution@GRAAL@subDir=graal -distribution@GRAAL@sourcesPath=graal.src.zip +distribution@GRAAL@sourcesPath=build/graal.src.zip distribution@GRAAL@dependencies=\ com.oracle.graal.hotspot.amd64,\ com.oracle.graal.hotspot.ptx,\ @@ -94,29 +94,29 @@ com.oracle.graal.hotspot.hsail distribution@GRAAL@exclude=FINDBUGS -distribution@GRAAL_LOADER@path=graal-loader.jar +distribution@GRAAL_LOADER@path=build/graal-loader.jar distribution@GRAAL_LOADER@subDir=graal -distribution@GRAAL_LOADER@sourcesPath=graal-loader.src.zip +distribution@GRAAL_LOADER@sourcesPath=build/graal-loader.src.zip distribution@GRAAL_LOADER@dependencies=com.oracle.graal.hotspot.loader -distribution@TRUFFLE@path=truffle.jar +distribution@TRUFFLE@path=build/truffle.jar distribution@TRUFFLE@subDir=graal -distribution@TRUFFLE@sourcesPath=truffle.src.zip +distribution@TRUFFLE@sourcesPath=build/truffle.src.zip distribution@TRUFFLE@dependencies=\ com.oracle.truffle.api.dsl -distribution@GRAAL_TRUFFLE@path=graal-truffle.jar +distribution@GRAAL_TRUFFLE@path=build/graal-truffle.jar distribution@GRAAL_TRUFFLE@subDir=graal -distribution@GRAAL_TRUFFLE@sourcesPath=graal-truffle.src.zip +distribution@GRAAL_TRUFFLE@sourcesPath=build/graal-truffle.src.zip distribution@GRAAL_TRUFFLE@dependencies=\ com.oracle.graal.truffle,\ com.oracle.graal.truffle.hotspot.amd64 distribution@GRAAL_TRUFFLE@exclude=FINDBUGS distribution@GRAAL_TRUFFLE@distDependencies=GRAAL,TRUFFLE -distribution@TRUFFLE-DSL-PROCESSOR@path=truffle-dsl-processor.jar +distribution@TRUFFLE-DSL-PROCESSOR@path=build/truffle-dsl-processor.jar distribution@TRUFFLE-DSL-PROCESSOR@subDir=graal -distribution@TRUFFLE-DSL-PROCESSOR@sourcesPath=truffle-dsl-processor.src.zip +distribution@TRUFFLE-DSL-PROCESSOR@sourcesPath=build/truffle-dsl-processor.src.zip distribution@TRUFFLE-DSL-PROCESSOR@dependencies=\ com.oracle.truffle.dsl.processor distribution@TRUFFLE-DSL-PROCESSOR@distDependencies=TRUFFLE diff -r 7c8ddb4233cd -r 6fdfe46660a1 mxtool/mx.py --- a/mxtool/mx.py Mon Aug 04 18:53:21 2014 -0700 +++ b/mxtool/mx.py Mon Aug 04 19:02:56 2014 -0700 @@ -2686,6 +2686,8 @@ def __enter__(self): if self.path: + if not isdir(dirname(self.path)): + os.makedirs(dirname(self.path)) fd, tmp = tempfile.mkstemp(suffix='', prefix=basename(self.path) + '.', dir=dirname(self.path)) self.tmpFd = fd self.tmpPath = tmp diff -r 7c8ddb4233cd -r 6fdfe46660a1 src/share/vm/graal/graalRuntime.cpp --- a/src/share/vm/graal/graalRuntime.cpp Mon Aug 04 18:53:21 2014 -0700 +++ b/src/share/vm/graal/graalRuntime.cpp Mon Aug 04 19:02:56 2014 -0700 @@ -39,6 +39,7 @@ address GraalRuntime::_external_deopt_i2c_entry = NULL; jobject GraalRuntime::_HotSpotGraalRuntime_instance = NULL; +bool GraalRuntime::_HotSpotGraalRuntime_initialized = false; void GraalRuntime::initialize_natives(JNIEnv *env, jclass c2vmClass) { uintptr_t heap_end = (uintptr_t) Universe::heap()->reserved_region().end(); @@ -681,6 +682,7 @@ Handle GraalRuntime::get_HotSpotGraalRuntime() { if (JNIHandles::resolve(_HotSpotGraalRuntime_instance) == NULL) { + guarantee(!_HotSpotGraalRuntime_initialized, "cannot reinitialize HotSpotGraalRuntime"); Thread* THREAD = Thread::current(); check_generated_sources_sha1(CHECK_ABORT_(Handle())); TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/HotSpotGraalRuntime", CHECK_ABORT_(Handle())); @@ -690,6 +692,7 @@ JavaValue result(T_OBJECT); JavaCalls::call_static(&result, klass, runtime, sig, CHECK_ABORT_(Handle())); _HotSpotGraalRuntime_instance = JNIHandles::make_global((oop) result.get_jobject()); + _HotSpotGraalRuntime_initialized = true; } return Handle(JNIHandles::resolve_non_null(_HotSpotGraalRuntime_instance)); } @@ -990,6 +993,12 @@ CLEAR_PENDING_EXCEPTION; tty->print_cr(message); call_printStackTrace(exception, THREAD); + + // Give other aborting threads to also print their stack traces. + // This can be very useful when debugging class initialization + // failures. + os::sleep(THREAD, 200, false); + vm_abort(dump_core); } diff -r 7c8ddb4233cd -r 6fdfe46660a1 src/share/vm/graal/graalRuntime.hpp --- a/src/share/vm/graal/graalRuntime.hpp Mon Aug 04 18:53:21 2014 -0700 +++ b/src/share/vm/graal/graalRuntime.hpp Mon Aug 04 19:02:56 2014 -0700 @@ -32,6 +32,7 @@ private: static jobject _HotSpotGraalRuntime_instance; + static bool _HotSpotGraalRuntime_initialized; static address _external_deopt_i2c_entry; static const char* _generated_sources_sha1; @@ -111,7 +112,7 @@ static void initialize_natives(JNIEnv *env, jclass c2vmClass); - static bool is_HotSpotGraalRuntime_initialized() { return _HotSpotGraalRuntime_instance != NULL; } + static bool is_HotSpotGraalRuntime_initialized() { return _HotSpotGraalRuntime_initialized; } /** * Gets the singleton HotSpotGraalRuntime instance, initializing it if necessary