changeset 16395:ad431bf0de07

added support to load classes from graal.jar with a separate class loader
author Doug Simon <doug.simon@oracle.com>
date Thu, 03 Jul 2014 16:30:28 +0200
parents 0dd27c6472d7
children 5c0f2b338874
files .hgignore graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java graal/com.oracle.graal.hotspot.loader/src/com/oracle/graal/hotspot/loader/Factory.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java mx/mx_graal.py mx/projects src/share/vm/classfile/systemDictionary.cpp src/share/vm/classfile/systemDictionary.hpp src/share/vm/classfile/verifier.cpp src/share/vm/classfile/vmSymbols.hpp src/share/vm/graal/graalGlobals.hpp src/share/vm/graal/graalRuntime.cpp src/share/vm/graal/graalRuntime.hpp src/share/vm/oops/instanceKlass.cpp src/share/vm/prims/nativeLookup.cpp src/share/vm/runtime/arguments.cpp src/share/vm/runtime/javaCalls.cpp src/share/vm/runtime/os.cpp src/share/vm/runtime/os.hpp src/share/vm/runtime/thread.cpp
diffstat 20 files changed, 273 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Thu Jul 03 14:31:34 2014 +0200
+++ b/.hgignore	Thu Jul 03 16:30:28 2014 +0200
@@ -72,6 +72,7 @@
 ^cscope.out
 ^tags
 graal.src.zip*
+graal-loader.src.zip*
 syntax: glob
 *.bgv
 core.*
--- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java	Thu Jul 03 14:31:34 2014 +0200
+++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java	Thu Jul 03 16:30:28 2014 +0200
@@ -26,11 +26,10 @@
 import static com.oracle.graal.api.code.CallingConvention.Type.*;
 import static com.oracle.graal.api.code.ValueUtil.*;
 import static com.oracle.graal.compiler.common.GraalOptions.*;
+import static com.oracle.graal.compiler.common.UnsafeAccess.*;
 
 import java.util.*;
 
-import sun.misc.*;
-
 import com.oracle.graal.amd64.*;
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
@@ -56,8 +55,6 @@
  */
 public class AMD64HotSpotBackend extends HotSpotHostBackend {
 
-    private static final Unsafe unsafe = Unsafe.getUnsafe();
-
     public AMD64HotSpotBackend(HotSpotGraalRuntime runtime, HotSpotProviders providers) {
         super(runtime, providers);
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot.loader/src/com/oracle/graal/hotspot/loader/Factory.java	Thu Jul 03 16:30:28 2014 +0200
@@ -0,0 +1,56 @@
+/*
+ * 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.loader;
+
+import java.io.*;
+import java.net.*;
+
+/**
+ * Utility to create a separate class loader for loading classes in {@code graal.jar}.
+ */
+public class Factory {
+
+    /**
+     * Creates a new class loader for loading classes in {@code graal.jar}.
+     */
+    public static ClassLoader newClassLoader() throws MalformedURLException {
+        URL[] urls = {getGraalJarUrl()};
+        return URLClassLoader.newInstance(urls);
+    }
+
+    /**
+     * Gets the URL for {@code graal.jar}.
+     */
+    private static URL getGraalJarUrl() throws MalformedURLException {
+        File file = new File(System.getProperty("java.home"));
+        for (String name : new String[]{"lib", "graal.jar"}) {
+            file = new File(file, name);
+        }
+
+        if (!file.exists()) {
+            throw new InternalError(file + " does not exist");
+        }
+
+        return file.toURI().toURL();
+    }
+}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java	Thu Jul 03 14:31:34 2014 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java	Thu Jul 03 16:30:28 2014 +0200
@@ -26,7 +26,6 @@
 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
 import static com.oracle.graal.hotspot.meta.HotSpotForeignCallsProviderImpl.*;
 import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*;
-import sun.misc.*;
 
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
@@ -260,7 +259,7 @@
 
     @Fold
     public static int pageSize() {
-        return Unsafe.getUnsafe().pageSize();
+        return unsafe.pageSize();
     }
 
     @Fold
--- a/mx/mx_graal.py	Thu Jul 03 14:31:34 2014 +0200
+++ b/mx/mx_graal.py	Thu Jul 03 16:30:28 2014 +0200
@@ -459,6 +459,7 @@
 
     if installGraalJar:
         _installGraalJarInJdks(mx.distribution('GRAAL'))
+        _installGraalJarInJdks(mx.distribution('GRAAL_LOADER'))
 
     if vmToCheck is not None:
         jvmCfg = _vmCfgInJdk(jdk)
@@ -497,7 +498,8 @@
 
 def _installGraalJarInJdks(graalDist):
     graalJar = graalDist.path
-    _update_graalRuntime_inline_hpp(graalJar)
+    if graalJar.endswith('graal.jar'):
+        _update_graalRuntime_inline_hpp(graalJar)
     jdks = _jdksDir()
 
     if exists(jdks):
@@ -649,6 +651,7 @@
             assert os.path.isdir(opts2.export_dir), '{} is not a directory'.format(opts2.export_dir)
 
         shutil.copy(mx.distribution('GRAAL').path, opts2.export_dir)
+        shutil.copy(mx.distribution('GRAAL_LOADER').path, opts2.export_dir)
         graalOptions = join(_graal_home, 'graal.options')
         if exists(graalOptions):
             shutil.copy(graalOptions, opts2.export_dir)
@@ -1050,14 +1053,17 @@
             prefixArgs.append('-XX:-DisableExplicitGC')
         with open(testfile) as fp:
             testclasses = [l.rstrip() for l in fp.readlines()]
-            
-        # Remove entries from class path that are in graal.jar
+
+        # Remove entries from class path that are in graal.jar and
+        # run the VM in a mode where application/test classes can
+        # access core Graal classes.
         cp = prefixCp + coreCp + os.pathsep + projectsCp
         if isGraalEnabled(_get_vm()):
             graalDist = mx.distribution('GRAAL')
             graalJarCp = set([d.output_dir() for d in graalDist.sorted_deps()])
             cp = os.pathsep.join([e for e in cp.split(os.pathsep) if e not in graalJarCp])
-        
+            vmArgs = vmArgs + ['-XX:-UseGraalClassLoader']
+
         if len(testclasses) == 1:
             # Execute Junit directly when one test is being run. This simplifies
             # replaying the VM execution in a native debugger (e.g., gdb).
@@ -2185,3 +2191,4 @@
     _vm_prefix = opts.vm_prefix
 
     mx.distribution('GRAAL').add_update_listener(_installGraalJarInJdks)
+    mx.distribution('GRAAL_LOADER').add_update_listener(_installGraalJarInJdks)
--- a/mx/projects	Thu Jul 03 14:31:34 2014 +0200
+++ b/mx/projects	Thu Jul 03 16:30:28 2014 +0200
@@ -80,6 +80,11 @@
 com.oracle.graal.hotspot.hsail
 distribution@GRAAL@exclude=FINDBUGS
 
+distribution@GRAAL_LOADER@path=graal-loader.jar
+distribution@GRAAL_LOADER@subDir=graal
+distribution@GRAAL_LOADER@sourcesPath=graal-loader.src.zip
+distribution@GRAAL_LOADER@dependencies=com.oracle.graal.hotspot.loader
+
 distribution@TRUFFLE@path=truffle.jar
 distribution@TRUFFLE@subDir=graal
 distribution@TRUFFLE@sourcesPath=truffle-sources.jar
@@ -205,6 +210,14 @@
 project@com.oracle.graal.hotspot@javaCompliance=1.8
 project@com.oracle.graal.hotspot@workingSets=Graal,HotSpot
 
+# graal.hotspot
+project@com.oracle.graal.hotspot.loader@subDir=graal
+project@com.oracle.graal.hotspot.loader@sourceDirs=src
+project@com.oracle.graal.hotspot.loader@dependencies=
+project@com.oracle.graal.hotspot.loader@checkstyle=com.oracle.graal.graph
+project@com.oracle.graal.hotspot.loader@javaCompliance=1.8
+project@com.oracle.graal.hotspot.loader@workingSets=Graal,HotSpot
+
 # graal.hotspot.sourcegen
 project@com.oracle.graal.hotspot.sourcegen@subDir=graal
 project@com.oracle.graal.hotspot.sourcegen@sourceDirs=src
--- a/src/share/vm/classfile/systemDictionary.cpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/classfile/systemDictionary.cpp	Thu Jul 03 16:30:28 2014 +0200
@@ -57,6 +57,9 @@
 #include "services/threadService.hpp"
 #include "utilities/macros.hpp"
 #include "utilities/ticks.hpp"
+#ifdef GRAAL
+#include "graal/graalRuntime.hpp"
+#endif
 
 #if INCLUDE_TRACE
  #include "trace/tracing.hpp"
@@ -87,6 +90,14 @@
 bool        SystemDictionary::_has_loadClassInternal      =  false;
 bool        SystemDictionary::_has_checkPackageAccess     =  false;
 
+#ifdef GRAAL
+oop         SystemDictionary::_graal_loader               = NULL;
+
+oop SystemDictionary::graal_loader() {
+  return _graal_loader;
+}
+#endif
+
 // lazily initialized klass variables
 Klass* volatile SystemDictionary::_abstract_ownable_synchronizer_klass = NULL;
 
@@ -1666,6 +1677,9 @@
 void SystemDictionary::always_strong_oops_do(OopClosure* blk) {
   blk->do_oop(&_java_system_loader);
   blk->do_oop(&_system_loader_lock_obj);
+#ifdef GRAAL
+  blk->do_oop(&_graal_loader);
+#endif
 
   dictionary()->always_strong_oops_do(blk);
 
@@ -1740,6 +1754,9 @@
 void SystemDictionary::oops_do(OopClosure* f) {
   f->do_oop(&_java_system_loader);
   f->do_oop(&_system_loader_lock_obj);
+#ifdef GRAAL
+  f->do_oop(&_graal_loader);
+#endif
 
   // Adjust dictionary
   dictionary()->oops_do(f);
@@ -1859,6 +1876,14 @@
   Klass**    klassp = &_well_known_klasses[id];
   bool must_load = (init_opt < SystemDictionary::Opt);
   if ((*klassp) == NULL) {
+#ifdef GRAAL
+    bool is_graal = init_opt == SystemDictionary::Graal;
+    assert(is_graal == (id >= (int)FIRST_GRAAL_WKID && id <= (int)LAST_GRAAL_WKID),
+        "Graal WKIDs must be contiguous and separate from non-Graal WKIDs");
+    if (is_graal) {
+      (*klassp) = resolve_or_fail(symbol, _graal_loader, Handle(), true, CHECK_0); // load required Graal class
+    } else
+#endif
     if (must_load) {
       (*klassp) = resolve_or_fail(symbol, true, CHECK_0); // load required class
     } else {
@@ -1935,7 +1960,7 @@
     scan = WKID(jsr292_group_end + 1);
   }
 
-  initialize_wk_klasses_until(WKID_LIMIT, scan, CHECK);
+  initialize_wk_klasses_until(NOT_GRAAL(WKID_LIMIT) GRAAL_ONLY(FIRST_GRAAL_WKID), scan, CHECK);
 
   _box_klasses[T_BOOLEAN] = WK_KLASS(Boolean_klass);
   _box_klasses[T_CHAR]    = WK_KLASS(Character_klass);
@@ -1958,6 +1983,18 @@
   }
 }
 
+#ifdef GRAAL
+void SystemDictionary::initialize_preloaded_graal_classes(TRAPS) {
+  assert(WK_KLASS(CompilerThread_klass) == NULL, "preloaded Graal classes should only be initialized once");
+  if (UseGraalClassLoader) {
+    _graal_loader = GraalRuntime::compute_graal_class_loader(CHECK);
+  }
+
+  WKID scan = FIRST_GRAAL_WKID;
+  initialize_wk_klasses_through(LAST_GRAAL_WKID, scan, CHECK);
+}
+#endif
+
 // Tells if a given klass is a box (wrapper class, such as java.lang.Integer).
 // If so, returns the basic type it holds.  If not, returns T_OBJECT.
 BasicType SystemDictionary::box_klass_type(Klass* k) {
--- a/src/share/vm/classfile/systemDictionary.hpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/classfile/systemDictionary.hpp	Thu Jul 03 16:30:28 2014 +0200
@@ -184,67 +184,63 @@
   do_klass(Long_klass,                                  java_lang_Long,                            Pre                 ) \
                                                                                                                          \
   /* Support for Graal */                                                                                                \
-  do_klass(CompilerThread_klass,                  com_oracle_graal_compiler_CompilerThread,                     Opt) \
-  do_klass(BitSet_klass,                          java_util_BitSet,                                             Opt) \
-  /* graal.graph */                                                                                                  \
-  do_klass(Node_klass,                            com_oracle_graal_graph_Node,                                  Opt) \
-  do_klass(NodeClass_klass,                       com_oracle_graal_graph_NodeClass,                             Opt) \
-  /* graal.hotspot */                                                                                                \
-  do_klass(HotSpotCompiledCode_klass,             com_oracle_graal_hotspot_HotSpotCompiledCode,                 Opt) \
-  do_klass(HotSpotCompiledCode_Comment_klass,     com_oracle_graal_hotspot_HotSpotCompiledCode_Comment,         Opt) \
-  do_klass(HotSpotCompiledNmethod_klass,          com_oracle_graal_hotspot_HotSpotCompiledNmethod,              Opt) \
-  do_klass(HotSpotCompiledRuntimeStub_klass,      com_oracle_graal_hotspot_HotSpotCompiledRuntimeStub,          Opt) \
-  do_klass(HotSpotForeignCallLinkage_klass,       com_oracle_graal_hotspot_HotSpotForeignCallLinkage,           Opt) \
-  do_klass(HotSpotReferenceMap_klass,             com_oracle_graal_hotspot_HotSpotReferenceMap,                 Opt) \
-  do_klass(DataSection_klass,                     com_oracle_graal_hotspot_data_DataSection,                    Opt) \
-  do_klass(DataSectionReference_klass,            com_oracle_graal_hotspot_data_DataSectionReference,           Opt) \
-  do_klass(MetaspaceData_klass,                   com_oracle_graal_hotspot_data_MetaspaceData,                  Opt) \
-  do_klass(OopData_klass,                         com_oracle_graal_hotspot_data_OopData,                        Opt) \
-  do_klass(HotSpotCodeInfo_klass,                 com_oracle_graal_hotspot_meta_HotSpotCodeInfo,                Opt) \
-  do_klass(HotSpotInstalledCode_klass,            com_oracle_graal_hotspot_meta_HotSpotInstalledCode,           Opt) \
-  do_klass(HotSpotNmethod_klass,                  com_oracle_graal_hotspot_meta_HotSpotNmethod,                 Opt) \
-  do_klass(HotSpotResolvedJavaMethod_klass,       com_oracle_graal_hotspot_meta_HotSpotResolvedJavaMethod,      Opt) \
-  do_klass(HotSpotResolvedObjectType_klass,       com_oracle_graal_hotspot_meta_HotSpotResolvedObjectType,      Opt) \
-  do_klass(HotSpotMonitorValue_klass,             com_oracle_graal_hotspot_meta_HotSpotMonitorValue,            Opt) \
-  do_klass(HotSpotObjectConstant_klass,           com_oracle_graal_hotspot_meta_HotSpotObjectConstant,          Opt) \
-  do_klass(HotSpotMetaspaceConstant_klass,        com_oracle_graal_hotspot_meta_HotSpotMetaspaceConstant,       Opt) \
-  do_klass(HotSpotStackFrameReference_klass,      com_oracle_graal_hotspot_HotSpotStackFrameReference,          Opt) \
-  do_klass(CompilationTask_klass,                 com_oracle_graal_hotspot_CompilationTask,                     Opt) \
-  /* graal.api.code */                                                                                               \
-  do_klass(Assumptions_klass,                     com_oracle_graal_api_code_Assumptions,                        Opt) \
-  do_klass(Assumptions_ConcreteMethod_klass,      com_oracle_graal_api_code_Assumptions_ConcreteMethod,         Opt) \
-  do_klass(Assumptions_NoFinalizableSubclass_klass, com_oracle_graal_api_code_Assumptions_NoFinalizableSubclass, Opt) \
-  do_klass(Assumptions_ConcreteSubtype_klass,     com_oracle_graal_api_code_Assumptions_ConcreteSubtype,        Opt) \
-  do_klass(Assumptions_MethodContents_klass,      com_oracle_graal_api_code_Assumptions_MethodContents,         Opt) \
-  do_klass(Assumptions_CallSiteTargetValue_klass, com_oracle_graal_api_code_Assumptions_CallSiteTargetValue,    Opt) \
-  do_klass(BytecodePosition_klass,                com_oracle_graal_api_code_BytecodePosition,                   Opt) \
-  do_klass(DebugInfo_klass,                       com_oracle_graal_api_code_DebugInfo,                          Opt) \
-  do_klass(RegisterSaveLayout_klass,              com_oracle_graal_api_code_RegisterSaveLayout,                 Opt) \
-  do_klass(BytecodeFrame_klass,                   com_oracle_graal_api_code_BytecodeFrame,                      Opt) \
-  do_klass(CompilationResult_klass,               com_oracle_graal_api_code_CompilationResult,                  Opt) \
-  do_klass(CompilationResult_Call_klass,          com_oracle_graal_api_code_CompilationResult_Call,             Opt) \
-  do_klass(CompilationResult_DataPatch_klass,     com_oracle_graal_api_code_CompilationResult_DataPatch,        Opt) \
-  do_klass(CompilationResult_ExceptionHandler_klass, com_oracle_graal_api_code_CompilationResult_ExceptionHandler, Opt) \
-  do_klass(CompilationResult_Mark_klass,          com_oracle_graal_api_code_CompilationResult_Mark,             Opt) \
-  do_klass(CompilationResult_Infopoint_klass,     com_oracle_graal_api_code_CompilationResult_Infopoint,        Opt) \
-  do_klass(CompilationResult_Site_klass,          com_oracle_graal_api_code_CompilationResult_Site,             Opt) \
-  do_klass(ExternalCompilationResult_klass,       com_oracle_graal_gpu_ExternalCompilationResult,               Opt) \
-  do_klass(InfopointReason_klass,                 com_oracle_graal_api_code_InfopointReason,                    Opt) \
-  do_klass(InstalledCode_klass,                   com_oracle_graal_api_code_InstalledCode,                      Opt) \
-  do_klass(code_Register_klass,                   com_oracle_graal_api_code_Register,                           Opt) \
-  do_klass(RegisterValue_klass,                   com_oracle_graal_api_code_RegisterValue,                      Opt) \
-  do_klass(StackSlot_klass,                       com_oracle_graal_api_code_StackSlot,                          Opt) \
-  do_klass(VirtualObject_klass,                   com_oracle_graal_api_code_VirtualObject,                      Opt) \
-  do_klass(SpeculationLog_klass,                  com_oracle_graal_api_code_SpeculationLog,                     Opt) \
-  /* graal.api.meta */                                                                                               \
-  do_klass(Constant_klass,                        com_oracle_graal_api_meta_Constant,                           Opt) \
-  do_klass(PrimitiveConstant_klass,               com_oracle_graal_api_meta_PrimitiveConstant,                  Opt) \
-  do_klass(NullConstant_klass,                    com_oracle_graal_api_meta_NullConstant,                       Opt) \
-  do_klass(ExceptionHandler_klass,                com_oracle_graal_api_meta_ExceptionHandler,                   Opt) \
-  do_klass(Kind_klass,                            com_oracle_graal_api_meta_Kind,                               Opt) \
-  do_klass(JavaMethod_klass,                      com_oracle_graal_api_meta_JavaMethod,                         Opt) \
-  do_klass(JavaType_klass,                        com_oracle_graal_api_meta_JavaType,                           Opt) \
-  do_klass(Value_klass,                           com_oracle_graal_api_meta_Value,                              Opt) \
+  do_klass(BitSet_klass,                                java_util_BitSet,                          Opt                 ) \
+  /* Graal classes */                                                                                                    \
+  GRAAL_ONLY(do_klass(CompilerThread_klass,                  com_oracle_graal_compiler_CompilerThread,                     Graal)) \
+  GRAAL_ONLY(do_klass(Node_klass,                            com_oracle_graal_graph_Node,                                  Graal)) \
+  GRAAL_ONLY(do_klass(NodeClass_klass,                       com_oracle_graal_graph_NodeClass,                             Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotCompiledCode_klass,             com_oracle_graal_hotspot_HotSpotCompiledCode,                 Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotCompiledCode_Comment_klass,     com_oracle_graal_hotspot_HotSpotCompiledCode_Comment,         Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotCompiledNmethod_klass,          com_oracle_graal_hotspot_HotSpotCompiledNmethod,              Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotCompiledRuntimeStub_klass,      com_oracle_graal_hotspot_HotSpotCompiledRuntimeStub,          Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotForeignCallLinkage_klass,       com_oracle_graal_hotspot_HotSpotForeignCallLinkage,           Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotReferenceMap_klass,             com_oracle_graal_hotspot_HotSpotReferenceMap,                 Graal)) \
+  GRAAL_ONLY(do_klass(DataSection_klass,                     com_oracle_graal_hotspot_data_DataSection,                    Graal)) \
+  GRAAL_ONLY(do_klass(DataSectionReference_klass,            com_oracle_graal_hotspot_data_DataSectionReference,           Graal)) \
+  GRAAL_ONLY(do_klass(MetaspaceData_klass,                   com_oracle_graal_hotspot_data_MetaspaceData,                  Graal)) \
+  GRAAL_ONLY(do_klass(OopData_klass,                         com_oracle_graal_hotspot_data_OopData,                        Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotInstalledCode_klass,            com_oracle_graal_hotspot_meta_HotSpotInstalledCode,           Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotNmethod_klass,                  com_oracle_graal_hotspot_meta_HotSpotNmethod,                 Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotResolvedJavaMethod_klass,       com_oracle_graal_hotspot_meta_HotSpotResolvedJavaMethod,      Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotResolvedObjectType_klass,       com_oracle_graal_hotspot_meta_HotSpotResolvedObjectType,      Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotMonitorValue_klass,             com_oracle_graal_hotspot_meta_HotSpotMonitorValue,            Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotObjectConstant_klass,           com_oracle_graal_hotspot_meta_HotSpotObjectConstant,          Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotMetaspaceConstant_klass,        com_oracle_graal_hotspot_meta_HotSpotMetaspaceConstant,       Graal)) \
+  GRAAL_ONLY(do_klass(HotSpotStackFrameReference_klass,      com_oracle_graal_hotspot_HotSpotStackFrameReference,          Graal)) \
+  GRAAL_ONLY(do_klass(CompilationTask_klass,                 com_oracle_graal_hotspot_CompilationTask,                     Graal)) \
+  GRAAL_ONLY(do_klass(Assumptions_klass,                     com_oracle_graal_api_code_Assumptions,                        Graal)) \
+  GRAAL_ONLY(do_klass(Assumptions_ConcreteMethod_klass,      com_oracle_graal_api_code_Assumptions_ConcreteMethod,         Graal)) \
+  GRAAL_ONLY(do_klass(Assumptions_NoFinalizableSubclass_klass, com_oracle_graal_api_code_Assumptions_NoFinalizableSubclass, Graal))\
+  GRAAL_ONLY(do_klass(Assumptions_ConcreteSubtype_klass,     com_oracle_graal_api_code_Assumptions_ConcreteSubtype,        Graal)) \
+  GRAAL_ONLY(do_klass(Assumptions_MethodContents_klass,      com_oracle_graal_api_code_Assumptions_MethodContents,         Graal)) \
+  GRAAL_ONLY(do_klass(Assumptions_CallSiteTargetValue_klass, com_oracle_graal_api_code_Assumptions_CallSiteTargetValue,    Graal)) \
+  GRAAL_ONLY(do_klass(BytecodePosition_klass,                com_oracle_graal_api_code_BytecodePosition,                   Graal)) \
+  GRAAL_ONLY(do_klass(DebugInfo_klass,                       com_oracle_graal_api_code_DebugInfo,                          Graal)) \
+  GRAAL_ONLY(do_klass(RegisterSaveLayout_klass,              com_oracle_graal_api_code_RegisterSaveLayout,                 Graal)) \
+  GRAAL_ONLY(do_klass(BytecodeFrame_klass,                   com_oracle_graal_api_code_BytecodeFrame,                      Graal)) \
+  GRAAL_ONLY(do_klass(CompilationResult_klass,               com_oracle_graal_api_code_CompilationResult,                  Graal)) \
+  GRAAL_ONLY(do_klass(CompilationResult_Call_klass,          com_oracle_graal_api_code_CompilationResult_Call,             Graal)) \
+  GRAAL_ONLY(do_klass(CompilationResult_DataPatch_klass,     com_oracle_graal_api_code_CompilationResult_DataPatch,        Graal)) \
+  GRAAL_ONLY(do_klass(CompilationResult_ExceptionHandler_klass, com_oracle_graal_api_code_CompilationResult_ExceptionHandler, Graal))\
+  GRAAL_ONLY(do_klass(CompilationResult_Mark_klass,          com_oracle_graal_api_code_CompilationResult_Mark,             Graal)) \
+  GRAAL_ONLY(do_klass(CompilationResult_Infopoint_klass,     com_oracle_graal_api_code_CompilationResult_Infopoint,        Graal)) \
+  GRAAL_ONLY(do_klass(CompilationResult_Site_klass,          com_oracle_graal_api_code_CompilationResult_Site,             Graal)) \
+  GRAAL_ONLY(do_klass(ExternalCompilationResult_klass,       com_oracle_graal_gpu_ExternalCompilationResult,               Graal)) \
+  GRAAL_ONLY(do_klass(InfopointReason_klass,                 com_oracle_graal_api_code_InfopointReason,                    Graal)) \
+  GRAAL_ONLY(do_klass(InstalledCode_klass,                   com_oracle_graal_api_code_InstalledCode,                      Graal)) \
+  GRAAL_ONLY(do_klass(code_Register_klass,                   com_oracle_graal_api_code_Register,                           Graal)) \
+  GRAAL_ONLY(do_klass(RegisterValue_klass,                   com_oracle_graal_api_code_RegisterValue,                      Graal)) \
+  GRAAL_ONLY(do_klass(StackSlot_klass,                       com_oracle_graal_api_code_StackSlot,                          Graal)) \
+  GRAAL_ONLY(do_klass(VirtualObject_klass,                   com_oracle_graal_api_code_VirtualObject,                      Graal)) \
+  GRAAL_ONLY(do_klass(SpeculationLog_klass,                  com_oracle_graal_api_code_SpeculationLog,                     Graal)) \
+  GRAAL_ONLY(do_klass(Constant_klass,                        com_oracle_graal_api_meta_Constant,                           Graal)) \
+  GRAAL_ONLY(do_klass(PrimitiveConstant_klass,               com_oracle_graal_api_meta_PrimitiveConstant,                  Graal)) \
+  GRAAL_ONLY(do_klass(NullConstant_klass,                    com_oracle_graal_api_meta_NullConstant,                       Graal)) \
+  GRAAL_ONLY(do_klass(ExceptionHandler_klass,                com_oracle_graal_api_meta_ExceptionHandler,                   Graal)) \
+  GRAAL_ONLY(do_klass(Kind_klass,                            com_oracle_graal_api_meta_Kind,                               Graal)) \
+  GRAAL_ONLY(do_klass(JavaMethod_klass,                      com_oracle_graal_api_meta_JavaMethod,                         Graal)) \
+  GRAAL_ONLY(do_klass(JavaType_klass,                        com_oracle_graal_api_meta_JavaType,                           Graal)) \
+  GRAAL_ONLY(do_klass(Value_klass,                           com_oracle_graal_api_meta_Value,                              Graal)) \
 
   /*end*/
 
@@ -263,6 +259,11 @@
 
     WKID_LIMIT,
 
+#ifdef GRAAL
+    FIRST_GRAAL_WKID = WK_KLASS_ENUM_NAME(CompilerThread_klass),
+    LAST_GRAAL_WKID  = WK_KLASS_ENUM_NAME(Value_klass),
+#endif
+
     FIRST_WKID = NO_WKID + 1
   };
 
@@ -276,6 +277,9 @@
     Opt,                        // preload tried; NULL if not present
     Opt_Only_JDK14NewRef,       // preload tried; use only with NewReflection
     Opt_Only_JDK15,             // preload tried; use only with JDK1.5+
+#ifdef GRAAL
+    Graal,                      // preload tried; error if not present, use only with GRAAL
+#endif
     OPTION_LIMIT,
     CEIL_LG_OPTION_LIMIT = 4    // OPTION_LIMIT <= (1<<CEIL_LG_OPTION_LIMIT)
   };
@@ -464,6 +468,9 @@
     // despite the optional loading, if you use this it must be present:
     return check_klass(k);
   }
+#ifdef GRAAL
+  static Klass* check_klass_Graal(Klass* k)      { return k; }
+#endif
 
   static bool initialize_wk_klass(WKID id, int init_opt, TRAPS);
   static void initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS);
@@ -529,6 +536,12 @@
   // Returns default system loader
   static oop java_system_loader();
 
+#ifdef GRAAL
+  // Returns the Graal loader. This will be NULL if !UseGraalClassLoader
+  // in which case it's equivalent to the boot loader
+  static oop graal_loader();
+#endif
+
   // Compute the default system loader
   static void compute_java_system_loader(TRAPS);
 
@@ -695,6 +708,10 @@
 public:
   static bool is_ext_class_loader(Handle class_loader);
 
+#ifdef GRAAL
+  static void initialize_preloaded_graal_classes(TRAPS);
+#endif
+
 private:
   static Klass* find_shared_class(Symbol* class_name);
 
@@ -757,6 +774,9 @@
   static Klass* _box_klasses[T_VOID+1];
 
   static oop  _java_system_loader;
+#ifdef GRAAL
+  static oop  _graal_loader;
+#endif
 
   static bool _has_loadClassInternal;
   static bool _has_checkPackageAccess;
--- a/src/share/vm/classfile/verifier.cpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/classfile/verifier.cpp	Thu Jul 03 16:30:28 2014 +0200
@@ -94,7 +94,7 @@
 // Methods in Verifier
 
 bool Verifier::should_verify_for(oop class_loader, bool should_verify_class) {
-  return (class_loader == NULL || !should_verify_class) ?
+  return (class_loader == NULL GRAAL_ONLY(|| class_loader == SystemDictionary::graal_loader()) || !should_verify_class) ?
     BytecodeVerificationLocal : BytecodeVerificationRemote;
 }
 
--- a/src/share/vm/classfile/vmSymbols.hpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/classfile/vmSymbols.hpp	Thu Jul 03 16:30:28 2014 +0200
@@ -308,7 +308,6 @@
   template(com_oracle_graal_hotspot_data_DataSectionReference,       "com/oracle/graal/hotspot/data/DataSectionReference")            \
   template(com_oracle_graal_hotspot_data_MetaspaceData,              "com/oracle/graal/hotspot/data/MetaspaceData")                   \
   template(com_oracle_graal_hotspot_data_OopData,                    "com/oracle/graal/hotspot/data/OopData")                         \
-  template(com_oracle_graal_hotspot_meta_HotSpotCodeInfo,            "com/oracle/graal/hotspot/meta/HotSpotCodeInfo")                 \
   template(com_oracle_graal_hotspot_meta_HotSpotInstalledCode,       "com/oracle/graal/hotspot/meta/HotSpotInstalledCode")            \
   template(com_oracle_graal_hotspot_meta_HotSpotNmethod,             "com/oracle/graal/hotspot/meta/HotSpotNmethod")                  \
   template(com_oracle_graal_hotspot_meta_HotSpotResolvedJavaMethod,  "com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod")       \
--- a/src/share/vm/graal/graalGlobals.hpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/graal/graalGlobals.hpp	Thu Jul 03 16:30:28 2014 +0200
@@ -49,6 +49,9 @@
   product(bool, DebugGraal, true,                                           \
           "Enable JVMTI for the compiler thread")                           \
                                                                             \
+  product(bool, UseGraalClassLoader, false,                                 \
+          "Load Graal classes with separate class loader")                  \
+                                                                            \
   COMPILERGRAAL_PRESENT(product(bool, BootstrapGraal, true,                 \
           "Bootstrap Graal before running Java main method"))               \
                                                                             \
--- a/src/share/vm/graal/graalRuntime.cpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/graal/graalRuntime.cpp	Thu Jul 03 16:30:28 2014 +0200
@@ -653,7 +653,7 @@
 // private static TruffleRuntime Truffle.createRuntime()
 JVM_ENTRY(jobject, JVM_CreateTruffleRuntime(JNIEnv *env, jclass c))
   TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime", THREAD);
-  KlassHandle klass = GraalRuntime::load_required_class(name);
+  KlassHandle klass = GraalRuntime::resolve_or_fail(name, CHECK_NULL);
 
   TempNewSymbol makeInstance = SymbolTable::new_symbol("makeInstance", THREAD);
   TempNewSymbol sig = SymbolTable::new_symbol("()Lcom/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime;", THREAD);
@@ -710,7 +710,7 @@
     // causes argument parsing to be redone with better error messages.
     CLEAR_PENDING_EXCEPTION;
     TempNewSymbol name = SymbolTable::new_symbol("Lcom/oracle/graal/hotspot/HotSpotOptions;", THREAD);
-    instanceKlassHandle hotSpotOptionsClass = SystemDictionary::resolve_or_fail(name, true, THREAD);
+    instanceKlassHandle hotSpotOptionsClass = resolve_or_fail(name, THREAD);
     GUARANTEE_NO_PENDING_EXCEPTION("Error in check_arguments");
 
     parse_arguments(hotSpotOptionsClass, THREAD);
@@ -909,7 +909,7 @@
 
 Handle GraalRuntime::get_OptionValue(const char* declaringClass, const char* fieldName, const char* fieldSig, TRAPS) {
   TempNewSymbol name = SymbolTable::new_symbol(declaringClass, THREAD);
-  Klass* klass = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
+  Klass* klass = resolve_or_fail(name, CHECK_NH);
 
   // The class has been loaded so the field and signature should already be in the symbol
   // table.  If they're not there, the field doesn't exist.
@@ -932,7 +932,7 @@
 
 Handle GraalRuntime::create_Service(const char* name, TRAPS) {
   TempNewSymbol kname = SymbolTable::new_symbol(name, THREAD);
-  Klass* k = SystemDictionary::resolve_or_fail(kname, true, CHECK_NH);
+  Klass* k = resolve_or_fail(kname, CHECK_NH);
   instanceKlassHandle klass(THREAD, k);
   klass->initialize(CHECK_NH);
   klass->check_valid_for_instantiation(true, CHECK_NH);
@@ -971,6 +971,22 @@
                           thread);
 }
 
+oop GraalRuntime::compute_graal_class_loader(TRAPS) {
+  assert(UseGraalClassLoader, "must be");
+  TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/loader/Factory", THREAD);
+  KlassHandle klass = SystemDictionary::resolve_or_null(name, THREAD);
+  if (klass.is_null()) {
+    tty->print_cr("Could not load class %s", name->as_C_string());
+    vm_abort(false);
+  }
+
+  TempNewSymbol getClassLoader = SymbolTable::new_symbol("newClassLoader", THREAD);
+  JavaValue result(T_OBJECT);
+  JavaCalls::call_static(&result, klass, getClassLoader, vmSymbols::void_classloader_signature(), THREAD);
+  GUARANTEE_NO_PENDING_EXCEPTION("Couldn't initialize HotSpotGraalRuntime");
+  return (oop) result.get_jobject();
+}
+
 void GraalRuntime::abort_on_pending_exception(Handle exception, const char* message, bool dump_core) {
   Thread* THREAD = Thread::current();
   CLEAR_PENDING_EXCEPTION;
@@ -979,8 +995,16 @@
   vm_abort(dump_core);
 }
 
+Klass* GraalRuntime::resolve_or_null(Symbol* name, TRAPS) {
+  return SystemDictionary::resolve_or_null(name, SystemDictionary::graal_loader(), Handle(), CHECK_NULL);
+}
+
+Klass* GraalRuntime::resolve_or_fail(Symbol* name, TRAPS) {
+  return SystemDictionary::resolve_or_fail(name, SystemDictionary::graal_loader(), Handle(), true, CHECK_NULL);
+}
+
 Klass* GraalRuntime::load_required_class(Symbol* name) {
-  Klass* klass = SystemDictionary::resolve_or_null(name, SystemDictionary::java_system_loader(), Handle(), Thread::current());
+  Klass* klass = resolve_or_null(name, Thread::current());
   if (klass == NULL) {
     tty->print_cr("Could not load class %s", name->as_C_string());
     vm_abort(false);
--- a/src/share/vm/graal/graalRuntime.hpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/graal/graalRuntime.hpp	Thu Jul 03 16:30:28 2014 +0200
@@ -145,8 +145,26 @@
     } \
   } while (0);
 
+  /**
+   * Same as SystemDictionary::resolve_or_null but uses the Graal loader.
+   */
+  static Klass* resolve_or_null(Symbol* name, TRAPS);
+
+  /**
+   * Same as SystemDictionary::resolve_or_fail but uses the Graal loader.
+   */
+  static Klass* resolve_or_fail(Symbol* name, TRAPS);
+
+  /**
+   * Loads a given Graal class and aborts the VM if it fails.
+   */
   static Klass* load_required_class(Symbol* name);
 
+  /**
+   * Creates a separate class loader for classes in graal.jar.
+   */
+  static oop compute_graal_class_loader(TRAPS);
+
   static BufferBlob* initialize_buffer_blob();
 
   /**
--- a/src/share/vm/oops/instanceKlass.cpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/oops/instanceKlass.cpp	Thu Jul 03 16:30:28 2014 +0200
@@ -1207,7 +1207,7 @@
   }
 
 #ifdef GRAAL
-  if (this_oop->is_subtype_of(SystemDictionary::Node_klass())) {
+  if (SystemDictionary::Node_klass() != NULL && this_oop->is_subtype_of(SystemDictionary::Node_klass())) {
     if (this_oop() != SystemDictionary::Node_klass()) {
       if (!GraalRuntime::is_HotSpotGraalRuntime_initialized() && JavaAssertions::systemClassDefault() == false) {
         // We want to ensure that the process of initializing HotSpotGraalRuntime
--- a/src/share/vm/prims/nativeLookup.cpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/prims/nativeLookup.cpp	Thu Jul 03 16:30:28 2014 +0200
@@ -182,7 +182,7 @@
   // gets found the first time around - otherwise an infinite loop can occure. This is
   // another VM/library dependency
   Handle loader(THREAD, method->method_holder()->class_loader());
-  if (loader.is_null()) {
+  if (loader.is_null() GRAAL_ONLY(|| loader() == SystemDictionary::graal_loader())) {
     entry = lookup_special_native(jni_name);
     if (entry == NULL) {
        entry = (address) os::dll_lookup(os::native_java_library(), jni_name);
--- a/src/share/vm/runtime/arguments.cpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/runtime/arguments.cpp	Thu Jul 03 16:30:28 2014 +0200
@@ -3248,6 +3248,15 @@
   // This must be done after all -D arguments have been processed.
   scp_p->expand_endorsed();
 
+#ifdef GRAAL
+  if (!UseGraalClassLoader) {
+    // Append graal.jar to boot class path
+    const char* home = Arguments::get_java_home();
+    scp_p->add_suffix(os::format_boot_path("%/lib/graal.jar", home, (int)strlen(home), os::file_separator()[0], os::path_separator()[0]));
+    scp_assembly_required = true;
+  }
+#endif
+
   if (scp_assembly_required || scp_p->get_endorsed() != NULL) {
     // Assemble the bootclasspath elements into the final path.
     Arguments::set_sysclasspath(scp_p->combined_path());
--- a/src/share/vm/runtime/javaCalls.cpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/runtime/javaCalls.cpp	Thu Jul 03 16:30:28 2014 +0200
@@ -40,8 +40,10 @@
 #include "runtime/signature.hpp"
 #include "runtime/stubRoutines.hpp"
 #include "runtime/thread.inline.hpp"
+#ifdef GRAAL
 #include "graal/graalJavaAccess.hpp"
 #include "graal/graalRuntime.hpp"
+#endif
 
 // -----------------------------------------------------
 // Implementation of JavaCallWrapper
--- a/src/share/vm/runtime/os.cpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/runtime/os.cpp	Thu Jul 03 16:30:28 2014 +0200
@@ -1268,7 +1268,7 @@
         "%/lib/JObjC.jar:"
 #endif
 #ifdef GRAAL
-        "%/lib/graal.jar:"
+        "%/lib/graal-loader.jar:"
 #endif
         "%/classes";
     char* sysclasspath = format_boot_path(classpath_format, home, home_len, fileSep, pathSep);
--- a/src/share/vm/runtime/os.hpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/runtime/os.hpp	Thu Jul 03 16:30:28 2014 +0200
@@ -92,6 +92,9 @@
 
 class os: AllStatic {
   friend class VMStructs;
+#ifdef GRAAL
+  friend class Arguments; // need access to format_boot_path
+#endif
 
  public:
   enum { page_sizes_max = 9 }; // Size of _page_sizes array (8 plus a sentinel)
--- a/src/share/vm/runtime/thread.cpp	Thu Jul 03 14:31:34 2014 +0200
+++ b/src/share/vm/runtime/thread.cpp	Thu Jul 03 16:30:28 2014 +0200
@@ -3679,6 +3679,9 @@
   // set_init_completed has just been called, causing exceptions not to be shortcut
   // anymore. We call vm_exit_during_initialization directly instead.
   SystemDictionary::compute_java_system_loader(THREAD);
+#ifdef GRAAL
+  SystemDictionary::initialize_preloaded_graal_classes(THREAD);
+#endif
   if (HAS_PENDING_EXCEPTION) {
     vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION));
   }