changeset 8230:b96c35c4b40c

Merge
author mchung
date Thu, 16 Apr 2015 21:23:06 -0700
parents 9c916db4bf3b 9c73fcc23ee8
children de648dabad71
files src/share/vm/memory/universe.cpp src/share/vm/oops/instanceKlass.cpp src/share/vm/oops/objArrayKlass.cpp src/share/vm/runtime/thread.cpp src/share/vm/runtime/vmStructs.cpp test/runtime/BadObjectClass/Object.java
diffstat 158 files changed, 8384 insertions(+), 1046 deletions(-) [+]
line wrap: on
line diff
--- a/.jcheck/conf	Thu Apr 09 17:38:28 2015 -0700
+++ b/.jcheck/conf	Thu Apr 16 21:23:06 2015 -0700
@@ -1,1 +1,4 @@
 project=jdk9
+comments=lax
+tags=lax
+bugids=dup
--- a/make/aix/makefiles/mapfile-vers-debug	Thu Apr 09 17:38:28 2015 -0700
+++ b/make/aix/makefiles/mapfile-vers-debug	Thu Apr 16 21:23:06 2015 -0700
@@ -19,7 +19,7 @@
 # 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.
-#  
+#
 #
 
 # Define public interface.
@@ -190,6 +190,26 @@
                 JVM_Yield;
                 JVM_handle_linux_signal;
 
+                # Modules
+                JVM_DefineModule;
+                JVM_AddReadsModule;
+                JVM_AddModuleExports;
+                JVM_CanReadModule;
+                JVM_IsExportedToModule;
+                JVM_AddModulePackage;
+
+                # Images
+                JVM_ImageOpen;
+                JVM_ImageClose;
+                JVM_ImageGetIndexAddress;
+                JVM_ImageGetDataAddress;
+                JVM_ImageRead;
+                JVM_ImageReadCompressed;
+                JVM_ImageGetStringBytes;
+                JVM_ImageGetAttributes;
+                JVM_ImageFindAttributes;
+                JVM_ImageAttributeOffsets;
+
                 # debug JVM
                 JVM_AccessVMBooleanFlag;
                 JVM_AccessVMIntFlag;
--- a/make/aix/makefiles/mapfile-vers-product	Thu Apr 09 17:38:28 2015 -0700
+++ b/make/aix/makefiles/mapfile-vers-product	Thu Apr 16 21:23:06 2015 -0700
@@ -19,7 +19,7 @@
 # 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.
-#  
+#
 #
 
 # Define public interface.
@@ -188,6 +188,26 @@
                 JVM_Yield;
                 JVM_handle_linux_signal;
 
+                # Modules
+                JVM_DefineModule;
+                JVM_AddReadsModule;
+                JVM_AddModuleExports;
+                JVM_CanReadModule;
+                JVM_IsExportedToModule;
+                JVM_AddModulePackage;
+
+                # Images
+                JVM_ImageOpen;
+                JVM_ImageClose;
+                JVM_ImageGetIndexAddress;
+                JVM_ImageGetDataAddress;
+                JVM_ImageRead;
+                JVM_ImageReadCompressed;
+                JVM_ImageGetStringBytes;
+                JVM_ImageGetAttributes;
+                JVM_ImageFindAttributes;
+                JVM_ImageAttributeOffsets;
+
                 # miscellaneous functions
                 jio_fprintf;
                 jio_printf;
--- a/make/bsd/makefiles/mapfile-vers-darwin-debug	Thu Apr 09 17:38:28 2015 -0700
+++ b/make/bsd/makefiles/mapfile-vers-darwin-debug	Thu Apr 16 21:23:06 2015 -0700
@@ -187,7 +187,26 @@
                 _JVM_Yield
                 _JVM_handle_bsd_signal
 
-                # miscellaneous functions
+                # Modules
+                _JVM_DefineModule
+                _JVM_AddReadsModule
+                _JVM_AddModuleExports
+                _JVM_CanReadModule
+                _JVM_IsExportedToModule
+                _JVM_AddModulePackage
+
+                # Images
+                _JVM_ImageOpen
+                _JVM_ImageClose
+                _JVM_ImageGetIndexAddress
+                _JVM_ImageGetDataAddress
+                _JVM_ImageRead
+                _JVM_ImageReadCompressed
+                _JVM_ImageGetStringBytes
+                _JVM_ImageGetAttributes
+                _JVM_ImageFindAttributes
+                _JVM_ImageAttributeOffsets
+
                 _jio_fprintf
                 _jio_printf
                 _jio_snprintf
--- a/make/bsd/makefiles/mapfile-vers-darwin-product	Thu Apr 09 17:38:28 2015 -0700
+++ b/make/bsd/makefiles/mapfile-vers-darwin-product	Thu Apr 16 21:23:06 2015 -0700
@@ -187,6 +187,26 @@
                 _JVM_Yield
                 _JVM_handle_bsd_signal
 
+                # Modules
+                _JVM_DefineModule
+                _JVM_AddReadsModule
+                _JVM_AddModuleExports
+                _JVM_CanReadModule
+                _JVM_IsExportedToModule
+                _JVM_AddModulePackage
+
+                # Images
+                _JVM_ImageOpen
+                _JVM_ImageClose
+                _JVM_ImageGetIndexAddress
+                _JVM_ImageGetDataAddress
+                _JVM_ImageRead
+                _JVM_ImageReadCompressed
+                _JVM_ImageGetStringBytes
+                _JVM_ImageGetAttributes
+                _JVM_ImageFindAttributes
+                _JVM_ImageAttributeOffsets
+
                 # miscellaneous functions
                 _jio_fprintf
                 _jio_printf
--- a/make/bsd/makefiles/mapfile-vers-debug	Thu Apr 09 17:38:28 2015 -0700
+++ b/make/bsd/makefiles/mapfile-vers-debug	Thu Apr 16 21:23:06 2015 -0700
@@ -19,7 +19,7 @@
 # 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.
-#  
+#
 #
 
 # Define public interface.
@@ -189,6 +189,26 @@
                 JVM_Yield;
                 JVM_handle_linux_signal;
 
+                # Modules
+                JVM_DefineModule;
+                JVM_AddReadsModule;
+                JVM_AddModuleExports;
+                JVM_CanReadModule;
+                JVM_IsExportedToModule;
+                JVM_AddModulePackage;
+
+                # Images
+                JVM_ImageOpen;
+                JVM_ImageClose;
+                JVM_ImageGetIndexAddress;
+                JVM_ImageGetDataAddress;
+                JVM_ImageRead;
+                JVM_ImageReadCompressed;
+                JVM_ImageGetStringBytes;
+                JVM_ImageGetAttributes;
+                JVM_ImageFindAttributes;
+                JVM_ImageAttributeOffsets;
+
                 # miscellaneous functions
                 jio_fprintf;
                 jio_printf;
--- a/make/bsd/makefiles/mapfile-vers-product	Thu Apr 09 17:38:28 2015 -0700
+++ b/make/bsd/makefiles/mapfile-vers-product	Thu Apr 16 21:23:06 2015 -0700
@@ -19,7 +19,7 @@
 # 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.
-#  
+#
 #
 
 # Define public interface.
@@ -189,6 +189,26 @@
                 JVM_Yield;
                 JVM_handle_linux_signal;
 
+                # Modules
+                JVM_DefineModule;
+                JVM_AddReadsModule;
+                JVM_AddModuleExports;
+                JVM_CanReadModule;
+                JVM_IsExportedToModule;
+                JVM_AddModulePackage;
+
+                # Images
+                JVM_ImageOpen;
+                JVM_ImageClose;
+                JVM_ImageGetIndexAddress;
+                JVM_ImageGetDataAddress;
+                JVM_ImageRead;
+                JVM_ImageReadCompressed;
+                JVM_ImageGetStringBytes;
+                JVM_ImageGetAttributes;
+                JVM_ImageFindAttributes;
+                JVM_ImageAttributeOffsets;
+
                 # miscellaneous functions
                 jio_fprintf;
                 jio_printf;
--- a/make/linux/makefiles/mapfile-vers-debug	Thu Apr 09 17:38:28 2015 -0700
+++ b/make/linux/makefiles/mapfile-vers-debug	Thu Apr 16 21:23:06 2015 -0700
@@ -19,7 +19,7 @@
 # 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.
-#  
+#
 #
 
 # Define public interface.
@@ -189,6 +189,26 @@
                 JVM_Yield;
                 JVM_handle_linux_signal;
 
+                # Modules
+                JVM_DefineModule;
+                JVM_AddReadsModule;
+                JVM_AddModuleExports;
+                JVM_CanReadModule;
+                JVM_IsExportedToModule;
+                JVM_AddModulePackage;
+
+                # Images
+                JVM_ImageOpen;
+                JVM_ImageClose;
+                JVM_ImageGetIndexAddress;
+                JVM_ImageGetDataAddress;
+                JVM_ImageRead;
+                JVM_ImageReadCompressed;
+                JVM_ImageGetStringBytes;
+                JVM_ImageGetAttributes;
+                JVM_ImageFindAttributes;
+                JVM_ImageAttributeOffsets;
+
                 # miscellaneous functions
                 jio_fprintf;
                 jio_printf;
--- a/make/linux/makefiles/mapfile-vers-product	Thu Apr 09 17:38:28 2015 -0700
+++ b/make/linux/makefiles/mapfile-vers-product	Thu Apr 16 21:23:06 2015 -0700
@@ -19,7 +19,7 @@
 # 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.
-#  
+#
 #
 
 # Define public interface.
@@ -189,6 +189,26 @@
                 JVM_Yield;
                 JVM_handle_linux_signal;
 
+                # Modules
+                JVM_DefineModule;
+                JVM_AddReadsModule;
+                JVM_AddModuleExports;
+                JVM_CanReadModule;
+                JVM_IsExportedToModule;
+                JVM_AddModulePackage;
+
+                # Images
+                JVM_ImageOpen;
+                JVM_ImageClose;
+                JVM_ImageGetIndexAddress;
+                JVM_ImageGetDataAddress;
+                JVM_ImageRead;
+                JVM_ImageReadCompressed;
+                JVM_ImageGetStringBytes;
+                JVM_ImageGetAttributes;
+                JVM_ImageFindAttributes;
+                JVM_ImageAttributeOffsets;
+
                 # miscellaneous functions
                 jio_fprintf;
                 jio_printf;
--- a/make/solaris/makefiles/mapfile-vers	Thu Apr 09 17:38:28 2015 -0700
+++ b/make/solaris/makefiles/mapfile-vers	Thu Apr 16 21:23:06 2015 -0700
@@ -19,7 +19,7 @@
 # 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.
-#  
+#
 #
 
 # Define public interface.
@@ -30,7 +30,7 @@
                 JNI_CreateJavaVM;
                 JNI_GetCreatedJavaVMs;
                 JNI_GetDefaultJavaVMInitArgs;
-        
+
                 # JVM
                 JVM_ActiveProcessorCount;
                 JVM_ArrayCopy;
@@ -189,6 +189,26 @@
                 JVM_Yield;
                 JVM_handle_solaris_signal;
 
+                # Modules
+                JVM_DefineModule;
+                JVM_AddReadsModule;
+                JVM_AddModuleExports;
+                JVM_CanReadModule;
+                JVM_IsExportedToModule;
+                JVM_AddModulePackage;
+
+                # Images
+                JVM_ImageOpen;
+                JVM_ImageClose;
+                JVM_ImageGetIndexAddress;
+                JVM_ImageGetDataAddress;
+                JVM_ImageRead;
+                JVM_ImageReadCompressed;
+                JVM_ImageGetStringBytes;
+                JVM_ImageGetAttributes;
+                JVM_ImageFindAttributes;
+                JVM_ImageAttributeOffsets;
+
                 # miscellaneous functions
                 jio_fprintf;
                 jio_printf;
@@ -196,6 +216,7 @@
                 jio_vfprintf;
                 jio_vsnprintf;
 
+
                 # Needed because there is no JVM interface for this.
                 sysThreadAvailableStackWithSlack;
 
--- a/src/os/linux/vm/os_linux.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/os/linux/vm/os_linux.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -110,7 +110,7 @@
 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
 // getrusage() is prepared to handle the associated failure.
 #ifndef RUSAGE_THREAD
-  #define RUSAGE_THREAD   (1)               /* only the calling thread */
+#define RUSAGE_THREAD   (1)               /* only the calling thread */
 #endif
 
 #define MAX_PATH    (2 * K)
@@ -213,17 +213,17 @@
 
 #ifndef SYS_gettid
 // i386: 224, ia64: 1105, amd64: 186, sparc 143
-  #ifdef __ia64__
-    #define SYS_gettid 1105
-  #elif __i386__
-    #define SYS_gettid 224
-  #elif __amd64__
-    #define SYS_gettid 186
-  #elif __sparc__
-    #define SYS_gettid 143
-  #else
-    #error define gettid for the arch
-  #endif
+#ifdef __ia64__
+#define SYS_gettid 1105
+#elif __i386__
+#define SYS_gettid 224
+#elif __amd64__
+#define SYS_gettid 186
+#elif __sparc__
+#define SYS_gettid 143
+#else
+#error define gettid for the arch
+#endif
 #endif
 
 // Cpu architecture string
@@ -241,10 +241,10 @@
 pid_t os::Linux::gettid() {
   int rslt = syscall(SYS_gettid);
   if (rslt == -1) {
-    // old kernel, no NPTL support
-    return getpid();
+     // old kernel, no NPTL support
+     return getpid();
   } else {
-    return (pid_t)rslt;
+     return (pid_t)rslt;
   }
 }
 
@@ -301,16 +301,16 @@
   // Important note: if the location of libjvm.so changes this
   // code needs to be changed accordingly.
 
-  // See ld(1):
-  //      The linker uses the following search paths to locate required
-  //      shared libraries:
-  //        1: ...
-  //        ...
-  //        7: The default directories, normally /lib and /usr/lib.
+// See ld(1):
+//      The linker uses the following search paths to locate required
+//      shared libraries:
+//        1: ...
+//        ...
+//        7: The default directories, normally /lib and /usr/lib.
 #if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390))
-  #define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib"
+#define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib"
 #else
-  #define DEFAULT_LIBPATH "/lib:/usr/lib"
+#define DEFAULT_LIBPATH "/lib:/usr/lib"
 #endif
 
 // Base path of extensions installed on the system.
@@ -412,15 +412,15 @@
 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs;
 
 bool os::Linux::is_sig_ignored(int sig) {
-  struct sigaction oact;
-  sigaction(sig, (struct sigaction*)NULL, &oact);
-  void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*,  oact.sa_sigaction)
-                                 : CAST_FROM_FN_PTR(void*,  oact.sa_handler);
+      struct sigaction oact;
+      sigaction(sig, (struct sigaction*)NULL, &oact);
+      void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*,  oact.sa_sigaction)
+                                     : CAST_FROM_FN_PTR(void*,  oact.sa_handler);
   if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) {
-    return true;
+           return true;
   } else {
-    return false;
-  }
+           return false;
+}
 }
 
 void os::Linux::signal_sets_init() {
@@ -451,18 +451,18 @@
   sigaddset(&unblocked_sigs, SR_signum);
 
   if (!ReduceSignalUsage) {
-    if (!os::Linux::is_sig_ignored(SHUTDOWN1_SIGNAL)) {
+   if (!os::Linux::is_sig_ignored(SHUTDOWN1_SIGNAL)) {
       sigaddset(&unblocked_sigs, SHUTDOWN1_SIGNAL);
       sigaddset(&allowdebug_blocked_sigs, SHUTDOWN1_SIGNAL);
-    }
-    if (!os::Linux::is_sig_ignored(SHUTDOWN2_SIGNAL)) {
+   }
+   if (!os::Linux::is_sig_ignored(SHUTDOWN2_SIGNAL)) {
       sigaddset(&unblocked_sigs, SHUTDOWN2_SIGNAL);
       sigaddset(&allowdebug_blocked_sigs, SHUTDOWN2_SIGNAL);
-    }
-    if (!os::Linux::is_sig_ignored(SHUTDOWN3_SIGNAL)) {
+   }
+   if (!os::Linux::is_sig_ignored(SHUTDOWN3_SIGNAL)) {
       sigaddset(&unblocked_sigs, SHUTDOWN3_SIGNAL);
       sigaddset(&allowdebug_blocked_sigs, SHUTDOWN3_SIGNAL);
-    }
+   }
   }
   // Fill in signals that are blocked by all but the VM thread.
   sigemptyset(&vm_sigs);
@@ -523,59 +523,59 @@
   // and _CS_GNU_LIBPTHREAD_VERSION are supported in glibc >= 2.3.2. Use a
   // generic name for earlier versions.
   // Define macros here so we can build HotSpot on old systems.
-#ifndef _CS_GNU_LIBC_VERSION
-  #define _CS_GNU_LIBC_VERSION 2
-#endif
-#ifndef _CS_GNU_LIBPTHREAD_VERSION
-  #define _CS_GNU_LIBPTHREAD_VERSION 3
-#endif
+# ifndef _CS_GNU_LIBC_VERSION
+# define _CS_GNU_LIBC_VERSION 2
+# endif
+# ifndef _CS_GNU_LIBPTHREAD_VERSION
+# define _CS_GNU_LIBPTHREAD_VERSION 3
+# endif
 
   size_t n = confstr(_CS_GNU_LIBC_VERSION, NULL, 0);
   if (n > 0) {
-    char *str = (char *)malloc(n, mtInternal);
-    confstr(_CS_GNU_LIBC_VERSION, str, n);
-    os::Linux::set_glibc_version(str);
+     char *str = (char *)malloc(n, mtInternal);
+     confstr(_CS_GNU_LIBC_VERSION, str, n);
+     os::Linux::set_glibc_version(str);
   } else {
-    // _CS_GNU_LIBC_VERSION is not supported, try gnu_get_libc_version()
-    static char _gnu_libc_version[32];
-    jio_snprintf(_gnu_libc_version, sizeof(_gnu_libc_version),
-                 "glibc %s %s", gnu_get_libc_version(), gnu_get_libc_release());
-    os::Linux::set_glibc_version(_gnu_libc_version);
+     // _CS_GNU_LIBC_VERSION is not supported, try gnu_get_libc_version()
+     static char _gnu_libc_version[32];
+     jio_snprintf(_gnu_libc_version, sizeof(_gnu_libc_version),
+              "glibc %s %s", gnu_get_libc_version(), gnu_get_libc_release());
+     os::Linux::set_glibc_version(_gnu_libc_version);
   }
 
   n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
   if (n > 0) {
-    char *str = (char *)malloc(n, mtInternal);
-    confstr(_CS_GNU_LIBPTHREAD_VERSION, str, n);
-    // Vanilla RH-9 (glibc 2.3.2) has a bug that confstr() always tells
-    // us "NPTL-0.29" even we are running with LinuxThreads. Check if this
-    // is the case. LinuxThreads has a hard limit on max number of threads.
-    // So sysconf(_SC_THREAD_THREADS_MAX) will return a positive value.
-    // On the other hand, NPTL does not have such a limit, sysconf()
-    // will return -1 and errno is not changed. Check if it is really NPTL.
-    if (strcmp(os::Linux::glibc_version(), "glibc 2.3.2") == 0 &&
-        strstr(str, "NPTL") &&
-        sysconf(_SC_THREAD_THREADS_MAX) > 0) {
-      free(str);
-      os::Linux::set_libpthread_version("linuxthreads");
-    } else {
-      os::Linux::set_libpthread_version(str);
-    }
+     char *str = (char *)malloc(n, mtInternal);
+     confstr(_CS_GNU_LIBPTHREAD_VERSION, str, n);
+     // Vanilla RH-9 (glibc 2.3.2) has a bug that confstr() always tells
+     // us "NPTL-0.29" even we are running with LinuxThreads. Check if this
+     // is the case. LinuxThreads has a hard limit on max number of threads.
+     // So sysconf(_SC_THREAD_THREADS_MAX) will return a positive value.
+     // On the other hand, NPTL does not have such a limit, sysconf()
+     // will return -1 and errno is not changed. Check if it is really NPTL.
+     if (strcmp(os::Linux::glibc_version(), "glibc 2.3.2") == 0 &&
+         strstr(str, "NPTL") &&
+         sysconf(_SC_THREAD_THREADS_MAX) > 0) {
+       free(str);
+       os::Linux::set_libpthread_version("linuxthreads");
+     } else {
+       os::Linux::set_libpthread_version(str);
+     }
   } else {
     // glibc before 2.3.2 only has LinuxThreads.
     os::Linux::set_libpthread_version("linuxthreads");
   }
 
   if (strstr(libpthread_version(), "NPTL")) {
-    os::Linux::set_is_NPTL();
+     os::Linux::set_is_NPTL();
   } else {
-    os::Linux::set_is_LinuxThreads();
+     os::Linux::set_is_LinuxThreads();
   }
 
   // LinuxThreads have two flavors: floating-stack mode, which allows variable
   // stack size; and fixed-stack mode. NPTL is always floating-stack.
   if (os::Linux::is_NPTL() || os::Linux::supports_variable_stack_size()) {
-    os::Linux::set_is_floating_stack();
+     os::Linux::set_is_floating_stack();
   }
 }
 
@@ -632,9 +632,9 @@
 // should always be true if the function is not inlined.
 
 #if __GNUC__ < 3    // gcc 2.x does not support noinline attribute
-  #define NOINLINE
+#define NOINLINE
 #else
-  #define NOINLINE __attribute__ ((noinline))
+#define NOINLINE __attribute__ ((noinline))
 #endif
 
 static void _expand_stack_to(address bottom) NOINLINE;
@@ -885,9 +885,9 @@
 
   // Aborted due to thread limit being reached
   if (state == ZOMBIE) {
-    thread->set_osthread(NULL);
-    delete osthread;
-    return false;
+      thread->set_osthread(NULL);
+      delete osthread;
+      return false;
   }
 
   // The thread is returned suspended (in state INITIALIZED),
@@ -907,7 +907,7 @@
 
 bool os::create_attached_thread(JavaThread* thread) {
 #ifdef ASSERT
-  thread->verify_not_published();
+    thread->verify_not_published();
 #endif
 
   // Allocate the OSThread object
@@ -979,7 +979,7 @@
     // Restore caller's signal mask
     sigset_t sigmask = osthread->caller_sigmask();
     pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
-  }
+   }
 
   delete osthread;
 }
@@ -1035,7 +1035,7 @@
          "os::init did not locate initial thread's stack region");
   if ((address)&dummy >= initial_thread_stack_bottom() &&
       (address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size()) {
-    return true;
+       return true;
   } else {
     return false;
   }
@@ -1049,10 +1049,10 @@
     while (!feof(fp)) {
       if (fscanf(fp, "%p-%p", &low, &high) == 2) {
         if (low <= addr && addr < high) {
-          if (vma_low)  *vma_low  = low;
-          if (vma_high) *vma_high = high;
-          fclose(fp);
-          return true;
+           if (vma_low)  *vma_low  = low;
+           if (vma_high) *vma_high = high;
+           fclose(fp);
+           return true;
         }
       }
       for (;;) {
@@ -1089,7 +1089,7 @@
   // FIXME: alt signal stack is gone, maybe we can relax this constraint?
   // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small
   if (stack_size > 2 * K * K IA64_ONLY(*2)) {
-    stack_size = 2 * K * K IA64_ONLY(*2);
+      stack_size = 2 * K * K IA64_ONLY(*2);
   }
   // Try to figure out where the stack base (top) is. This is harder.
   //
@@ -1209,11 +1209,11 @@
 #undef _DFM
 
       if (i != 28 - 2) {
-        assert(false, "Bad conversion from /proc/self/stat");
-        // product mode - assume we are the initial thread, good luck in the
-        // embedded case.
-        warning("Can't detect initial thread stack location - bad conversion");
-        stack_start = (uintptr_t) &rlim;
+         assert(false, "Bad conversion from /proc/self/stat");
+         // product mode - assume we are the initial thread, good luck in the
+         // embedded case.
+         warning("Can't detect initial thread stack location - bad conversion");
+         stack_start = (uintptr_t) &rlim;
       }
     } else {
       // For some reason we can't open /proc/self/stat (for example, running on
@@ -1251,9 +1251,9 @@
   stack_top = align_size_up(stack_top, page_size());
 
   if (max_size && stack_size > max_size) {
-    _initial_thread_stack_size = max_size;
+     _initial_thread_stack_size = max_size;
   } else {
-    _initial_thread_stack_size = stack_size;
+     _initial_thread_stack_size = stack_size;
   }
 
   _initial_thread_stack_size = align_size_down(_initial_thread_stack_size, page_size());
@@ -1310,7 +1310,7 @@
 
 
 #ifndef CLOCK_MONOTONIC
-  #define CLOCK_MONOTONIC (1)
+#define CLOCK_MONOTONIC (1)
 #endif
 
 void os::Linux::clock_init() {
@@ -1353,15 +1353,15 @@
 }
 
 #ifndef SYS_clock_getres
-  #if defined(IA32) || defined(AMD64)
-    #define SYS_clock_getres IA32_ONLY(266)  AMD64_ONLY(229)
-    #define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
-  #else
-    #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
-    #define sys_clock_getres(x,y)  -1
-  #endif
+#if defined(IA32) || defined(AMD64)
+#define SYS_clock_getres IA32_ONLY(266)  AMD64_ONLY(229)
+#define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
 #else
-  #define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
+#warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
+#define sys_clock_getres(x,y)  -1
+#endif
+#else
+#define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
 #endif
 
 void os::Linux::fast_thread_clock_init() {
@@ -1383,8 +1383,8 @@
   // better than 1 sec. This is extra check for reliability.
 
   if (pthread_getcpuclockid_func &&
-      pthread_getcpuclockid_func(_main_thread, &clockid) == 0 &&
-      sys_clock_getres(clockid, &tp) == 0 && tp.tv_sec == 0) {
+     pthread_getcpuclockid_func(_main_thread, &clockid) == 0 &&
+     sys_clock_getres(clockid, &tp) == 0 && tp.tv_sec == 0) {
     _supports_fast_thread_cpu_time = true;
     _pthread_getcpuclockid = pthread_getcpuclockid_func;
   }
@@ -1727,9 +1727,9 @@
   int rslt = dl_iterate_phdr(address_to_library_name_callback, (void *)&data);
 
   if (rslt) {
-    // buf already contains library name
-    if (offset) *offset = addr - data.base;
-    return true;
+     // buf already contains library name
+     if (offset) *offset = addr - data.base;
+     return true;
   }
   if (dladdr((void*)addr, &dlinfo) != 0) {
     if (dlinfo.dli_fname != NULL) {
@@ -1746,9 +1746,9 @@
   return false;
 }
 
-// Loads .dll/.so and
-// in case of error it checks if .dll/.so was built for the
-// same architecture as Hotspot is running on
+  // Loads .dll/.so and
+  // in case of error it checks if .dll/.so was built for the
+  // same architecture as Hotspot is running on
 
 
 // Remember the stack's state. The Linux dynamic linker will change
@@ -1862,7 +1862,7 @@
 
   bool failed_to_read_elf_head=
     (sizeof(elf_head)!=
-     (::read(file_descriptor, &elf_head,sizeof(elf_head))));
+        (::read(file_descriptor, &elf_head,sizeof(elf_head))));
 
   ::close(file_descriptor);
   if (failed_to_read_elf_head) {
@@ -1878,7 +1878,7 @@
     char*       name;         // String representation
   } arch_t;
 
-#ifndef EM_486
+  #ifndef EM_486
   #define EM_486          6               /* Intel 80486 */
 #endif
 #ifndef EM_AARCH64
@@ -1961,7 +1961,7 @@
   }
 
   assert(running_arch_index != -1,
-         "Didn't find running architecture code (running_arch_code) in arch_array");
+    "Didn't find running architecture code (running_arch_code) in arch_array");
   if (running_arch_index == -1) {
     // Even though running architecture detection failed
     // we may still continue with reporting dlerror() message
@@ -1983,13 +1983,13 @@
   if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) {
     if (lib_arch.name!=NULL) {
       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
-                 " (Possible cause: can't load %s-bit .so on a %s-bit platform)",
-                 lib_arch.name, arch_array[running_arch_index].name);
+        " (Possible cause: can't load %s-bit .so on a %s-bit platform)",
+        lib_arch.name, arch_array[running_arch_index].name);
     } else {
       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
-                 " (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)",
-                 lib_arch.code,
-                 arch_array[running_arch_index].name);
+      " (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)",
+        lib_arch.code,
+        arch_array[running_arch_index].name);
     }
   }
 
@@ -2057,7 +2057,7 @@
 static bool _print_ascii_file(const char* filename, outputStream* st) {
   int fd = ::open(filename, O_RDONLY);
   if (fd == -1) {
-    return false;
+     return false;
   }
 
   char buf[32];
@@ -2072,16 +2072,16 @@
 }
 
 void os::print_dll_info(outputStream *st) {
-  st->print_cr("Dynamic libraries:");
-
-  char fname[32];
-  pid_t pid = os::Linux::gettid();
-
-  jio_snprintf(fname, sizeof(fname), "/proc/%d/maps", pid);
-
-  if (!_print_ascii_file(fname, st)) {
-    st->print("Can not get library information for pid = %d\n", pid);
-  }
+   st->print_cr("Dynamic libraries:");
+
+   char fname[32];
+   pid_t pid = os::Linux::gettid();
+
+   jio_snprintf(fname, sizeof(fname), "/proc/%d/maps", pid);
+
+   if (!_print_ascii_file(fname, st)) {
+     st->print("Can not get library information for pid = %d\n", pid);
+   }
 }
 
 int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
@@ -2171,28 +2171,28 @@
 // an informative string like "6.0.6" or "wheezy/sid". Because of this
 // "Debian " is printed before the contents of the debian_version file.
 void os::Linux::print_distro_info(outputStream* st) {
-  if (!_print_ascii_file("/etc/oracle-release", st) &&
-      !_print_ascii_file("/etc/mandriva-release", st) &&
-      !_print_ascii_file("/etc/mandrake-release", st) &&
-      !_print_ascii_file("/etc/sun-release", st) &&
-      !_print_ascii_file("/etc/redhat-release", st) &&
-      !_print_ascii_file("/etc/lsb-release", st) &&
-      !_print_ascii_file("/etc/SuSE-release", st) &&
-      !_print_ascii_file("/etc/turbolinux-release", st) &&
-      !_print_ascii_file("/etc/gentoo-release", st) &&
-      !_print_ascii_file("/etc/ltib-release", st) &&
-      !_print_ascii_file("/etc/angstrom-version", st) &&
-      !_print_ascii_file("/etc/system-release", st) &&
-      !_print_ascii_file("/etc/os-release", st)) {
-
-    if (file_exists("/etc/debian_version")) {
-      st->print("Debian ");
-      _print_ascii_file("/etc/debian_version", st);
-    } else {
-      st->print("Linux");
-    }
-  }
-  st->cr();
+   if (!_print_ascii_file("/etc/oracle-release", st) &&
+       !_print_ascii_file("/etc/mandriva-release", st) &&
+       !_print_ascii_file("/etc/mandrake-release", st) &&
+       !_print_ascii_file("/etc/sun-release", st) &&
+       !_print_ascii_file("/etc/redhat-release", st) &&
+       !_print_ascii_file("/etc/lsb-release", st) &&
+       !_print_ascii_file("/etc/SuSE-release", st) &&
+       !_print_ascii_file("/etc/turbolinux-release", st) &&
+       !_print_ascii_file("/etc/gentoo-release", st) &&
+       !_print_ascii_file("/etc/ltib-release", st) &&
+       !_print_ascii_file("/etc/angstrom-version", st) &&
+       !_print_ascii_file("/etc/system-release", st) &&
+       !_print_ascii_file("/etc/os-release", st)) {
+
+       if (file_exists("/etc/debian_version")) {
+         st->print("Debian ");
+         _print_ascii_file("/etc/debian_version", st);
+       } else {
+         st->print("Linux");
+       }
+   }
+   st->cr();
 }
 
 void os::Linux::print_libversion_info(outputStream* st) {
@@ -2201,15 +2201,15 @@
   st->print("%s ", os::Linux::glibc_version());
   st->print("%s ", os::Linux::libpthread_version());
   if (os::Linux::is_LinuxThreads()) {
-    st->print("(%s stack)", os::Linux::is_floating_stack() ? "floating" : "fixed");
+     st->print("(%s stack)", os::Linux::is_floating_stack() ? "floating" : "fixed");
   }
   st->cr();
 }
 
 void os::Linux::print_full_memory_info(outputStream* st) {
-  st->print("\n/proc/meminfo:\n");
-  _print_ascii_file("/proc/meminfo", st);
-  st->cr();
+   st->print("\n/proc/meminfo:\n");
+   _print_ascii_file("/proc/meminfo", st);
+   st->cr();
 }
 
 void os::print_memory_info(outputStream* st) {
@@ -2299,8 +2299,8 @@
 
   char dli_fname[MAXPATHLEN];
   bool ret = dll_address_to_library_name(
-                                         CAST_FROM_FN_PTR(address, os::jvm_path),
-                                         dli_fname, sizeof(dli_fname), NULL);
+                CAST_FROM_FN_PTR(address, os::jvm_path),
+                dli_fname, sizeof(dli_fname), NULL);
   assert(ret, "cannot locate libjvm");
   char *rp = NULL;
   if (ret && dli_fname[0] != '\0') {
@@ -2362,11 +2362,11 @@
           rp = realpath(dli_fname, buf);
           if (rp == NULL) {
             return;
-          }
         }
       }
     }
   }
+  }
 
   strncpy(saved_jvm_path, buf, MAXPATHLEN);
   saved_jvm_path[MAXPATHLEN - 1] = '\0';
@@ -2390,13 +2390,13 @@
   // the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We
   // don't want to flood the manager thread with sem_post requests.
   if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1) {
-    return;
+      return;
   }
 
   // Ctrl-C is pressed during error reporting, likely because the error
   // handler fails to abort. Let VM die immediately.
   if (sig == SIGINT && is_error_reported()) {
-    os::die();
+     os::die();
   }
 
   os::signal_notify(sig);
@@ -2407,15 +2407,15 @@
 }
 
 class Semaphore : public StackObj {
- public:
-  Semaphore();
-  ~Semaphore();
-  void signal();
-  void wait();
-  bool trywait();
-  bool timedwait(unsigned int sec, int nsec);
- private:
-  sem_t _semaphore;
+  public:
+    Semaphore();
+    ~Semaphore();
+    void signal();
+    void wait();
+    bool trywait();
+    bool timedwait(unsigned int sec, int nsec);
+  private:
+    sem_t _semaphore;
 };
 
 Semaphore::Semaphore() {
@@ -2662,7 +2662,7 @@
 int os::Linux::commit_memory_impl(char* addr, size_t size, bool exec) {
   int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
   uintptr_t res = (uintptr_t) ::mmap(addr, size, prot,
-                                     MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
+                                   MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
   if (res != (uintptr_t) MAP_FAILED) {
     if (UseNUMAInterleaving) {
       numa_make_global(addr, size);
@@ -2697,12 +2697,12 @@
 
 // Define MAP_HUGETLB here so we can build HotSpot on old systems.
 #ifndef MAP_HUGETLB
-  #define MAP_HUGETLB 0x40000
+#define MAP_HUGETLB 0x40000
 #endif
 
 // Define MADV_HUGEPAGE here so we can build HotSpot on old systems.
 #ifndef MADV_HUGEPAGE
-  #define MADV_HUGEPAGE 14
+#define MADV_HUGEPAGE 14
 #endif
 
 int os::Linux::commit_memory_impl(char* addr, size_t size,
@@ -2770,7 +2770,7 @@
   Linux::numa_tonode_memory(addr, bytes, lgrp_hint);
 }
 
-bool os::numa_topology_changed() { return false; }
+bool os::numa_topology_changed()   { return false; }
 
 size_t os::numa_get_groups_num() {
   int max_node = Linux::numa_max_node();
@@ -2810,17 +2810,17 @@
   int retval = -1;
 
 #if defined(IA32)
-  #ifndef SYS_getcpu
-    #define SYS_getcpu 318
-  #endif
+# ifndef SYS_getcpu
+# define SYS_getcpu 318
+# endif
   retval = syscall(SYS_getcpu, &cpu, NULL, NULL);
 #elif defined(AMD64)
 // Unfortunately we have to bring all these macros here from vsyscall.h
 // to be able to compile on old linuxes.
-  #define __NR_vgetcpu 2
-  #define VSYSCALL_START (-10UL << 20)
-  #define VSYSCALL_SIZE 1024
-  #define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
+# define __NR_vgetcpu 2
+# define VSYSCALL_START (-10UL << 20)
+# define VSYSCALL_SIZE 1024
+# define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
   typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache);
   vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu);
   retval = vgetcpu(&cpu, NULL, NULL);
@@ -2870,9 +2870,9 @@
       set_numa_tonode_memory(CAST_TO_FN_PTR(numa_tonode_memory_func_t,
                                             libnuma_dlsym(handle, "numa_tonode_memory")));
       set_numa_interleave_memory(CAST_TO_FN_PTR(numa_interleave_memory_func_t,
-                                                libnuma_dlsym(handle, "numa_interleave_memory")));
+                                            libnuma_dlsym(handle, "numa_interleave_memory")));
       set_numa_set_bind_policy(CAST_TO_FN_PTR(numa_set_bind_policy_func_t,
-                                              libnuma_dlsym(handle, "numa_set_bind_policy")));
+                                            libnuma_dlsym(handle, "numa_set_bind_policy")));
 
 
       if (numa_available() != -1) {
@@ -2944,7 +2944,7 @@
 
 bool os::pd_uncommit_memory(char* addr, size_t size) {
   uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE,
-                                     MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0);
+                MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0);
   return res  != (uintptr_t) MAP_FAILED;
 }
 
@@ -3033,8 +3033,8 @@
     if (mincore((address)stack_extent, os::vm_page_size(), vec) == -1) {
       // Fallback to slow path on all errors, including EAGAIN
       stack_extent = (uintptr_t) get_stack_commited_bottom(
-                                                           os::Linux::initial_thread_stack_bottom(),
-                                                           (size_t)addr - stack_extent);
+                                    os::Linux::initial_thread_stack_bottom(),
+                                    (size_t)addr - stack_extent);
     }
 
     if (stack_extent < (uintptr_t)addr) {
@@ -3107,7 +3107,7 @@
 }
 
 char* os::pd_reserve_memory(size_t bytes, char* requested_addr,
-                            size_t alignment_hint) {
+                         size_t alignment_hint) {
   return anon_mmap(requested_addr, bytes, (requested_addr != NULL));
 }
 
@@ -3298,8 +3298,8 @@
 
   if (!FLAG_IS_DEFAULT(LargePageSizeInBytes) && LargePageSizeInBytes != large_page_size) {
     warning("Setting LargePageSizeInBytes has no effect on this OS. Large page size is "
-            SIZE_FORMAT "%s.", byte_size_in_proper_unit(large_page_size),
-            proper_unit_for_byte_size(large_page_size));
+        SIZE_FORMAT "%s.", byte_size_in_proper_unit(large_page_size),
+        proper_unit_for_byte_size(large_page_size));
   }
 
   return large_page_size;
@@ -3379,7 +3379,7 @@
 }
 
 #ifndef SHM_HUGETLB
-  #define SHM_HUGETLB 04000
+#define SHM_HUGETLB 04000
 #endif
 
 char* os::Linux::reserve_memory_special_shm(size_t bytes, size_t alignment,
@@ -3406,25 +3406,25 @@
   // Currently, size is the total size of the heap
   int shmid = shmget(key, bytes, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
   if (shmid == -1) {
-    // Possible reasons for shmget failure:
-    // 1. shmmax is too small for Java heap.
-    //    > check shmmax value: cat /proc/sys/kernel/shmmax
-    //    > increase shmmax value: echo "0xffffffff" > /proc/sys/kernel/shmmax
-    // 2. not enough large page memory.
-    //    > check available large pages: cat /proc/meminfo
-    //    > increase amount of large pages:
-    //          echo new_value > /proc/sys/vm/nr_hugepages
-    //      Note 1: different Linux may use different name for this property,
-    //            e.g. on Redhat AS-3 it is "hugetlb_pool".
-    //      Note 2: it's possible there's enough physical memory available but
-    //            they are so fragmented after a long run that they can't
-    //            coalesce into large pages. Try to reserve large pages when
-    //            the system is still "fresh".
-    if (warn_on_failure) {
-      jio_snprintf(msg, sizeof(msg), "Failed to reserve shared memory (errno = %d).", errno);
-      warning("%s", msg);
-    }
-    return NULL;
+     // Possible reasons for shmget failure:
+     // 1. shmmax is too small for Java heap.
+     //    > check shmmax value: cat /proc/sys/kernel/shmmax
+     //    > increase shmmax value: echo "0xffffffff" > /proc/sys/kernel/shmmax
+     // 2. not enough large page memory.
+     //    > check available large pages: cat /proc/meminfo
+     //    > increase amount of large pages:
+     //          echo new_value > /proc/sys/vm/nr_hugepages
+     //      Note 1: different Linux may use different name for this property,
+     //            e.g. on Redhat AS-3 it is "hugetlb_pool".
+     //      Note 2: it's possible there's enough physical memory available but
+     //            they are so fragmented after a long run that they can't
+     //            coalesce into large pages. Try to reserve large pages when
+     //            the system is still "fresh".
+     if (warn_on_failure) {
+       jio_snprintf(msg, sizeof(msg), "Failed to reserve shared memory (errno = %d).", errno);
+       warning("%s", msg);
+     }
+     return NULL;
   }
 
   // attach to the region
@@ -3438,11 +3438,11 @@
   shmctl(shmid, IPC_RMID, NULL);
 
   if ((intptr_t)addr == -1) {
-    if (warn_on_failure) {
-      jio_snprintf(msg, sizeof(msg), "Failed to attach shared memory (errno = %d).", err);
-      warning("%s", msg);
-    }
-    return NULL;
+     if (warn_on_failure) {
+       jio_snprintf(msg, sizeof(msg), "Failed to attach shared memory (errno = %d).", err);
+       warning("%s", msg);
+     }
+     return NULL;
   }
 
   return addr;
@@ -3460,7 +3460,7 @@
   if (warn_on_failure) {
     char msg[128];
     jio_snprintf(msg, sizeof(msg), "Failed to reserve large pages memory req_addr: "
-                 PTR_FORMAT " bytes: " SIZE_FORMAT " (errno = %d).", req_addr, bytes, error);
+        PTR_FORMAT " bytes: " SIZE_FORMAT " (errno = %d).", req_addr, bytes, error);
     warning("%s", msg);
   }
 }
@@ -3570,9 +3570,9 @@
   }
 
   if (lp_end != end) {
-    result = ::mmap(lp_end, end - lp_end, prot,
-                    MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,
-                    -1, 0);
+      result = ::mmap(lp_end, end - lp_end, prot,
+                      MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,
+                      -1, 0);
     if (result == MAP_FAILED) {
       ::munmap(start, lp_end - start);
       return NULL;
@@ -3710,12 +3710,12 @@
   // if kernel honors the hint then we can return immediately.
   char * addr = anon_mmap(requested_addr, bytes, false);
   if (addr == requested_addr) {
-    return requested_addr;
+     return requested_addr;
   }
 
   if (addr != NULL) {
-    // mmap() is successful but it fails to reserve at the requested address
-    anon_munmap(addr, bytes);
+     // mmap() is successful but it fails to reserve at the requested address
+     anon_munmap(addr, bytes);
   }
 
   int i;
@@ -4002,12 +4002,12 @@
   if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) {
     int sig = ::strtol(s, 0, 10);
     if (sig > 0 || sig < _NSIG) {
-      SR_signum = sig;
+        SR_signum = sig;
     }
   }
 
   assert(SR_signum > SIGSEGV && SR_signum > SIGBUS,
-         "SR_signum must be greater than max(SIGSEGV, SIGBUS), see 4355769");
+        "SR_signum must be greater than max(SIGSEGV, SIGBUS), see 4355769");
 
   sigemptyset(&SR_sigset);
   sigaddset(&SR_sigset, SR_signum);
@@ -4319,12 +4319,12 @@
     signal_setting_t begin_signal_setting = NULL;
     signal_setting_t end_signal_setting = NULL;
     begin_signal_setting = CAST_TO_FN_PTR(signal_setting_t,
-                                          dlsym(RTLD_DEFAULT, "JVM_begin_signal_setting"));
+                             dlsym(RTLD_DEFAULT, "JVM_begin_signal_setting"));
     if (begin_signal_setting != NULL) {
       end_signal_setting = CAST_TO_FN_PTR(signal_setting_t,
-                                          dlsym(RTLD_DEFAULT, "JVM_end_signal_setting"));
+                             dlsym(RTLD_DEFAULT, "JVM_end_signal_setting"));
       get_signal_action = CAST_TO_FN_PTR(get_signal_t,
-                                         dlsym(RTLD_DEFAULT, "JVM_get_signal_action"));
+                            dlsym(RTLD_DEFAULT, "JVM_get_signal_action"));
       libjsig_is_loaded = true;
       assert(UseSignalChaining, "should enable signal-chaining");
     }
@@ -4390,7 +4390,7 @@
 // We will never set this flag, and we should
 // ignore this flag in our diagnostic
 #ifdef SIGNIFICANT_SIGNAL_MASK
-  #undef SIGNIFICANT_SIGNAL_MASK
+#undef SIGNIFICANT_SIGNAL_MASK
 #endif
 #define SIGNIFICANT_SIGNAL_MASK (~0x04000000)
 
@@ -4449,7 +4449,7 @@
 
   // Check: is it our handler?
   if (handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)signalHandler) ||
-      handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler)) {
+     handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler)) {
     // It is our signal handler
     // check for flags, reset system-used one!
     if ((int)sa.sa_flags != os::Linux::get_our_sigflags(sig)) {
@@ -4462,7 +4462,7 @@
 }
 
 
-#define DO_SIGNAL_CHECK(sig)                      \
+#define DO_SIGNAL_CHECK(sig) \
   do {                                            \
     if (!sigismember(&check_signal_done, sig)) {  \
       os::Linux::check_signal_handler(sig);       \
@@ -4724,22 +4724,22 @@
   // Add in 2*BytesPerWord times page size to account for VM stack during
   // class initialization depending on 32 or 64 bit VM.
   os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,
-                                      (size_t)(StackYellowPages+StackRedPages+StackShadowPages) * Linux::page_size() +
-                                      (2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::vm_default_page_size());
+            (size_t)(StackYellowPages+StackRedPages+StackShadowPages) * Linux::page_size() +
+                    (2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::vm_default_page_size());
 
   size_t threadStackSizeInBytes = ThreadStackSize * K;
   if (threadStackSizeInBytes != 0 &&
       threadStackSizeInBytes < os::Linux::min_stack_allowed) {
-    tty->print_cr("\nThe stack size specified is too small, "
-                  "Specify at least %dk",
-                  os::Linux::min_stack_allowed/ K);
-    return JNI_ERR;
+        tty->print_cr("\nThe stack size specified is too small, "
+                      "Specify at least %dk",
+                      os::Linux::min_stack_allowed/ K);
+        return JNI_ERR;
   }
 
   // Make the stack size a multiple of the page size so that
   // the yellow/red zones can be guarded.
   JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
-                                                vm_page_size()));
+        vm_page_size()));
 
   Linux::capture_initial_stack(JavaThread::stack_size_at_create());
 
@@ -4749,9 +4749,9 @@
 
   Linux::libpthread_init();
   if (PrintMiscellaneous && (Verbose || WizardMode)) {
-    tty->print_cr("[HotSpot is running with %s, %s(%s)]\n",
-                  Linux::glibc_version(), Linux::libpthread_version(),
-                  Linux::is_floating_stack() ? "floating stack" : "fixed stack");
+     tty->print_cr("[HotSpot is running with %s, %s(%s)]\n",
+          Linux::glibc_version(), Linux::libpthread_version(),
+          Linux::is_floating_stack() ? "floating stack" : "fixed stack");
   }
 
   if (UseNUMA) {
@@ -4802,10 +4802,10 @@
       if (status != 0) {
         if (PrintMiscellaneous && (Verbose || WizardMode)) {
           perror("os::init_2 setrlimit failed");
-        }
       }
     }
   }
+  }
 
   // Initialize lock used to serialize thread creation (see os::create_thread)
   Linux::set_createThread_lock(new Mutex(Mutex::leaf, "createThread_lock", false));
@@ -4889,12 +4889,12 @@
 }
 
 class PcFetcher : public os::SuspendedThreadTask {
- public:
+public:
   PcFetcher(Thread* thread) : os::SuspendedThreadTask(thread) {}
   ExtendedPC result();
- protected:
+protected:
   void do_task(const os::SuspendedThreadTaskContext& context);
- private:
+private:
   ExtendedPC _epc;
 };
 
@@ -4929,17 +4929,17 @@
 int os::Linux::safe_cond_timedwait(pthread_cond_t *_cond,
                                    pthread_mutex_t *_mutex,
                                    const struct timespec *_abstime) {
-  if (is_NPTL()) {
-    return pthread_cond_timedwait(_cond, _mutex, _abstime);
-  } else {
-    // 6292965: LinuxThreads pthread_cond_timedwait() resets FPU control
-    // word back to default 64bit precision if condvar is signaled. Java
-    // wants 53bit precision.  Save and restore current value.
-    int fpu = get_fpu_control_word();
-    int status = pthread_cond_timedwait(_cond, _mutex, _abstime);
-    set_fpu_control_word(fpu);
-    return status;
-  }
+   if (is_NPTL()) {
+      return pthread_cond_timedwait(_cond, _mutex, _abstime);
+   } else {
+      // 6292965: LinuxThreads pthread_cond_timedwait() resets FPU control
+      // word back to default 64bit precision if condvar is signaled. Java
+      // wants 53bit precision.  Save and restore current value.
+      int fpu = get_fpu_control_word();
+      int status = pthread_cond_timedwait(_cond, _mutex, _abstime);
+      set_fpu_control_word(fpu);
+      return status;
+   }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -4952,7 +4952,7 @@
     st->print(PTR_FORMAT ": ", addr);
     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
       st->print("%s+%#x", dlinfo.dli_sname,
-                addr - (intptr_t)dlinfo.dli_saddr);
+                 addr - (intptr_t)dlinfo.dli_saddr);
     } else if (dlinfo.dli_fbase != NULL) {
       st->print("<offset %#x>", addr - (intptr_t)dlinfo.dli_fbase);
     } else {
@@ -5118,12 +5118,12 @@
   // With recent kernels, we will perform this check exactly once.
   static sig_atomic_t O_CLOEXEC_is_known_to_work = 0;
   if (!O_CLOEXEC_is_known_to_work) {
-    int flags = ::fcntl(fd, F_GETFD);
+        int flags = ::fcntl(fd, F_GETFD);
     if (flags != -1) {
       if ((flags & FD_CLOEXEC) != 0)
         O_CLOEXEC_is_known_to_work = 1;
       else
-        ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
+            ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
     }
   }
 #endif
@@ -5185,8 +5185,8 @@
 
 // Map a block of memory.
 char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
-                        char *addr, size_t bytes, bool read_only,
-                        bool allow_exec) {
+                     char *addr, size_t bytes, bool read_only,
+                     bool allow_exec) {
   int prot;
   int flags = MAP_PRIVATE;
 
@@ -5215,8 +5215,8 @@
 
 // Remap a block of memory.
 char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset,
-                          char *addr, size_t bytes, bool read_only,
-                          bool allow_exec) {
+                       char *addr, size_t bytes, bool read_only,
+                       bool allow_exec) {
   // same as map_memory() on this OS
   return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only,
                         allow_exec);
@@ -5368,7 +5368,7 @@
     }
   } else {
     jio_fprintf(stderr,
-                "Could not open pause file '%s', continuing immediately.\n", filename);
+      "Could not open pause file '%s', continuing immediately.\n", filename);
   }
 }
 
@@ -5495,28 +5495,28 @@
 
   int v;
   for (;;) {
-    v = _Event;
-    if (Atomic::cmpxchg(v-1, &_Event, v) == v) break;
+      v = _Event;
+      if (Atomic::cmpxchg(v-1, &_Event, v) == v) break;
   }
   guarantee(v >= 0, "invariant");
   if (v == 0) {
-    // Do this the hard way by blocking ...
-    int status = pthread_mutex_lock(_mutex);
-    assert_status(status == 0, status, "mutex_lock");
-    guarantee(_nParked == 0, "invariant");
-    ++_nParked;
-    while (_Event < 0) {
-      status = pthread_cond_wait(_cond, _mutex);
-      // for some reason, under 2.7 lwp_cond_wait() may return ETIME ...
-      // Treat this the same as if the wait was interrupted
-      if (status == ETIME) { status = EINTR; }
-      assert_status(status == 0 || status == EINTR, status, "cond_wait");
-    }
-    --_nParked;
+     // Do this the hard way by blocking ...
+     int status = pthread_mutex_lock(_mutex);
+     assert_status(status == 0, status, "mutex_lock");
+     guarantee(_nParked == 0, "invariant");
+     ++_nParked;
+     while (_Event < 0) {
+        status = pthread_cond_wait(_cond, _mutex);
+        // for some reason, under 2.7 lwp_cond_wait() may return ETIME ...
+        // Treat this the same as if the wait was interrupted
+        if (status == ETIME) { status = EINTR; }
+        assert_status(status == 0 || status == EINTR, status, "cond_wait");
+     }
+     --_nParked;
 
     _Event = 0;
-    status = pthread_mutex_unlock(_mutex);
-    assert_status(status == 0, status, "mutex_unlock");
+     status = pthread_mutex_unlock(_mutex);
+     assert_status(status == 0, status, "mutex_unlock");
     // Paranoia to ensure our locked and lock-free paths interact
     // correctly with each other.
     OrderAccess::fence();
@@ -5534,8 +5534,8 @@
 
   int v;
   for (;;) {
-    v = _Event;
-    if (Atomic::cmpxchg(v-1, &_Event, v) == v) break;
+      v = _Event;
+      if (Atomic::cmpxchg(v-1, &_Event, v) == v) break;
   }
   guarantee(v >= 0, "invariant");
   if (v != 0) return OS_OK;
@@ -5579,7 +5579,7 @@
   }
   --_nParked;
   if (_Event >= 0) {
-    ret = OS_OK;
+     ret = OS_OK;
   }
   _Event = 0;
   status = pthread_mutex_unlock(_mutex);
@@ -5596,8 +5596,8 @@
   //    0 => 1 : just return
   //    1 => 1 : just return
   //   -1 => either 0 or 1; must signal target thread
-  //         That is, we can safely transition _Event from -1 to either
-  //         0 or 1.
+  //          That is, we can safely transition _Event from -1 to either
+  //          0 or 1.
   // See also: "Semaphores in Plan 9" by Mullender & Cox
   //
   // Note: Forcing a transition from "-1" to "1" on an unpark() means
@@ -5831,14 +5831,14 @@
     if (_cur_index != -1) {
       // thread is definitely parked
       if (WorkAroundNPTLTimedWaitHang) {
-        status = pthread_cond_signal(&_cond[_cur_index]);
+        status = pthread_cond_signal (&_cond[_cur_index]);
         assert(status == 0, "invariant");
         status = pthread_mutex_unlock(_mutex);
         assert(status == 0, "invariant");
       } else {
         status = pthread_mutex_unlock(_mutex);
         assert(status == 0, "invariant");
-        status = pthread_cond_signal(&_cond[_cur_index]);
+        status = pthread_cond_signal (&_cond[_cur_index]);
         assert(status == 0, "invariant");
       }
     } else {
@@ -5875,7 +5875,7 @@
   // On IA64 there's no fork syscall, we have to use fork() and hope for
   // the best...
   pid_t pid = NOT_IA64(syscall(__NR_fork);)
-  IA64_ONLY(fork();)
+              IA64_ONLY(fork();)
 
   if (pid < 0) {
     // fork failed
@@ -5906,26 +5906,26 @@
     // Wait for the child process to exit.  This returns immediately if
     // the child has already exited. */
     while (waitpid(pid, &status, 0) < 0) {
-      switch (errno) {
-      case ECHILD: return 0;
-      case EINTR: break;
-      default: return -1;
-      }
+        switch (errno) {
+        case ECHILD: return 0;
+        case EINTR: break;
+        default: return -1;
+        }
     }
 
     if (WIFEXITED(status)) {
-      // The child exited normally; get its exit code.
-      return WEXITSTATUS(status);
+       // The child exited normally; get its exit code.
+       return WEXITSTATUS(status);
     } else if (WIFSIGNALED(status)) {
-      // The child exited because of a signal
-      // The best value to return is 0x80 + signal number,
-      // because that is what all Unix shells do, and because
-      // it allows callers to distinguish between process exit and
-      // process death by signal.
-      return 0x80 + WTERMSIG(status);
+       // The child exited because of a signal
+       // The best value to return is 0x80 + signal number,
+       // because that is what all Unix shells do, and because
+       // it allows callers to distinguish between process exit and
+       // process death by signal.
+       return 0x80 + WTERMSIG(status);
     } else {
-      // Unknown exit code; pass it through
-      return status;
+       // Unknown exit code; pass it through
+       return status;
     }
   }
 }
@@ -5939,43 +5939,43 @@
 // as libawt.so, and renamed libawt_xawt.so
 //
 bool os::is_headless_jre() {
-  struct stat statbuf;
-  char buf[MAXPATHLEN];
-  char libmawtpath[MAXPATHLEN];
-  const char *xawtstr  = "/xawt/libmawt.so";
-  const char *new_xawtstr = "/libawt_xawt.so";
-  char *p;
-
-  // Get path to libjvm.so
-  os::jvm_path(buf, sizeof(buf));
-
-  // Get rid of libjvm.so
-  p = strrchr(buf, '/');
+    struct stat statbuf;
+    char buf[MAXPATHLEN];
+    char libmawtpath[MAXPATHLEN];
+    const char *xawtstr  = "/xawt/libmawt.so";
+    const char *new_xawtstr = "/libawt_xawt.so";
+    char *p;
+
+    // Get path to libjvm.so
+    os::jvm_path(buf, sizeof(buf));
+
+    // Get rid of libjvm.so
+    p = strrchr(buf, '/');
   if (p == NULL) {
     return false;
   } else {
     *p = '\0';
   }
 
-  // Get rid of client or server
-  p = strrchr(buf, '/');
+    // Get rid of client or server
+    p = strrchr(buf, '/');
   if (p == NULL) {
     return false;
   } else {
     *p = '\0';
   }
 
-  // check xawt/libmawt.so
-  strcpy(libmawtpath, buf);
-  strcat(libmawtpath, xawtstr);
-  if (::stat(libmawtpath, &statbuf) == 0) return false;
-
-  // check libawt_xawt.so
-  strcpy(libmawtpath, buf);
-  strcat(libmawtpath, new_xawtstr);
-  if (::stat(libmawtpath, &statbuf) == 0) return false;
-
-  return true;
+    // check xawt/libmawt.so
+    strcpy(libmawtpath, buf);
+    strcat(libmawtpath, xawtstr);
+    if (::stat(libmawtpath, &statbuf) == 0) return false;
+
+    // check libawt_xawt.so
+    strcpy(libmawtpath, buf);
+    strcat(libmawtpath, new_xawtstr);
+    if (::stat(libmawtpath, &statbuf) == 0) return false;
+
+    return true;
 }
 
 // Get the default path to the core file
@@ -6054,12 +6054,12 @@
 
 #ifndef PRODUCT
 
-#define test_log(...)              \
-  do {                             \
-    if (VerboseInternalVMTests) {  \
-      tty->print_cr(__VA_ARGS__);  \
-      tty->flush();                \
-    }                              \
+#define test_log(...) \
+  do {\
+    if (VerboseInternalVMTests) { \
+      tty->print_cr(__VA_ARGS__); \
+      tty->flush(); \
+    }\
   } while (false)
 
 class TestReserveMemorySpecial : AllStatic {
@@ -6103,11 +6103,11 @@
 
   static void test_reserve_memory_special_huge_tlbfs_mixed(size_t size, size_t alignment) {
     if (!UseHugeTLBFS) {
-      return;
+        return;
     }
 
     test_log("test_reserve_memory_special_huge_tlbfs_mixed(" SIZE_FORMAT ", " SIZE_FORMAT ")",
-             size, alignment);
+        size, alignment);
 
     assert(size >= os::large_page_size(), "Incorrect input to test");
 
--- a/src/os/posix/dtrace/hotspot_jni.d	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/os/posix/dtrace/hotspot_jni.d	Thu Apr 16 21:23:06 2015 -0700
@@ -300,6 +300,8 @@
   probe GetLongField__return(uintptr_t);
   probe GetMethodID__entry(void*, void*, const char*, const char*);
   probe GetMethodID__return(uintptr_t);
+  probe GetModule__entry(void*, void*);
+  probe GetModule__return(void*);
   probe GetObjectArrayElement__entry(void*, void*, uintptr_t);
   probe GetObjectArrayElement__return(void*);
   probe GetObjectClass__entry(void*, void*);
--- a/src/share/vm/c1/c1_LIRGenerator.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/c1/c1_LIRGenerator.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -3051,7 +3051,7 @@
     LIR_Opr klass = new_pointer_register();
     __ move(new LIR_Address(arg.result(), java_lang_Class::klass_offset_in_bytes(), klass_pointer_type), klass, info);
     LIR_Opr id = new_register(T_LONG);
-    ByteSize offset = TRACE_ID_OFFSET;
+    ByteSize offset = TRACE_KLASS_TRACE_ID_OFFSET;
     LIR_Address* trace_id_addr = new LIR_Address(klass, in_bytes(offset), T_LONG);
     __ move(trace_id_addr, id);
     __ logical_or(id, LIR_OprFact::longConst(0x01l), id);
--- a/src/share/vm/c1/c1_Runtime1.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/c1/c1_Runtime1.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -638,7 +638,7 @@
   NOT_PRODUCT(_throw_class_cast_exception_count++;)
   ResourceMark rm(thread);
   char* message = SharedRuntime::generate_class_cast_message(
-    thread, object->klass()->external_name());
+    thread, object->klass());
   SharedRuntime::throw_and_post_jvmti_exception(
     thread, vmSymbols::java_lang_ClassCastException(), message);
 JRT_END
--- a/src/share/vm/ci/ciEnv.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/ci/ciEnv.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -370,9 +370,9 @@
     resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass();
   }
   if (resolved_klass->oop_is_instance()) {
-    return Reflection::verify_class_access(accessing_klass->get_Klass(),
-                                           resolved_klass,
-                                           true);
+    return (Reflection::verify_class_access(accessing_klass->get_Klass(),
+                                            resolved_klass,
+                                            true) == Reflection::ACCESS_OK);
   }
   return true;
 }
--- a/src/share/vm/classfile/classFileParser.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/classFileParser.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -28,6 +28,8 @@
 #include "classfile/classLoaderData.inline.hpp"
 #include "classfile/defaultMethods.hpp"
 #include "classfile/javaClasses.inline.hpp"
+#include "classfile/moduleEntry.hpp"
+#include "classfile/packageEntry.hpp"
 #include "classfile/symbolTable.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/verificationType.hpp"
@@ -4127,6 +4129,17 @@
       this_klass->set_host_klass(host_klass());
     }
 
+    // After the majority of the set up for this_klass has occurred,
+    // set its PackageEntry.  Critical to be done after set_name
+    // and set_host_klass in order to handle anonymous classes
+    // properly.
+    oop cl = this_klass->is_anonymous() ? this_klass->host_klass()->class_loader() :
+                                          this_klass->class_loader();
+
+    Handle clh = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(cl));
+    ClassLoaderData* cld = ClassLoaderData::class_loader_data_or_null(clh());
+    this_klass->set_package(this_klass->name(), cld, CHECK_NULL);
+
     // Set up Method*::intrinsic_id as soon as we know the names of methods.
     // (We used to do this lazily, but now we query it in Rewriter,
     // which is eagerly done for every method, so we might as well do it now,
@@ -4190,8 +4203,13 @@
       }
     }
 
+    // Obtain this_klass' module
+    ModuleEntry* module_entry = this_klass->module();
+    // Check for unnamed module, obtain j.l.r.Module if available
+    Handle class_module(THREAD, ((module_entry == NULL) ? (oop)NULL : module_entry->module()));
+
     // Allocate mirror and initialize static fields
-    java_lang_Class::create_mirror(this_klass, class_loader, protection_domain,
+    java_lang_Class::create_mirror(this_klass, class_loader, class_module, protection_domain,
                                    CHECK_(nullHandle));
 
     // Generate any default methods - default methods are interface methods
@@ -4586,17 +4604,29 @@
 
 void ClassFileParser::check_super_class_access(instanceKlassHandle this_klass, TRAPS) {
   Klass* super = this_klass->super();
-  if ((super != NULL) &&
-      (!Reflection::verify_class_access(this_klass(), super, false))) {
-    ResourceMark rm(THREAD);
-    Exceptions::fthrow(
-      THREAD_AND_LOCATION,
-      vmSymbols::java_lang_IllegalAccessError(),
-      "class %s cannot access its superclass %s",
-      this_klass->external_name(),
-      InstanceKlass::cast(super)->external_name()
-    );
-    return;
+  if (super != NULL) {
+    Reflection::VerifyClassAccessResults vca_result =
+      Reflection::verify_class_access(this_klass(), super, false);
+    if (vca_result != Reflection::ACCESS_OK) {
+      ResourceMark rm(THREAD);
+      char* msg =  Reflection::verify_class_access_msg(this_klass(), super, vca_result);
+      if (msg == NULL) {
+        Exceptions::fthrow(
+          THREAD_AND_LOCATION,
+          vmSymbols::java_lang_IllegalAccessError(),
+          "class %s cannot access its superclass %s",
+          this_klass->external_name(),
+          InstanceKlass::cast(super)->external_name());
+      } else {
+        // Add additional message content.
+        Exceptions::fthrow(
+          THREAD_AND_LOCATION,
+          vmSymbols::java_lang_IllegalAccessError(),
+          "superclass access check failed: %s",
+          msg);
+      }
+      return;
+    }
   }
 }
 
@@ -4607,15 +4637,26 @@
   for (int i = lng - 1; i >= 0; i--) {
     Klass* k = local_interfaces->at(i);
     assert (k != NULL && k->is_interface(), "invalid interface");
-    if (!Reflection::verify_class_access(this_klass(), k, false)) {
+    Reflection::VerifyClassAccessResults vca_result =
+      Reflection::verify_class_access(this_klass(), k, false);
+    if (vca_result != Reflection::ACCESS_OK) {
       ResourceMark rm(THREAD);
-      Exceptions::fthrow(
-        THREAD_AND_LOCATION,
-        vmSymbols::java_lang_IllegalAccessError(),
-        "class %s cannot access its superinterface %s",
-        this_klass->external_name(),
-        InstanceKlass::cast(k)->external_name()
-      );
+      char* msg =  Reflection::verify_class_access_msg(this_klass(), k, vca_result);
+      if (msg == NULL) {
+        Exceptions::fthrow(
+          THREAD_AND_LOCATION,
+          vmSymbols::java_lang_IllegalAccessError(),
+          "class %s cannot access its superinterface %s",
+          this_klass->external_name(),
+          InstanceKlass::cast(k)->external_name());
+      } else {
+        // Add additional message content.
+        Exceptions::fthrow(
+          THREAD_AND_LOCATION,
+          vmSymbols::java_lang_IllegalAccessError(),
+          "superinterface check failed: %s",
+          msg);
+      }
       return;
     }
   }
@@ -4714,12 +4755,13 @@
   const bool is_super      = (flags & JVM_ACC_SUPER)      != 0;
   const bool is_enum       = (flags & JVM_ACC_ENUM)       != 0;
   const bool is_annotation = (flags & JVM_ACC_ANNOTATION) != 0;
+  const bool is_module_info= (flags & JVM_ACC_MODULE)     != 0;
   const bool major_gte_15  = _major_version >= JAVA_1_5_VERSION;
 
   if ((is_abstract && is_final) ||
       (is_interface && !is_abstract) ||
       (is_interface && major_gte_15 && (is_super || is_enum)) ||
-      (!is_interface && major_gte_15 && is_annotation)) {
+      (!is_interface && major_gte_15 && is_annotation) || is_module_info) {
     ResourceMark rm(THREAD);
     Exceptions::fthrow(
       THREAD_AND_LOCATION,
@@ -4869,65 +4911,9 @@
 
 void ClassFileParser::verify_legal_utf8(const unsigned char* buffer, int length, TRAPS) {
   assert(_need_verify, "only called when _need_verify is true");
-  int i = 0;
-  int count = length >> 2;
-  for (int k=0; k<count; k++) {
-    unsigned char b0 = buffer[i];
-    unsigned char b1 = buffer[i+1];
-    unsigned char b2 = buffer[i+2];
-    unsigned char b3 = buffer[i+3];
-    // For an unsigned char v,
-    // (v | v - 1) is < 128 (highest bit 0) for 0 < v < 128;
-    // (v | v - 1) is >= 128 (highest bit 1) for v == 0 or v >= 128.
-    unsigned char res = b0 | b0 - 1 |
-                        b1 | b1 - 1 |
-                        b2 | b2 - 1 |
-                        b3 | b3 - 1;
-    if (res >= 128) break;
-    i += 4;
+  if (!UTF8::is_legal_utf8(buffer, length, _major_version <= 47)) {
+        classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", CHECK);
   }
-  for(; i < length; i++) {
-    unsigned short c;
-    // no embedded zeros
-    guarantee_property((buffer[i] != 0), "Illegal UTF8 string in constant pool in class file %s", CHECK);
-    if(buffer[i] < 128) {
-      continue;
-    }
-    if ((i + 5) < length) { // see if it's legal supplementary character
-      if (UTF8::is_supplementary_character(&buffer[i])) {
-        c = UTF8::get_supplementary_character(&buffer[i]);
-        i += 5;
-        continue;
-      }
-    }
-    switch (buffer[i] >> 4) {
-      default: break;
-      case 0x8: case 0x9: case 0xA: case 0xB: case 0xF:
-        classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", CHECK);
-      case 0xC: case 0xD:  // 110xxxxx  10xxxxxx
-        c = (buffer[i] & 0x1F) << 6;
-        i++;
-        if ((i < length) && ((buffer[i] & 0xC0) == 0x80)) {
-          c += buffer[i] & 0x3F;
-          if (_major_version <= 47 || c == 0 || c >= 0x80) {
-            // for classes with major > 47, c must a null or a character in its shortest form
-            break;
-          }
-        }
-        classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", CHECK);
-      case 0xE:  // 1110xxxx 10xxxxxx 10xxxxxx
-        c = (buffer[i] & 0xF) << 12;
-        i += 2;
-        if ((i < length) && ((buffer[i-1] & 0xC0) == 0x80) && ((buffer[i] & 0xC0) == 0x80)) {
-          c += ((buffer[i-1] & 0x3F) << 6) + (buffer[i] & 0x3F);
-          if (_major_version <= 47 || c >= 0x800) {
-            // for classes with major > 47, c must be in its shortest form
-            break;
-          }
-        }
-        classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", CHECK);
-    }  // end of switch
-  } // end of for
 }
 
 // Checks if name is a legal class name.
@@ -5111,6 +5097,8 @@
 // or <clinit>.  Note that method names may not be <init> or <clinit> in this
 // method.  Because these names have been checked as special cases before
 // calling this method in verify_legal_method_name.
+//
+// This method is also called from jvm.cpp. Be careful about changing it.
 bool ClassFileParser::verify_unqualified_name(
     char* name, unsigned int length, int type) {
   jchar ch;
@@ -5118,8 +5106,15 @@
   for (char* p = name; p != name + length; ) {
     ch = *p;
     if (ch < 128) {
-      p++;
-      if (ch == '.' || ch == ';' || ch == '[' ) {
+      if (ch == '.') {
+        // permit '.' in module names unless it's the first char, or
+        // preceding char is also a '.', or last char is a '.'.
+        if ((type != LegalModule) || (p == name) || (*(p-1) == '.') ||
+          (p == name + length - 1)) {
+          return false;
+        }
+      }
+      if (ch == ';' || ch == '[' ) {
         return false;   // do not permit '.', ';', or '['
       }
       if (type != LegalClass && ch == '/') {
@@ -5128,6 +5123,7 @@
       if (type == LegalMethod && (ch == '<' || ch == '>')) {
         return false;   // do not permit '<' or '>' in method names
       }
+      p++;
     } else {
       char* tmp_p = UTF8::next(p, &ch);
       p = tmp_p;
--- a/src/share/vm/classfile/classFileParser.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/classFileParser.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -204,8 +204,10 @@
 
   ClassFileStream* _stream;              // Actual input stream
 
-  enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
+  public:
+  enum { LegalClass, LegalField, LegalMethod, LegalModule }; // used to verify unqualified names
 
+  private:
   // Accessors
   ClassFileStream* stream()                        { return _stream; }
   void set_stream(ClassFileStream* st)             { _stream = st; }
@@ -379,7 +381,7 @@
   void verify_legal_class_modifiers(jint flags, TRAPS);
   void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS);
   void verify_legal_method_modifiers(jint flags, bool is_interface, Symbol* name, TRAPS);
-  bool verify_unqualified_name(char* name, unsigned int length, int type);
+
   char* skip_over_field_name(char* name, bool slash_ok, unsigned int length);
   char* skip_over_field_signature(char* signature, bool void_ok, unsigned int length, TRAPS);
 
@@ -483,6 +485,7 @@
   static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
   static void check_final_method_override(instanceKlassHandle this_klass, TRAPS);
   static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS);
+  static bool verify_unqualified_name(char* name, unsigned int length, int type);
 };
 
 #endif // SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP
--- a/src/share/vm/classfile/classLoader.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/classLoader.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -30,6 +30,9 @@
 #include "classfile/classLoaderData.inline.hpp"
 #include "classfile/imageFile.hpp"
 #include "classfile/javaClasses.hpp"
+#include "classfile/moduleEntry.hpp"
+#include "classfile/modules.hpp"
+#include "classfile/packageEntry.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
 #include "compiler/compileBroker.hpp"
@@ -68,7 +71,6 @@
 #include "classfile/sharedClassUtil.hpp"
 #endif
 
-
 // Entry points in zip.dll for loading zip/jar file entries and image file entries
 
 typedef void * * (JNICALL *ZipOpen_t)(const char *name, char **pmsg);
@@ -124,10 +126,12 @@
 PerfCounter*    ClassLoader::_isUnsyncloadClass = NULL;
 PerfCounter*    ClassLoader::_load_instance_class_failCounter = NULL;
 
-ClassPathEntry* ClassLoader::_first_entry         = NULL;
-ClassPathEntry* ClassLoader::_last_entry          = NULL;
-int             ClassLoader::_num_entries         = 0;
+ClassPathEntry* ClassLoader::_first_entry = NULL;
+ClassPathEntry* ClassLoader::_last_entry  = NULL;
+int             ClassLoader::_num_entries = 0;
+ClassPathEntry* ClassLoader::_first_append_entry = NULL;
 PackageHashtable* ClassLoader::_package_hash_table = NULL;
+bool            ClassLoader::_has_bootmodules_jimage = false;
 
 #if INCLUDE_CDS
 SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL;
@@ -167,7 +171,6 @@
   _dir = copy;
 }
 
-
 ClassFileStream* ClassPathDirEntry::open_stream(const char* name, TRAPS) {
   // construct full path name
   char path[JVM_MAXPATHLEN];
@@ -352,16 +355,212 @@
   }
 }
 
-ClassPathImageEntry::ClassPathImageEntry(char* name) : ClassPathEntry(), _image(new ImageFile(name)) {
-  bool opened = _image->open();
-  if (!opened) {
-    _image = NULL;
+// Find package names for java.base module by scanning directories starting
+// with java_base_path.  Add each found package to the boot classloader's
+// package_entry table.
+// To find package names, look at each sub-directory.  If it contains one or
+// more '.class' files then create a package name from the sub-directory path
+// relative to java_base_path.  Also, make sure that the package name delimeters
+// are virgules.
+static void package_list(char *java_base_path, ModuleEntry* jb_module) {
+  Thread* THREAD = Thread::current();
+  ResourceMark rm(THREAD);
+  struct stat stat_buf;
+  struct dirent* dir_entry;
+  char stat_path[JVM_MAXPATHLEN];
+  ClassLoaderData* null_cld = ClassLoaderData::the_null_class_loader_data();
+  PackageEntryTable* null_cld_packages = null_cld->packages();
+  const char* file_sep = os::file_separator();
+
+  size_t start_len = strlen(java_base_path);
+  char *current_path = java_base_path;
+  GrowableArray<char *>* dir_stack = new GrowableArray<char *>(15);
+  if (TraceModules) {
+    tty->print_cr("module path:  %s", java_base_path);
+  }
+
+  // Loop through all the sub-directories
+  while (current_path != NULL) {
+    bool dir_already_listed = false;
+    DIR *dir = os::opendir(current_path);
+    if (dir == NULL) {
+      vm_exit_during_initialization(
+        "Unable to open modules directory: ", current_path);
+    }
+
+    char *dbuf = NEW_C_HEAP_ARRAY(
+      char, os::readdir_buf_size(current_path), mtInternal);
+
+    MutexLocker m1(Module_lock, THREAD);
+
+    // Look at each entry in the directory.
+    while ((dir_entry = os::readdir(dir, (dirent *)dbuf)) != NULL) {
+      // Ignore anything starting with '.', including '.' and '..'.
+      if (dir_entry->d_name[0] != '.') {
+
+        // Create full path for stat().
+        sprintf(stat_path, "%s%s%s", current_path, file_sep, dir_entry->d_name);
+        int res = os::stat(stat_path, &stat_buf);
+        assert(res == 0, err_msg("os::stat() failed, file: %s", dir_entry->d_name));
+
+        if ((stat_buf.st_mode & S_IFMT) == S_IFDIR) {
+          // It's a sub-directory, push it on the stack to be looked at later.
+          char *dir_name = NEW_RESOURCE_ARRAY(char, strlen(stat_path) + 1);
+          strcpy(dir_name, stat_path);
+          dir_stack->push(dir_name);
+
+        } else if (!dir_already_listed &&
+                   ((stat_buf.st_mode & S_IFMT) == S_IFREG) &&
+                   string_ends_with(dir_entry->d_name, ".class")) {
+          // This directory entry is a file ending in '.class'.  Construct a
+          // package name from its dir by chopping off the original prefix and
+          // starting '/'.
+          char *package_name = current_path + start_len + 1;
+
+          // Ignore classes in .../modules/java.base directory.
+          if (strlen(package_name) != 0) {
+            if (file_sep[0] != '/') { // Change file separators to '/'.
+              for (char* p = package_name; *p != 0; ++p) {
+                if (*p == file_sep[0]) *p = '/';
+              }
+            }
+            // Found the package name, first look it up in the symbol table.
+            TempNewSymbol pkg_name = SymbolTable::new_symbol(package_name, CHECK);
+
+            // Insert into the null class loader's package entry table.
+            PackageEntry* pkg = null_cld_packages->locked_create_entry_or_null(
+                                  pkg_name, jb_module);
+            assert(pkg != NULL,
+                   err_msg("Package %s not found in package entry table", package_name));
+            dir_already_listed = true;
+            if (TraceModules) {
+              tty->print_cr("package:  %s", package_name);
+            }
+          }
+        }
+      }
+    }
+    FREE_C_HEAP_ARRAY(char, dbuf);
+    current_path = dir_stack->is_empty() ? NULL : dir_stack->pop();
+    os::closedir(dir);
+  }
+}
+
+static void process_javabase(const char* path) {
+  Thread* THREAD = Thread::current();
+
+  // The build exploded directory for java.base being opened due to
+  // processing the first well known class java/lang/Object.  Must create
+  // java.base's module entry and package entries for the null class
+  // loader prior to loading j.l.Ojbect.
+  ClassLoaderData* null_cld = ClassLoaderData::the_null_class_loader_data();
+
+  // Get module entry table
+  ModuleEntryTable* null_cld_modules = null_cld->modules();
+  assert(null_cld_modules != NULL, "No module entry table for boot class loader?");
+
+  // Add entry, without a java.lang.reflect.Module object yet.
+  // The j.l.r.m will be added later.
+  ModuleEntry* jb_module = NULL;
+  TempNewSymbol version_symbol = SymbolTable::new_symbol(Modules::default_version(), THREAD);
+  assert(version_symbol != NULL, "Symbol creation failed");
+  TempNewSymbol location_symbol = SymbolTable::new_symbol("jrt:/java.base", THREAD);
+  assert(location_symbol != NULL, "Symbol creation failed");
+  {
+    MutexLocker ml(Module_lock, THREAD);
+    jb_module = null_cld_modules->locked_create_entry_or_null(
+      NULL, vmSymbols::java_base(), version_symbol, location_symbol, null_cld);
+    assert(jb_module != NULL, "no entry created for java.base");
+  }
+
+  if (TraceModules) {
+    tty->print_cr("[Local packages for java.base:]");
+  }
+
+  char modules_path[JVM_MAXPATHLEN];
+  strcpy(modules_path, path);
+  package_list(modules_path, jb_module);
+}
+
+static void process_javabase(ClassPathImageEntry *entry) {
+  Thread* THREAD = Thread::current();
+  ResourceMark rm(THREAD);
+
+  ImageFileReader* image = entry->image();
+  ImageModuleData* module_data = entry->module_data();
+
+  // bootmodules.jimage being opened due to processing
+  // the first well known class java/lang/Object.  Must create
+  // java.base's module entry and package entries for the null
+  // class loader prior to loading j.l.Ojbect.
+  ClassLoaderData* null_cld = ClassLoaderData::the_null_class_loader_data();
+
+  // Get module entry table
+  PackageEntryTable* null_cld_packages = null_cld->packages();
+  ModuleEntryTable* null_cld_modules = null_cld->modules();
+  assert((null_cld_modules != NULL || null_cld_packages != NULL),
+         "No package and/or module table for boot class loader?");
+
+  // Add entry, without a java.lang.reflect.Module object yet.
+  // The j.l.r.m will be added later.
+  TempNewSymbol version_symbol = SymbolTable::new_symbol(Modules::default_version(), THREAD);
+  assert(version_symbol != NULL, "Symbol creation failed");
+  TempNewSymbol location_symbol = SymbolTable::new_symbol("jrt:/java.base", THREAD);
+  assert(location_symbol != NULL, "Symbol creation failed");
+  MutexLocker ml(Module_lock, THREAD);
+  ModuleEntry* jb_module = null_cld_modules->locked_create_entry_or_null(
+    NULL, vmSymbols::java_base(), version_symbol, location_symbol, null_cld);
+  assert(jb_module != NULL, "no entry created for java.base");
+
+  if (TraceModules) {
+    tty->print_cr("[Local packages for java.base:]");
+  }
+
+  GrowableArray<const char*>* packages =
+      module_data->module_to_packages(vmSymbols::java_base()->as_C_string());
+
+  for (int i = 0; i < packages->length(); i++) {
+    // Verify valid package name.
+    const char* package_name = packages->at(i);
+    if (!Modules::verify_package_name((char *)package_name)) {
+      vm_exit_during_initialization(
+        "invalid package name in " BOOT_IMAGE_NAME " file",
+        package_name == NULL ? "NULL" : package_name);
+    }
+
+    // Found the package name, first look it up in the symbol table.
+    TempNewSymbol pkg_name = SymbolTable::new_symbol(package_name, CHECK);
+
+    // Insert into the null class loader's package entry table.
+    PackageEntry* pkg = null_cld_packages->locked_create_entry_or_null(pkg_name, jb_module);
+    assert(pkg != NULL, "Package should have been defined and found in package entry table");
+
+    if (TraceModules) {
+      tty->print_cr("  %s", package_name);
+    }
+  }
+}
+
+ClassPathImageEntry::ClassPathImageEntry(ImageFileReader* image) :
+  ClassPathEntry(),
+  _image(image),
+  _module_data(NULL) {
+
+  if (is_open()) {
+    char module_data_name[JVM_MAXPATHLEN];
+    ImageModuleData::module_data_name(module_data_name, _image->name());
+    _module_data = new ImageModuleData(_image, module_data_name);
   }
 }
 
 ClassPathImageEntry::~ClassPathImageEntry() {
+  if (_module_data) {
+    delete _module_data;
+    _module_data = NULL;
+  }
+
   if (_image) {
-    _image->close();
+    ImageFileReader::close(_image);
     _image = NULL;
   }
 }
@@ -370,16 +569,38 @@
   return _image ? _image->name() : "";
 }
 
+bool ClassPathImageEntry::is_verified() {
+  return _image && _image->is_verified();
+}
+
+
 ClassFileStream* ClassPathImageEntry::open_stream(const char* name, TRAPS) {
   u1* buffer;
   u8 size;
   _image->get_resource(name, buffer, size);
 
+  if (!buffer) {
+    const char *pslash = strrchr(name, '/');
+
+    if (pslash) {
+      char path[JVM_MAXPATHLEN];
+      int len = pslash - name;
+      strncpy(path, name, len);
+      path[len] = '\0';
+      const char* moduleName = _module_data->package_to_module(path);
+
+      if (moduleName) {
+        jio_snprintf(path, JVM_MAXPATHLEN - 1, "/%s/%s", moduleName, name);
+        _image->get_resource(path, buffer, size);
+      }
+    }
+  }
+
   if (buffer) {
     if (UsePerfData) {
       ClassLoader::perf_sys_classfile_bytes_read()->inc(size);
     }
-    return new ClassFileStream(buffer, (int)size, (char*)name);  // Resource allocated
+    return new ClassFileStream(buffer, (int)size, _image->name());  // Resource allocated
   }
 
   return NULL;
@@ -391,20 +612,14 @@
   tty->cr();
   const ImageStrings strings = _image->get_strings();
   // Retrieve each path component string.
-  u4 count = _image->get_location_count();
-  for (u4 i = 0; i < count; i++) {
+  u4 length = _image->table_length();
+  for (u4 i = 0; i < length; i++) {
     u1* location_data = _image->get_location_data(i);
 
     if (location_data) {
        ImageLocation location(location_data);
-       const char* parent = location.get_attribute(ImageLocation::ATTRIBUTE_PARENT, strings);
-       const char* base = location.get_attribute(ImageLocation::ATTRIBUTE_BASE, strings);
-       const char* extension = location.get_attribute(ImageLocation::ATTRIBUTE_EXTENSION, strings);
-       assert((strlen(parent) + strlen(base) + strlen(extension)) < JVM_MAXPATHLEN, "path exceeds buffer");
        char path[JVM_MAXPATHLEN];
-       strcpy(path, parent);
-       strcat(path, base);
-       strcat(path, extension);
+       _image->location_path(location, path, JVM_MAXPATHLEN);
        ClassLoader::compile_the_world_in(path, loader, CHECK);
     }
   }
@@ -420,7 +635,7 @@
 }
 
 bool ClassPathImageEntry::is_jrt() {
-  return string_ends_with(name(), "bootmodules.jimage");
+  return string_ends_with(name(), BOOT_IMAGE_NAME);
 }
 #endif
 
@@ -491,7 +706,7 @@
     _shared_paths_misc_info->add_boot_classpath(sys_class_path);
   }
 #endif
-  setup_search_path(sys_class_path);
+  setup_search_path(sys_class_path, true);
 }
 
 #if INCLUDE_CDS
@@ -511,10 +726,11 @@
 }
 #endif
 
-void ClassLoader::setup_search_path(const char *class_path) {
+void ClassLoader::setup_search_path(const char *class_path, bool bootstrap_search) {
   int offset = 0;
   int len = (int)strlen(class_path);
   int end = 0;
+  bool mark_append_entry = false;
 
   // Iterate over class path entries
   for (int start = 0; start < len; start = end) {
@@ -523,10 +739,24 @@
     }
     EXCEPTION_MARK;
     ResourceMark rm(THREAD);
+    mark_append_entry = (mark_append_entry ||
+      (bootstrap_search && (start == Arguments::bootclassloader_append_index())));
+
     char* path = NEW_RESOURCE_ARRAY(char, end - start + 1);
     strncpy(path, &class_path[start], end - start);
     path[end - start] = '\0';
-    update_class_path_entry_list(path, false);
+    update_class_path_entry_list(path, false, mark_append_entry);
+
+    // Check on the state of the boot loader's append path
+    if (mark_append_entry && (_first_append_entry == NULL)) {
+      // Failure to mark the first append entry, most likely
+      // due to a non-existent path. Record the next entry
+      // as the first boot loader append entry.
+      mark_append_entry = true;
+    } else {
+      mark_append_entry = false;
+    }
+
 #if INCLUDE_CDS
     if (DumpSharedSpaces) {
       check_shared_classpath(path);
@@ -538,6 +768,23 @@
   }
 }
 
+static bool is_override_dir(const char *path) {
+  assert(string_ends_with(path, "java.base"), "must end in java.base");
+  if (Arguments::override_dir() != NULL) {
+    size_t path_len = strlen(path);
+    const char *override_path = Arguments::override_dir();
+    size_t override_len = strlen(override_path);
+
+    // Does path_len = override_len + strlen(/java.base)?
+    if(path_len == override_len + 1 + 9 &&
+      (path[override_len] ==  os::file_separator()[0]) &&
+      string_starts_with(path, override_path)) {
+      return true;
+    }
+  }
+  return false;
+}
+
 ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const struct stat* st,
                                                      bool lazy, bool throw_exception, TRAPS) {
   JavaThread* thread = JavaThread::current();
@@ -558,9 +805,9 @@
       }
     }
     // TODO - add proper criteria for selecting image file
-    ClassPathImageEntry* entry = new ClassPathImageEntry(canonical_path);
-    if (entry->is_open()) {
-      new_entry = entry;
+    ImageFileReader* image = ImageFileReader::open(canonical_path);
+    if (image) {
+      new_entry = new ClassPathImageEntry(image);
     } else {
     char* error_msg = NULL;
     jzfile* zip;
@@ -632,6 +879,18 @@
   return NULL;
 }
 
+// The boot class loader must adhere to specfic visibility rules.
+// Prior to loading a class in a named package, the package is checked
+// to see if it is in a module defined to the boot loader. If the
+// package is not in a module defined to the boot loader, the class
+// must be loaded only in the boot loader's append path, which
+// consists of [-Xbootclasspath/a]; [jvmti appended entries]
+void ClassLoader::set_first_append_entry(ClassPathEntry *new_entry) {
+  if (_first_append_entry == NULL) {
+    _first_append_entry = new_entry;
+  }
+}
+
 // returns true if entry already on class path
 bool ClassLoader::contains_entry(ClassPathEntry *entry) {
   ClassPathEntry* e = _first_entry;
@@ -657,25 +916,44 @@
   _num_entries ++;
 }
 
+void ClassLoader::add_to_list(const char *apath) {
+  update_class_path_entry_list((char*)apath, false, false);
+}
+
 // Returns true IFF the file/dir exists and the entry was successfully created.
 bool ClassLoader::update_class_path_entry_list(const char *path,
                                                bool check_for_duplicates,
+                                               bool mark_append_entry,
                                                bool throw_exception) {
   struct stat st;
   if (os::stat(path, &st) == 0) {
     // File or directory found
     ClassPathEntry* new_entry = NULL;
     Thread* THREAD = Thread::current();
-    new_entry = create_class_path_entry(path, &st, LazyBootClassLoader, throw_exception, CHECK_(false));
+
+    // If entry is the bootmodules.jimage then pass FALSE for 'lazy' to ensure
+    // that the jimage is opened.  This will enable process_javabase() to read it.
+    bool lazy = string_ends_with(path, BOOT_IMAGE_NAME) ? false : LazyBootClassLoader;
+
+    new_entry = create_class_path_entry(path, &st, lazy, throw_exception, CHECK_(false));
     if (new_entry == NULL) {
       return false;
     }
+
+    // Ensure that the first boot loader append entry will always be set correctly.
+    assert((!mark_append_entry ||
+            (mark_append_entry && (!check_for_duplicates || !contains_entry(new_entry)))),
+           "failed to mark boot loader's first append boundary");
+
     // The kernel VM adds dynamically to the end of the classloader path and
     // doesn't reorder the bootclasspath which would break java.lang.Package
     // (see PackageInfo).
     // Add new entry to linked list
     if (!check_for_duplicates || !contains_entry(new_entry)) {
       ClassLoaderExt::add_class_path_entry(path, check_for_duplicates, new_entry);
+      if (mark_append_entry) {
+        set_first_append_entry(new_entry);
+      }
     }
     return true;
   } else {
@@ -773,6 +1051,7 @@
 public:
   const char* _pkgname;       // Package name
   int _classpath_index;       // Index of directory or JAR file loaded from
+  Symbol* _module_location;   // Location of module containing the package
 
   PackageInfo* next() {
     return (PackageInfo*)BasicHashtableEntry<mtClass>::next();
@@ -785,9 +1064,14 @@
     return ClassLoader::classpath_entry(_classpath_index)->name();
   }
 
-  void set_index(int index) {
+  void set_location_and_index(Symbol* mod_loc, int index) {
+    _module_location = mod_loc;
+    if (_module_location != NULL)
+        _module_location->increment_refcount();
     _classpath_index = index;
   }
+
+  Symbol* module_location() { return _module_location; }
 };
 
 
@@ -899,12 +1183,20 @@
 }
 #endif
 
-PackageInfo* ClassLoader::lookup_package(const char *pkgname) {
-  const char *cp = strrchr(pkgname, '/');
-  if (cp != NULL) {
-    // Package prefix found
-    int n = cp - pkgname + 1;
-    return _package_hash_table->get_entry(pkgname, n);
+PackageInfo* ClassLoader::lookup_package(const char *pkgname, int len) {
+  return _package_hash_table->get_entry(pkgname, len);
+}
+
+// If a class's package is in a module defined by the boot loader then
+// return the module location, else return NULL.
+static Symbol* boot_module_location(const char* pkg_name, int len, TRAPS) {
+  PackageEntryTable* pkg_entry_tbl =
+    ClassLoaderData::the_null_class_loader_data()->packages();
+  TempNewSymbol pkg_symbol = SymbolTable::new_symbol(pkg_name, len, CHECK_NULL);
+  PackageEntry* pkg_entry = pkg_entry_tbl->lookup_only(pkg_symbol);
+
+  if (pkg_entry != NULL && !pkg_entry->in_unnamed_module()) {
+    return pkg_entry->module()->location();
   }
   return NULL;
 }
@@ -917,47 +1209,61 @@
   {
     MutexLocker ml(PackageTable_lock, THREAD);
     // First check for previously loaded entry
-    PackageInfo* pp = lookup_package(pkgname);
-    if (pp != NULL) {
-      // Existing entry found, check source of package
-      pp->set_index(classpath_index);
-      return true;
-    }
-
     const char *cp = strrchr(pkgname, '/');
     if (cp != NULL) {
       // Package prefix found
-      int n = cp - pkgname + 1;
+      int len = cp - pkgname + 1;
+      PackageInfo* pp = lookup_package(pkgname, len);
+      if (pp != NULL) {
+        // Existing entry found, check source of package (remove trailing '/')
+        Symbol* module_location = boot_module_location(pkgname, len - 1, CHECK_false);
+        pp->set_location_and_index(module_location, classpath_index);
+        return true;
+      }
 
-      char* new_pkgname = NEW_C_HEAP_ARRAY(char, n + 1, mtClass);
+      char* new_pkgname = NEW_C_HEAP_ARRAY(char, len + 1, mtClass);
       if (new_pkgname == NULL) {
         return false;
       }
 
-      memcpy(new_pkgname, pkgname, n);
-      new_pkgname[n] = '\0';
-      pp = _package_hash_table->new_entry(new_pkgname, n);
-      pp->set_index(classpath_index);
+      memcpy(new_pkgname, pkgname, len);
+      new_pkgname[len] = '\0';
+      pp = _package_hash_table->new_entry(new_pkgname, len);
+      Symbol* module_location = boot_module_location(new_pkgname, len - 1, CHECK_false);
+      pp->set_location_and_index(module_location, classpath_index);
 
       // Insert into hash table
       _package_hash_table->add_entry(pp);
     }
-    return true;
   }
+  return true;
 }
 
 
 oop ClassLoader::get_system_package(const char* name, TRAPS) {
-  PackageInfo* pp;
+  PackageInfo* pp = NULL;
   {
     MutexLocker ml(PackageTable_lock, THREAD);
-    pp = lookup_package(name);
+    const char *cp = strrchr(name, '/');
+    if (cp != NULL) {
+      pp = lookup_package(name, cp - name + 1);
+    }
   }
   if (pp == NULL) {
     return NULL;
   } else {
-    Handle p = java_lang_String::create_from_str(pp->filename(), THREAD);
-    return p();
+    // If the module_location field of the PackageInfo record is not null then
+    // return the module location.  Otherwise, use boot class path index.
+    Symbol* module_location = pp->module_location();
+    if (module_location != NULL) {
+      ResourceMark rm(THREAD);
+      Handle ml = java_lang_String::create_from_str(
+        module_location->as_C_string(), THREAD);
+      return ml();
+    } else {
+      Handle p = java_lang_String::create_from_str(pp->filename(), THREAD);
+      return p();
+    }
   }
 }
 
@@ -988,7 +1294,7 @@
 }
 
 
-instanceKlassHandle ClassLoader::load_classfile(Symbol* h_name, TRAPS) {
+instanceKlassHandle ClassLoader::load_classfile(Symbol* h_name, bool search_append_only, TRAPS) {
   ResourceMark rm(THREAD);
   const char* class_name = h_name->as_C_string();
   EventMark m("loading class %s", class_name);
@@ -1005,14 +1311,29 @@
   // Lookup stream for parsing .class file
   ClassFileStream* stream = NULL;
   int classpath_index = 0;
-  ClassPathEntry* e = NULL;
+  ClassPathEntry* e = (!search_append_only ? _first_entry : _first_append_entry);
+  ClassPathEntry* last_e = (!search_append_only ? _first_append_entry : NULL);
   instanceKlassHandle h;
   {
     PerfClassTraceTime vmtimer(perf_sys_class_lookup_time(),
                                ((JavaThread*) THREAD)->get_thread_stat()->perf_timers_addr(),
                                PerfClassTraceTime::CLASS_LOAD);
-    e = _first_entry;
-    while (e != NULL) {
+    if (search_append_only) {
+      // For the boot loader append path search, must calculate
+      // the starting classpath_index prior to attempting to
+      // load the classfile.
+      ClassPathEntry *tmp_e = _first_entry;
+      while ((tmp_e != NULL) && (tmp_e != _first_append_entry)) {
+        tmp_e = tmp_e->next();
+        ++classpath_index;
+      }
+    }
+
+    // Attempt to load the classfile from either:
+    //   - [-Xoverride:dir]; exploded build | bootmodules.jimage
+    //     or
+    //   - [-Xbootclasspath/a]; [jvmti appended entries]
+    while ((e != NULL) && (e != last_e)) {
       stream = e->open_stream(file_name, CHECK_NULL);
       if (!context.check(stream, classpath_index)) {
         return h; // NULL
@@ -1223,6 +1544,45 @@
   return true;
 }
 
+
+void ClassLoader::define_javabase() {
+  ClassPathEntry* e = _first_entry;
+  ClassPathEntry* last_e = _first_append_entry;
+
+  assert(!ModuleEntryTable::javabase_created() && !ClassLoader::has_bootmodules_jimage(),
+         "java.base has already been processed");
+
+  // When looking for the jimage file, only
+  // search the boot loader's module path which
+  // can consist of [-Xoverride]; exploded build | bootmodules.jimage
+  // Do not search the boot loader's append path.
+  while ((e != NULL) && (e != last_e)) {
+    ImageFileReader *image = e->image();
+    if (image != NULL && string_ends_with(e->name(), BOOT_IMAGE_NAME)) {
+      process_javabase((ClassPathImageEntry *)e);
+      set_has_bootmodules_jimage(true);
+      return;
+    }
+    e = e->next();
+  }
+
+  // If bootmodules.jimage has not been located,
+  // assume an exploded build.
+  e = _first_entry;
+  while ((e != NULL) && (e != last_e)) {
+    const char *path = e->name();
+    if (string_ends_with(path, "java.base") &&
+        !is_override_dir(path) &&
+        !e->is_jar_file()) {
+      process_javabase(path);
+      return;
+    }
+    e = e->next();
+  }
+
+  vm_exit_during_initialization("Unable to correctly define java.base from either the exploded build or bootmodules.jimage");
+}
+
 #ifndef PRODUCT
 
 void ClassLoader::verify() {
--- a/src/share/vm/classfile/classLoader.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/classLoader.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -32,9 +32,14 @@
 // The VM class loader.
 #include <sys/stat.h>
 
+// Name of boot module image
+#define  BOOT_IMAGE_NAME "bootmodules.jimage"
 
 // Class path entry (directory or zip file)
 
+class ImageFileReader;
+class ImageModuleData;
+
 class ClassPathEntry: public CHeapObj<mtClass> {
  private:
   ClassPathEntry* _next;
@@ -47,6 +52,8 @@
   }
   virtual bool is_jar_file() = 0;
   virtual const char* name() = 0;
+  virtual ImageFileReader* image() = 0;
+  virtual bool is_verified() = 0;
   virtual bool is_lazy();
   // Constructor
   ClassPathEntry();
@@ -63,8 +70,10 @@
  private:
   const char* _dir;           // Name of directory
  public:
-  bool is_jar_file()  { return false;  }
-  const char* name()  { return _dir; }
+  bool is_jar_file()       { return false;  }
+  const char* name()       { return _dir; }
+  ImageFileReader* image() { return NULL; }
+  bool is_verified()       { return false; }
   ClassPathDirEntry(const char* dir);
   ClassFileStream* open_stream(const char* name, TRAPS);
   // Debugging
@@ -92,8 +101,10 @@
   jzfile* _zip;              // The zip archive
   const char*   _zip_name;   // Name of zip archive
  public:
-  bool is_jar_file()  { return true;  }
-  const char* name()  { return _zip_name; }
+  bool is_jar_file()       { return true;  }
+  const char* name()       { return _zip_name; }
+  ImageFileReader* image() { return NULL; }
+  bool is_verified()       { return false; }
   ClassPathZipEntry(jzfile* zip, const char* zip_name);
   ~ClassPathZipEntry();
   u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
@@ -116,7 +127,9 @@
   ClassPathEntry* resolve_entry(TRAPS);
  public:
   bool is_jar_file();
-  const char* name()  { return _path; }
+  const char* name()       { return _path; }
+  ImageFileReader* image() { return NULL; }
+  bool is_verified()       { return false; }
   LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception);
   virtual ~LazyClassPathEntry();
   u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
@@ -129,15 +142,18 @@
 };
 
 // For java image files
-class ImageFile;
 class ClassPathImageEntry: public ClassPathEntry {
 private:
-  ImageFile *_image;
+  ImageFileReader* _image;
+  ImageModuleData* _module_data;
 public:
   bool is_jar_file()  { return false;  }
   bool is_open()  { return _image != NULL; }
   const char* name();
-  ClassPathImageEntry(char* name);
+  ImageFileReader* image() { return _image; }
+  bool is_verified();
+  ImageModuleData* module_data() { return _module_data; }
+  ClassPathImageEntry(ImageFileReader* image);
   ~ClassPathImageEntry();
   ClassFileStream* open_stream(const char* name, TRAPS);
 
@@ -194,16 +210,30 @@
   static PerfCounter* _isUnsyncloadClass;
   static PerfCounter* _load_instance_class_failCounter;
 
-  // First entry in linked list of ClassPathEntry instances
+  // First entry in linked list of ClassPathEntry instances.
+  // This consists of entries made up by:
+  //   - boot loader modules
+  //     [-Xoverride]; exploded build | bootmodules.jimage;
+  //   - boot loader append path
+  //     [-Xbootclasspath/a]; [jvmti appended entries]
   static ClassPathEntry* _first_entry;
   // Last entry in linked list of ClassPathEntry instances
   static ClassPathEntry* _last_entry;
   static int _num_entries;
 
+  // Pointer into the linked list of ClassPathEntry instances.
+  // Marks the start of:
+  //   - the boot loader's append path
+  //     [-Xbootclasspath/a]; [jvmti appended entries]
+  static ClassPathEntry* _first_append_entry;
+
   // Hash table used to keep track of loaded packages
   static PackageHashtable* _package_hash_table;
   static const char* _shared_archive;
 
+  // True if the boot path has a bootmodules.jimage
+  static bool _has_bootmodules_jimage;
+
   // Info used by CDS
   CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;)
 
@@ -211,14 +241,14 @@
   static unsigned int hash(const char *s, int n);
   // Returns the package file name corresponding to the specified package
   // or class name, or null if not found.
-  static PackageInfo* lookup_package(const char *pkgname);
+  static PackageInfo* lookup_package(const char *pkgname, int len);
   // Adds a new package entry for the specified class or package name and
   // corresponding directory or jar file name.
   static bool add_package(const char *pkgname, int classpath_index, TRAPS);
 
   // Initialization
   static void setup_bootstrap_search_path();
-  static void setup_search_path(const char *class_path);
+  static void setup_search_path(const char *class_path, bool setting_bootstrap);
 
   static void load_zip_library();
   static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st,
@@ -227,11 +257,13 @@
   // Canonicalizes path names, so strcmp will work properly. This is mainly
   // to avoid confusing the zip library
   static bool get_canonical_path(const char* orig, char* out, int len);
+
  public:
   static jboolean decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg);
   static int crc32(int crc, const char* buf, int len);
   static bool update_class_path_entry_list(const char *path,
                                            bool check_for_duplicates,
+                                           bool mark_append_entry,
                                            bool throw_exception=true);
   static void print_bootclasspath();
 
@@ -296,8 +328,19 @@
     return _load_instance_class_failCounter;
   }
 
+  // Sets _has_bootmodules_jimage to TRUE if bootmodules.jimage file exists.
+  static void set_has_bootmodules_jimage(bool val) {
+    _has_bootmodules_jimage = val;
+  }
+
+  static bool has_bootmodules_jimage() { return _has_bootmodules_jimage; }
+
+  // Read the packages for module java.base from the bootmodules.jimage
+  // file, if it exists. If it does not, assume exploded build.
+  static void define_javabase();
+
   // Load individual .class file
-  static instanceKlassHandle load_classfile(Symbol* h_name, TRAPS);
+  static instanceKlassHandle load_classfile(Symbol* h_name, bool search_append_only, TRAPS);
 
   // If the specified package has been loaded by the system, then returns
   // the name of the directory or ZIP file that the package was loaded from.
@@ -354,6 +397,8 @@
   static jlong class_link_count();
   static jlong class_link_time_ms();
 
+  static void set_first_append_entry(ClassPathEntry* entry);
+
   // indicates if class path already contains a entry (exact match by name)
   static bool contains_entry(ClassPathEntry* entry);
 
@@ -363,6 +408,9 @@
   // creates a class path zip entry (returns NULL if JAR file cannot be opened)
   static ClassPathZipEntry* create_class_path_zip_entry(const char *apath);
 
+  // add a path to class path list
+  static void add_to_list(const char* apath);
+
   // Debugging
   static void verify()              PRODUCT_RETURN;
 
--- a/src/share/vm/classfile/classLoaderData.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/classLoaderData.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -51,6 +51,8 @@
 #include "classfile/classLoaderData.inline.hpp"
 #include "classfile/javaClasses.hpp"
 #include "classfile/metadataOnStackMark.hpp"
+#include "classfile/moduleEntry.hpp"
+#include "classfile/packageEntry.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "code/codeCache.hpp"
 #include "memory/gcLocker.hpp"
@@ -81,6 +83,7 @@
   // The null-class-loader should always be kept alive.
   _keep_alive(is_anonymous || h_class_loader.is_null()),
   _metaspace(NULL), _unloading(false), _klasses(NULL),
+  _modules(NULL), _packages(NULL),
   _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL),
   _next(NULL), _dependencies(dependencies),
   _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true,
@@ -119,6 +122,9 @@
   if (klass_closure != NULL) {
     classes_do(klass_closure);
   }
+  if (_modules != NULL) {
+    _modules->oops_do(f);
+  }
 }
 
 void ClassLoaderData::Dependencies::oops_do(OopClosure* f) {
@@ -166,6 +172,30 @@
   }
 }
 
+void ClassLoaderData::modules_do(void f(ModuleEntry*)) {
+  if (_modules != NULL) {
+    for (int i = 0; i < _modules->table_size(); i++) {
+      for (ModuleEntry* entry = _modules->bucket(i);
+                              entry != NULL;
+                              entry = entry->next()) {
+        f(entry);
+      }
+    }
+  }
+}
+
+void ClassLoaderData::packages_do(void f(PackageEntry*)) {
+  if (_packages != NULL) {
+    for (int i = 0; i < _packages->table_size(); i++) {
+      for (PackageEntry* entry = _packages->bucket(i);
+                              entry != NULL;
+                              entry = entry->next()) {
+        f(entry);
+      }
+    }
+  }
+}
+
 void ClassLoaderData::record_dependency(Klass* k, TRAPS) {
   ClassLoaderData * const from_cld = this;
   ClassLoaderData * const to_cld = k->class_loader_data();
@@ -334,6 +364,32 @@
   }
 }
 
+PackageEntryTable* ClassLoaderData::packages() {
+  // Lazily create the package entry table at first request.
+  if (_packages == NULL) {
+    MutexLockerEx m1(metaspace_lock(), Mutex::_no_safepoint_check_flag);
+    // Check again if _packages has been allocated while we were getting this lock.
+    if (_packages != NULL) {
+      return _packages;
+    }
+    _packages = new PackageEntryTable(PackageEntryTable::_packagetable_entry_size);
+  }
+  return _packages;
+}
+
+ModuleEntryTable* ClassLoaderData::modules() {
+  // Lazily create the module entry table at first request.
+  if (_modules == NULL) {
+    MutexLockerEx m1(metaspace_lock(), Mutex::_no_safepoint_check_flag);
+    // Check again if _modules has been allocated while we were getting this lock.
+    if (_modules != NULL) {
+      return _modules;
+    }
+    _modules = new ModuleEntryTable(ModuleEntryTable::_moduletable_entry_size);
+  }
+  return _modules;
+}
+
 oop ClassLoaderData::keep_alive_object() const {
   assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
   return is_anonymous() ? _klasses->java_mirror() : class_loader();
@@ -351,6 +407,20 @@
   // Release C heap structures for all the classes.
   classes_do(InstanceKlass::release_C_heap_structures);
 
+  // Release C heap allocated hashtable for all the packages.
+  if (_packages != NULL) {
+    // Destroy the table itself
+    delete _packages;
+    _packages = NULL;
+  }
+
+  // Release C heap allocated hashtable for all the modules.
+  if (_modules != NULL) {
+    // Destroy the table itself
+    delete _modules;
+    _modules = NULL;
+  }
+
   Metaspace *m = _metaspace;
   if (m != NULL) {
     _metaspace = NULL;
@@ -679,6 +749,40 @@
   }
 }
 
+void ClassLoaderDataGraph::modules_do(void f(ModuleEntry*)) {
+  assert_locked_or_safepoint(Module_lock);
+  for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
+    cld->modules_do(f);
+  }
+}
+
+void ClassLoaderDataGraph::modules_unloading_do(void f(ModuleEntry*)) {
+  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
+  // Only walk the head until any clds not purged from prior unloading
+  // (CMS doesn't purge right away).
+  for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
+    assert(cld->is_unloading(), "invariant");
+    cld->modules_do(f);
+  }
+}
+
+void ClassLoaderDataGraph::packages_do(void f(PackageEntry*)) {
+  assert_locked_or_safepoint(Module_lock);
+  for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
+    cld->packages_do(f);
+  }
+}
+
+void ClassLoaderDataGraph::packages_unloading_do(void f(PackageEntry*)) {
+  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
+  // Only walk the head until any clds not purged from prior unloading
+  // (CMS doesn't purge right away).
+  for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
+    assert(cld->is_unloading(), "invariant");
+    cld->packages_do(f);
+  }
+}
+
 void ClassLoaderDataGraph::loaded_classes_do(KlassClosure* klass_closure) {
   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
     cld->loaded_classes_do(klass_closure);
@@ -690,6 +794,7 @@
   // Only walk the head until any clds not purged from prior unloading
   // (CMS doesn't purge right away).
   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
+    assert(cld->is_unloading(), "invariant");
     cld->classes_do(f);
   }
 }
@@ -766,6 +871,12 @@
   data = _head;
   while (data != NULL) {
     if (data->is_alive(is_alive_closure)) {
+      if (!data->packageTable_is_null()) {
+        data->packages()->purge_all_package_exports();
+      }
+      if (!data->moduleTable_is_null()) {
+        data->modules()->purge_all_module_reads();
+      }
       // clean metaspace
       if (walk_all_metadata) {
         data->classes_do(InstanceKlass::purge_previous_versions);
@@ -812,7 +923,7 @@
     classes_unloaded = true;
   }
   if (classes_unloaded) {
-    Metaspace::purge();
+  Metaspace::purge();
     set_metaspace_oom(false);
   }
 }
@@ -958,6 +1069,7 @@
 Ticks ClassLoaderDataGraph::_class_unload_time;
 
 void ClassLoaderDataGraph::class_unload_event(Klass* const k) {
+  assert(k != NULL, "invariant");
 
   // post class unload event
   EventClassUnload event(UNTIMED);
--- a/src/share/vm/classfile/classLoaderData.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/classLoaderData.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -53,6 +53,10 @@
 class JNIMethodBlock;
 class JNIHandleBlock;
 class Metadebug;
+class ModuleEntry;
+class PackageEntry;
+class ModuleEntryTable;
+class PackageEntryTable;
 
 // GC root for walking class loader data created
 
@@ -92,6 +96,10 @@
   static void classes_do(KlassClosure* klass_closure);
   static void classes_do(void f(Klass* const));
   static void methods_do(void f(Method*));
+  static void modules_do(void f(ModuleEntry*));
+  static void modules_unloading_do(void f(ModuleEntry*));
+  static void packages_do(void f(PackageEntry*));
+  static void packages_unloading_do(void f(PackageEntry*));
   static void loaded_classes_do(KlassClosure* klass_closure);
   static void classes_unloading_do(void f(Klass* const));
   static bool do_unloading(BoolObjectClosure* is_alive, bool clean_previous_versions);
@@ -171,9 +179,11 @@
   volatile int _claimed;   // true if claimed, for example during GC traces.
                            // To avoid applying oop closure more than once.
                            // Has to be an int because we cas it.
+  JNIHandleBlock* _handles; // Handles to constant pool arrays
+
   Klass* _klasses;         // The classes defined by the class loader.
-
-  JNIHandleBlock* _handles; // Handles to constant pool arrays
+  PackageEntryTable* _packages; // The packages defined by the class loader.
+  ModuleEntryTable* _modules;   // The modules defined by the class loader.
 
   // These method IDs are created for the class loader and set to NULL when the
   // class loader is unloaded.  They are rarely freed, only for redefine classes
@@ -214,6 +224,8 @@
   void loaded_classes_do(KlassClosure* klass_closure);
   void classes_do(void f(InstanceKlass*));
   void methods_do(void f(Method*));
+  void modules_do(void f(ModuleEntry*));
+  void packages_do(void f(PackageEntry*));
 
   // Deallocate free list during class unloading.
   void free_deallocate_list();
@@ -296,6 +308,10 @@
   bool contains_klass(Klass* k);
   void record_dependency(Klass* to, TRAPS);
   void init_dependencies(TRAPS);
+  PackageEntryTable* packages();
+  bool packageTable_is_null() { return (_packages == NULL); }
+  ModuleEntryTable* modules();
+  bool moduleTable_is_null() { return (_modules == NULL); }
 
   void add_to_deallocate_list(Metadata* m);
 
--- a/src/share/vm/classfile/classLoaderExt.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/classLoaderExt.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2015, 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
@@ -67,6 +67,13 @@
   }
   static void append_boot_classpath(ClassPathEntry* new_entry) {
     ClassLoader::add_to_list(new_entry);
+    // During jvmti live phase an entry can be appended to the boot
+    // loader's ClassPathEntry instances.  Need to mark the start
+    // of the boot loader's append path in case there was no reason
+    // to mark it initially in setup_bootstrap_search_path.
+    if (ClassLoader::_first_append_entry == NULL) {
+      ClassLoader::set_first_append_entry(new_entry);
+    }
   }
   static void setup_search_paths() {}
 };
--- a/src/share/vm/classfile/dictionary.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/dictionary.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -777,4 +777,3 @@
 
   _pd_cache_table->verify();
 }
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/classfile/imageDecompressor.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "classfile/imageDecompressor.hpp"
+#include "utilities/bytes.hpp"
+
+// Allocate in C Heap not in resource area, otherwise JVM crashes.
+GrowableArray<ImageDecompressor*>* ImageDecompressor::decompressors =
+        new(ResourceObj::C_HEAP, mtInternal) GrowableArray<ImageDecompressor*>(2, true);
+
+void ImageDecompressor::decompress_resource(u1* compressed, u1* uncompressed,
+        u4 uncompressed_size, const ImageStrings* strings, bool is_C_heap) {
+  bool has_header = false;
+  u1* decompressed_resource = compressed;
+  u1* compressed_resource = compressed;
+
+  // Resource could have been transformed by a stack of decompressors
+  do {
+    ResourceHeader _header;
+    memcpy(&_header, compressed_resource, sizeof(ResourceHeader));
+    has_header = _header._magic == RESOURCE_HEADER_MAGIC;
+    if (has_header) {
+      decompressed_resource = is_C_heap && _header._is_terminal ?
+          NEW_C_HEAP_ARRAY(u1, _header._uncompressed_size, mtClass) :
+          NEW_C_HEAP_ARRAY(u1, _header._uncompressed_size, mtOther);
+      const char* decompressor_name = strings->get(_header._decompressor_name_offset);
+      if (decompressor_name == NULL) warning("image decompressor not found\n");
+      guarantee(decompressor_name, "image decompressor not found");
+      ImageDecompressor* decompressor = get_decompressor(decompressor_name);
+      if (decompressor == NULL) warning("image decompressor %s not found\n",
+              decompressor_name);
+      guarantee(decompressor, "image decompressor not found");
+      u1* compressed_resource_base = compressed_resource;
+      compressed_resource += RESOURCE_HEADER_LENGTH;
+      decompressor->decompress_resource(compressed_resource, decompressed_resource,
+              &_header, strings);
+      if(compressed_resource_base != compressed) {
+        FREE_C_HEAP_ARRAY(char, compressed_resource_base);
+      }
+      compressed_resource = decompressed_resource;
+    }
+  }while(has_header);
+  memcpy(uncompressed, decompressed_resource, uncompressed_size);
+}
+
+// ZIP decompressor
+ZIPDecompressor* ZIPDecompressor::ZIP = new ZIPDecompressor();
+
+void ZIPDecompressor::decompress_resource(u1* data, u1* uncompressed,
+        ResourceHeader* header, const ImageStrings* strings) {
+  char* msg = NULL;
+  jboolean res = ClassLoader::decompress(data, header->_size, uncompressed,
+          header->_uncompressed_size, &msg);
+  if (!res) warning("decompression failed due to %s\n", msg);
+  guarantee(res, "decompression failed");
+}
+
+// END ZIP Decompressor
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/classfile/imageDecompressor.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ */
+
+#ifndef SHARE_VM_CLASSFILE_IMAGEDECOMPRESSOR_HPP
+#define SHARE_VM_CLASSFILE_IMAGEDECOMPRESSOR_HPP
+
+#include "classfile/classLoader.hpp"
+#include "classfile/imageFile.hpp"
+#include "utilities/growableArray.hpp"
+
+// Resource located in image can have an header
+struct ResourceHeader {
+  u4 _magic; // Resource header
+  u4 _size;  // Resource size
+  u4 _uncompressed_size;  // Expected uncompressed size
+  u4 _decompressor_name_offset;  // Strings table decompressor offset
+  u4 _decompressor_config_offset; // Strings table config offset
+  u1 _is_terminal; // Last decompressor 1, otherwise 0.
+};
+
+class ImageDecompressor: public CHeapObj<mtClass> {
+
+private:
+  const char* _name;
+  static const u1 RESOURCE_HEADER_LENGTH = 21;
+  static const u4 RESOURCE_HEADER_MAGIC = 0xCAFEFAFA;
+  static GrowableArray<ImageDecompressor*>* decompressors;
+
+  inline const char* get_name() const { return _name; }
+
+  inline static void add_decompressor(ImageDecompressor* decompressor) {
+     decompressors->append(decompressor);
+  }
+
+  inline static ImageDecompressor* get_decompressor(const char * decompressor_name) {
+    for (int i = 0; i < decompressors->length(); i++) {
+      ImageDecompressor* decompressor = decompressors->at(i);
+      if (strcmp(decompressor_name, decompressor->get_name()) == 0) {
+        return decompressor;
+      }
+    }
+    return NULL;
+  }
+
+public:
+  ImageDecompressor(const char* name) : _name(name) {
+      add_decompressor(this);
+  }
+  virtual void decompress_resource(u1* data, u1* uncompressed,
+    ResourceHeader* header, const ImageStrings* strings) {}
+  static void decompress_resource(u1* compressed, u1* uncompressed,
+    u4 uncompressed_size, const ImageStrings* strings, bool is_C_heap);
+};
+
+class ZIPDecompressor : public ImageDecompressor {
+private:
+  static ZIPDecompressor* ZIP;
+public:
+  ZIPDecompressor() : ImageDecompressor("zip") { }
+  void decompress_resource(u1* data, u1* uncompressed, ResourceHeader* header,
+    const ImageStrings* strings);
+};
+
+#endif // SHARE_VM_CLASSFILE_IMAGEDECOMPRESSOR_HPP
--- a/src/share/vm/classfile/imageFile.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/imageFile.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -23,13 +23,20 @@
  */
 
 #include "precompiled.hpp"
+#include "classfile/imageDecompressor.hpp"
 #include "classfile/imageFile.hpp"
+#include "runtime/mutex.hpp"
+#include "runtime/mutexLocker.hpp"
 #include "runtime/os.inline.hpp"
-#include "utilities/bytes.hpp"
+#include "utilities/endian.hpp"
+#include "utilities/growableArray.hpp"
 
+// Used to advance a pointer, unstructured.
+#undef NEXTPTR
+#define NEXTPTR(base, fromType, count, toType) (toType*)((fromType*)(base) + (count))
 
 // Compute the Perfect Hashing hash code for the supplied string.
-u4 ImageStrings::hash_code(const char* string, u4 seed) {
+s4 ImageStrings::hash_code(const char* string, s4 seed) {
   u1* bytes = (u1*)string;
 
   // Compute hash code.
@@ -41,8 +48,28 @@
   return seed & 0x7FFFFFFF;
 }
 
-// Test to see if string begins with start.  If so returns remaining portion
-// of string.  Otherwise, NULL.
+s4 ImageStrings::find(Endian* endian, const char* name, s4* redirect, u4 length) {
+  if (!redirect || !length) {
+    return NOT_FOUND;
+  }
+
+  s4 hash_code = ImageStrings::hash_code(name);
+  s4 index = hash_code % length;
+  s4 value = endian->get(redirect[index]);
+
+  if (value > 0 ) {
+    // Collision value, need to rehash.
+    hash_code = ImageStrings::hash_code(name, value);
+
+    return hash_code % length;
+  } else if (value < 0) {
+    // Direct access.
+    return -1 - value;
+  }
+
+  return NOT_FOUND;
+}
+
 const char* ImageStrings::starts_with(const char* string, const char* start) {
   char ch1, ch2;
 
@@ -68,32 +95,166 @@
   while ((byte = *data) != ATTRIBUTE_END) {
     u1 kind = attribute_kind(byte);
     u1 n = attribute_length(byte);
-    assert(kind < ATTRIBUTE_COUNT, "invalid image location attribute");
+    guarantee(kind < ATTRIBUTE_COUNT, "invalid image location attribute");
     _attributes[kind] = attribute_value(data + 1, n);
     data += n + 1;
   }
 }
 
-ImageFile::ImageFile(const char* name) {
+ImageModuleData::ImageModuleData(const ImageFileReader* image_file,
+        const char* module_data_name) :
+    _image_file(image_file),
+    _endian(image_file->endian()),
+    _strings(image_file->get_strings()) {
+  _image_file->get_resource(module_data_name, _data, _data_size, true);
+  guarantee(_data, "missing module data");
+
+  _header = NEXTPTR(_data, u1, 0, Header);
+  u4 ptm_count = _header->ptm_count(_endian);
+  u4 mtp_count = _header->mtp_count(_endian);
+
+  _ptm_redirect = NEXTPTR(_header, Header, 1, s4);
+  _ptm_data = NEXTPTR(_ptm_redirect, s4, ptm_count, PTMData);
+  _mtp_redirect = NEXTPTR(_ptm_data, PTMData, ptm_count, s4);
+  _mtp_data = NEXTPTR(_mtp_redirect, s4, mtp_count, MTPData);
+  _mtp_packages = NEXTPTR(_mtp_data, MTPData, mtp_count, s4);
+}
+
+ImageModuleData::~ImageModuleData() {
+  if (_data) {
+    FREE_C_HEAP_ARRAY(u1, _data);
+  }
+}
+
+void ImageModuleData::module_data_name(char* buffer, const char* image_file_name) {
+  const char* slash = strrchr(image_file_name, os::file_separator()[0]);
+  const char* name = slash ? slash + 1 : (char *)image_file_name;
+  const char* dot = strrchr(name, '.');
+  guarantee(dot, "missing extension on jimage name");
+  int length = dot - name;
+  strncpy(buffer, name, length);
+  buffer[length] = '\0';
+
+  strcat(buffer, ".jdata");
+}
+
+const char* ImageModuleData::package_to_module(const char* package_name) {
+  s4 index = ImageStrings::find(_endian, package_name, _ptm_redirect,
+                                  _header->ptm_count(_endian));
+
+  if (index != ImageStrings::NOT_FOUND) {
+    PTMData* data = _ptm_data + index;
+
+    if (strcmp(package_name, get_string(data->name_offset(_endian))) != 0) {
+      return NULL;
+    }
+
+    return get_string(data->module_name_offset(_endian));
+  }
+
+  return NULL;
+}
+
+GrowableArray<const char*>* ImageModuleData::module_to_packages(const char* module_name) {
+  s4 index = ImageStrings::find(_endian, module_name, _mtp_redirect,
+                                  _header->mtp_count(_endian));
+
+  if (index != ImageStrings::NOT_FOUND) {
+    MTPData* data = _mtp_data + index;
+
+    if (strcmp(module_name, get_string(data->name_offset(_endian))) != 0) {
+      return NULL;
+    }
+
+    GrowableArray<const char*>* packages = new GrowableArray<const char*>();
+    s4 package_offset = data->package_offset(_endian);
+    for (u4 i = 0; i < data->package_count(_endian); i++) {
+      u4 package_name_offset = mtp_package(package_offset + i);
+      const char* package_name = get_string(package_name_offset);
+      packages->append(package_name);
+    }
+
+    return packages;
+  }
+
+  return NULL;
+}
+
+GrowableArray<ImageFileReader*>* ImageFileReader::_reader_table =
+  new(ResourceObj::C_HEAP, mtInternal) GrowableArray<ImageFileReader*>(2, true);
+
+ImageFileReader* ImageFileReader::open(const char* name, bool big_endian) {
+  MutexLockerEx il(ImageFileReaderTable_lock,  Mutex::_no_safepoint_check_flag);
+  ImageFileReader* reader;
+
+  for (int i = 0; i < _reader_table->length(); i++) {
+    reader = _reader_table->at(i);
+
+    if (strcmp(reader->name(), name) == 0) {
+      reader->inc_use();
+      return reader;
+    }
+  }
+
+  reader = new ImageFileReader(name, big_endian);
+  bool opened = reader->open();
+
+  if (!opened) {
+    delete reader;
+    return NULL;
+  }
+
+  reader->inc_use();
+  _reader_table->append(reader);
+  return reader;
+}
+
+void ImageFileReader::close(ImageFileReader *reader) {
+  MutexLockerEx il(ImageFileReaderTable_lock,  Mutex::_no_safepoint_check_flag);
+
+  if (reader->dec_use()) {
+    _reader_table->remove(reader);
+    delete reader;
+  }
+}
+
+// Return an id for the specifed ImageFileReader.
+u8 ImageFileReader::readerToID(ImageFileReader *reader) {
+  return (u8)reader;
+}
+
+// Return an id for the specifed ImageFileReader.
+ImageFileReader* ImageFileReader::idToReader(u8 id) {
+  ImageFileReader* reader = (ImageFileReader*)id;
+#ifndef PRODUCT
+  MutexLockerEx il(ImageFileReaderTable_lock,  Mutex::_no_safepoint_check_flag);
+  guarantee(_reader_table->contains(reader), "bad image id");
+#endif
+  return reader;
+}
+
+ImageFileReader::ImageFileReader(const char* name, bool big_endian) {
   // Copy the image file name.
   _name = NEW_C_HEAP_ARRAY(char, strlen(name)+1, mtClass);
   strcpy(_name, name);
-
   // Initialize for a closed file.
   _fd = -1;
-  _memory_mapped = true;
+  _endian = Endian::get_handler(big_endian);
   _index_data = NULL;
 }
 
-ImageFile::~ImageFile() {
+ImageFileReader::~ImageFileReader() {
   // Ensure file is closed.
   close();
 
   // Free up name.
-  FREE_C_HEAP_ARRAY(char, _name);
+  if (_name) {
+    FREE_C_HEAP_ARRAY(char, _name);
+    _name = NULL;
+  }
 }
 
-bool ImageFile::open() {
+bool ImageFileReader::open() {
   // If file exists open for reading.
   struct stat st;
   if (os::stat(_name, &st) != 0 ||
@@ -103,60 +264,37 @@
   }
 
   // Read image file header and verify.
-  u8 header_size = sizeof(ImageHeader);
-  if (os::read(_fd, &_header, header_size) != header_size ||
-    _header._magic != IMAGE_MAGIC ||
-    _header._major_version != MAJOR_VERSION ||
-    _header._minor_version != MINOR_VERSION) {
+  size_t header_size = sizeof(ImageHeader);
+  if (!read_at((u1*)&_header, header_size, 0) ||
+    _header.magic(_endian) != IMAGE_MAGIC ||
+    _header.major_version(_endian) != MAJOR_VERSION ||
+    _header.minor_version(_endian) != MINOR_VERSION) {
     close();
+
     return false;
   }
 
   // Memory map index.
   _index_size = index_size();
-  _index_data = (u1*)os::map_memory(_fd, _name, 0, NULL, _index_size, true, false);
+  off_t map_size = (off_t)(MemoryMapImage ? st.st_size : _index_size);
+  _index_data = (u1*)os::map_memory(_fd, _name, 0, NULL, map_size, true, false);
+  guarantee(_index_data, "image file not memory mapped");
 
-  // Failing that, read index into C memory.
-  if (_index_data == NULL) {
-    _memory_mapped = false;
-    _index_data = NEW_RESOURCE_ARRAY(u1, _index_size);
-
-    if (os::seek_to_file_offset(_fd, 0) == -1) {
-      close();
-      return false;
-    }
-
-    if (os::read(_fd, _index_data, _index_size) != _index_size) {
-      close();
-      return false;
-    }
-
-    return true;
-  }
-
-// Used to advance a pointer, unstructured.
-#undef nextPtr
-#define nextPtr(base, fromType, count, toType) (toType*)((fromType*)(base) + (count))
   // Pull tables out from the index.
-  _redirect_table = nextPtr(_index_data, u1, header_size, s4);
-  _offsets_table = nextPtr(_redirect_table, s4, _header._location_count, u4);
-  _location_bytes = nextPtr(_offsets_table, u4, _header._location_count, u1);
-  _string_bytes = nextPtr(_location_bytes, u1, _header._locations_size, u1);
-#undef nextPtr
+  u4 length = table_length();
+  _redirect_table = NEXTPTR(_index_data, u1, header_size, s4);
+  _offsets_table = NEXTPTR(_redirect_table, s4, length, u4);
+  _location_bytes = NEXTPTR(_offsets_table, u4, length, u1);
+  _string_bytes = NEXTPTR(_location_bytes, u1, locations_size(), u1);
 
   // Successful open.
   return true;
 }
 
-void ImageFile::close() {
+void ImageFileReader::close() {
   // Dealllocate the index.
   if (_index_data) {
-    if (_memory_mapped) {
-      os::unmap_memory((char*)_index_data, _index_size);
-    } else {
-      FREE_RESOURCE_ARRAY(u1, _index_data, _index_size);
-    }
-
+    os::unmap_memory((char*)_index_data, _index_size);
     _index_data = NULL;
   }
 
@@ -165,122 +303,147 @@
     os::close(_fd);
     _fd = -1;
   }
-
 }
 
-// Return the attribute stream for a named resourced.
-u1* ImageFile::find_location_data(const char* path) const {
-  // Compute hash.
-  u4 hash = ImageStrings::hash_code(path) % _header._location_count;
-  s4 redirect = _redirect_table[hash];
+// Read directly from the file.
+bool ImageFileReader::read_at(u1* data, u8 size, u8 offset) const {
+  u8 read = os::read_at(_fd, data, size, offset);
 
-  if (!redirect) {
+  return read == size;
+}
+
+// Return the attribute stream for a named resource.
+u1* ImageFileReader::find_location_data(const char* path) const {
+  s4 index = ImageStrings::find(_endian, path, _redirect_table, table_length());
+
+  if (index == ImageStrings::NOT_FOUND) {
     return NULL;
   }
 
-  u4 index;
+  return get_location_data(index);
+}
 
-  if (redirect < 0) {
-    // If no collision.
-    index = -redirect - 1;
-  } else {
-    // If collision, recompute hash code.
-    index = ImageStrings::hash_code(path, redirect) % _header._location_count;
+void ImageFileReader::location_path(ImageLocation& location, char* path, size_t max) const {
+  ImageStrings strings(_string_bytes, _header.strings_size(_endian));
+  char* next = path;
+  size_t length;
+
+  const char* module = location.get_attribute(ImageLocation::ATTRIBUTE_MODULE, strings);
+  if (*module != '\0') {
+    length = strlen(module);
+    guarantee(next - path + length + 2 < max, "buffer overflow");
+    *next++ = '/';
+    strcpy(next, module); next += length;
+    *next++ = '/';
   }
 
-  assert(index < _header._location_count, "index exceeds location count");
-  u4 offset = _offsets_table[index];
-  assert(offset < _header._locations_size, "offset exceeds location attributes size");
-
-  if (offset == 0) {
-    return NULL;
+  const char* parent = location.get_attribute(ImageLocation::ATTRIBUTE_PARENT, strings);
+  if (*parent != '\0') {
+    length = strlen(parent);
+    guarantee(next - path + length + 1 < max, "buffer overflow");
+    strcpy(next, parent); next += length;
+    *next++ = '/';
   }
 
-  return _location_bytes + offset;
+  const char* base = location.get_attribute(ImageLocation::ATTRIBUTE_BASE, strings);
+  length = strlen(base);
+  guarantee(next - path + length < max, "buffer overflow");
+  strcpy(next, base); next += length;
+
+  const char* extension = location.get_attribute(ImageLocation::ATTRIBUTE_EXTENSION, strings);
+  if (*extension != '\0') {
+    length = strlen(extension);
+    guarantee(next - path + length + 1 < max, "buffer overflow");
+    *next++ = '.';
+    strcpy(next, extension); next += length;
+  }
+
+  guarantee((size_t)(next - path) < max, "buffer overflow");
+  *next = '\0';
 }
 
 // Verify that a found location matches the supplied path.
-bool ImageFile::verify_location(ImageLocation& location, const char* path) const {
-  // Retrieve each path component string.
-  ImageStrings strings(_string_bytes, _header._strings_size);
-  // Match a path with each subcomponent without concatenation (copy).
-  // Match up path parent.
+bool ImageFileReader::verify_location(ImageLocation& location, const char* path) const {
+  ImageStrings strings(_string_bytes, _header.strings_size(_endian));
+  const char* next = path;
+
+  const char* module = location.get_attribute(ImageLocation::ATTRIBUTE_MODULE, strings);
+  if (*module != '\0') {
+    if (*next++ != '/') return false;
+    if (!(next = ImageStrings::starts_with(next, module))) return false;
+    if (*next++ != '/') return false;
+  }
+
   const char* parent = location.get_attribute(ImageLocation::ATTRIBUTE_PARENT, strings);
-  const char* next = ImageStrings::starts_with(path, parent);
-  // Continue only if a complete match.
-  if (!next) return false;
-  // Match up path base.
+  if (*parent != '\0') {
+    if (!(next = ImageStrings::starts_with(next, parent))) return false;
+    if (*next++ != '/') return false;
+  }
+
   const char* base = location.get_attribute(ImageLocation::ATTRIBUTE_BASE, strings);
-  next = ImageStrings::starts_with(next, base);
-  // Continue only if a complete match.
-  if (!next) return false;
-  // Match up path extension.
+  if (!(next = ImageStrings::starts_with(next, base))) return false;
+
   const char* extension = location.get_attribute(ImageLocation::ATTRIBUTE_EXTENSION, strings);
-  next = ImageStrings::starts_with(next, extension);
+  if (*extension != '\0') {
+    if (*next++ != '.') return false;
+    if (!(next = ImageStrings::starts_with(next, extension))) return false;
+  }
 
   // True only if complete match and no more characters.
-  return next && *next == '\0';
+  return *next == '\0';
 }
 
 // Return the resource for the supplied location.
-u1* ImageFile::get_resource(ImageLocation& location) const {
+u1* ImageFileReader::get_resource(ImageLocation& location, bool is_C_heap) const {
   // Retrieve the byte offset and size of the resource.
-  u8 offset = _index_size + location.get_attribute(ImageLocation::ATTRIBUTE_OFFSET);
-  u8 size = location.get_attribute(ImageLocation::ATTRIBUTE_UNCOMPRESSED);
+  u8 offset = location.get_attribute(ImageLocation::ATTRIBUTE_OFFSET);
+  u8 uncompressed_size = location.get_attribute(ImageLocation::ATTRIBUTE_UNCOMPRESSED);
   u8 compressed_size = location.get_attribute(ImageLocation::ATTRIBUTE_COMPRESSED);
-  u8 read_size = compressed_size ? compressed_size : size;
 
-  // Allocate space for the resource.
-  u1* data = NEW_RESOURCE_ARRAY(u1, read_size);
+  if (compressed_size) {
+    u1* compressed_data = MemoryMapImage ? get_data_address() + offset
+                                         : NEW_RESOURCE_ARRAY(u1, compressed_size);
+    if (!MemoryMapImage) {
+      bool is_read = read_at(compressed_data, compressed_size, _index_size + offset);
+      guarantee(is_read, "error reading from image or short read");
+    }
 
-  bool is_read = os::read_at(_fd, data, read_size, offset) == read_size;
-  guarantee(is_read, "error reading from image or short read");
+    u1* uncompressed_data = is_C_heap ? NEW_C_HEAP_ARRAY(u1, uncompressed_size, mtClass)
+                                      : NEW_RESOURCE_ARRAY(u1, uncompressed_size);
+    const ImageStrings strings = get_strings();
+    ImageDecompressor::decompress_resource(compressed_data, uncompressed_data, uncompressed_size,
+            &strings, is_C_heap);
+    if (!MemoryMapImage) {
+        FREE_RESOURCE_ARRAY(u1, compressed_data, compressed_size);
+    }
+    return uncompressed_data;
+  } else {
+    if (MemoryMapImage && !is_C_heap) {
+      return get_data_address() + offset;
+    }
 
-  // If not compressed, just return the data.
-  if (!compressed_size) {
-    return data;
+    u1* uncompressed_data = is_C_heap ? NEW_C_HEAP_ARRAY(u1, uncompressed_size, mtClass)
+                                      : NEW_RESOURCE_ARRAY(u1, uncompressed_size);
+    bool is_read = read_at(uncompressed_data, uncompressed_size, _index_size + offset);
+    guarantee(is_read, "error reading from image or short read");
+
+    return uncompressed_data;
   }
-
-  u1* uncompressed = NEW_RESOURCE_ARRAY(u1, size);
-  char* msg = NULL;
-  jboolean res = ClassLoader::decompress(data, compressed_size, uncompressed, size, &msg);
-  if (!res) warning("decompression failed due to %s\n", msg);
-  guarantee(res, "decompression failed");
-
-  return uncompressed;
 }
 
-void ImageFile::get_resource(const char* path, u1*& buffer, u8& size) const {
+void ImageFileReader::get_resource(const char* path, u1*& buffer, u8& size, bool is_C_heap) const {
   buffer = NULL;
   size = 0;
   u1* data = find_location_data(path);
   if (data) {
     ImageLocation location(data);
+
     if (verify_location(location, path)) {
       size = location.get_attribute(ImageLocation::ATTRIBUTE_UNCOMPRESSED);
-      buffer = get_resource(location);
+      buffer = get_resource(location, is_C_heap);
     }
   }
 }
 
-GrowableArray<const char*>* ImageFile::packages(const char* name) {
-  char entry[JVM_MAXPATHLEN];
-  bool overflow = jio_snprintf(entry, sizeof(entry), "%s/packages.offsets", name) == -1;
-  guarantee(!overflow, "package name overflow");
 
-  u1* buffer;
-  u8 size;
 
-  get_resource(entry, buffer, size);
-  guarantee(buffer, "missing module packages reource");
-  ImageStrings strings(_string_bytes, _header._strings_size);
-  GrowableArray<const char*>* pkgs = new GrowableArray<const char*>();
-  int count = size / 4;
-  for (int i = 0; i < count; i++) {
-    u4 offset = Bytes::get_Java_u4(buffer + (i*4));
-    const char* p = strings.get(offset);
-    pkgs->append(p);
-  }
-
-  return pkgs;
-}
--- a/src/share/vm/classfile/imageFile.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/imageFile.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -28,13 +28,15 @@
 #include "classfile/classLoader.hpp"
 #include "memory/allocation.hpp"
 #include "memory/allocation.inline.hpp"
+#include "utilities/endian.hpp"
 #include "utilities/globalDefinitions.hpp"
+#include "utilities/growableArray.hpp"
 
 // Image files are an alternate file format for storing classes and resources. The
 // goal is to supply file access which is faster and smaller that the jar format.
-// It should be noted that unlike jars information stored in an image is in native
-// endian format. This allows the image to be memory mapped into memory without
-// endian translation.  This also means that images are platform dependent.
+// It should be noted that unlike jars, information stored in an image is in native
+// endian format. This allows the image to be mapped into memory without endian
+// translation.  This also means that images are platform dependent.
 //
 // Image files are structured as three sections;
 //
@@ -42,7 +44,7 @@
 //         |  Header   |
 //         +-----------+
 //         |           |
-//         | Directory |
+//         |   Index   |
 //         |           |
 //         +-----------+
 //         |           |
@@ -60,7 +62,11 @@
 //         +------------+------------+
 //         | Major Vers | Minor Vers |
 //         +------------+------------+
-//         |      Location Count     |
+//         |          Flags          |
+//         +-------------------------+
+//         |      Resource Count     |
+//         +-------------------------+
+//         |       Table Length      |
 //         +-------------------------+
 //         |      Attributes Size    |
 //         +-------------------------+
@@ -71,23 +77,24 @@
 //         special file extension.
 // Major vers, minor vers - differences in version numbers indicate structural
 //                          changes in the image.
-// Location count - number of locations/resources in the file.  This count is also
-//                  the length of lookup tables used in the directory.
+// Flags - various image wide flags.
+// Resource count - number of resources in the file.
+// Table length - the length of lookup tables used in the index.
 // Attributes size - number of bytes in the region used to store location attribute
 //                   streams.
 // Strings size - the size of the region used to store strings used by the
-//                directory and meta data.
+//                index and meta data.
 //
-// The directory contains information related to resource lookup. The algorithm
+// The index contains information related to resource lookup. The algorithm
 // used for lookup is "A Practical Minimal Perfect Hashing Method"
 // (http://homepages.dcc.ufmg.br/~nivio/papers/wea05.pdf). Given a path string
-// in the form <package>/<base>.<extension>  return the resource location
+// in the form /<module>/<package>/<base>.<extension>  return the resource location
 // information;
 //
-//     redirectIndex = hash(path, DEFAULT_SEED) % count;
+//     redirectIndex = hash(path, DEFAULT_SEED) % table_length;
 //     redirect = redirectTable[redirectIndex];
 //     if (redirect == 0) return not found;
-//     locationIndex = redirect < 0 ? -1 - redirect : hash(path, redirect) % count;
+//     locationIndex = redirect < 0 ? -1 - redirect : hash(path, redirect) % table_length;
 //     location = locationTable[locationIndex];
 //     if (!verify(location, path)) return not found;
 //     return location;
@@ -97,7 +104,7 @@
 // other seeds. The verify function guarantees the found resource location is
 // indeed the resource we are looking for.
 //
-// The following is the format of the directory;
+// The following is the format of the index;
 //
 //         +-------------------+
 //         |   Redirect Table  |
@@ -117,35 +124,44 @@
 //                  offsets.  Zero indicates not found.
 // Attribute Offsets - Array of 32-bit unsigned values representing offsets into
 //                     attribute data.  Attribute offsets can be iterated to do a
-//                     full survey of resources in the image.
+//                     full survey of resources in the image.  Offset of zero
+//                     indicates no attributes.
 // Attribute Data - Bytes representing compact attribute data for locations. (See
 //                  comments in ImageLocation.)
-// Strings - Collection of zero terminated UTF-8 strings used by the directory and
+// Strings - Collection of zero terminated UTF-8 strings used by the index and
 //           image meta data.  Each string is accessed by offset.  Each string is
 //           unique.  Offset zero is reserved for the empty string.
 //
-// Note that the memory mapped directory assumes 32 bit alignment of the image
-// header, the redirect table and the attribute offsets.
+// Note that the memory mapped index assumes 32 bit alignment of each component
+// in the index.
+//
+// Endianness of an image.
+// An image booted by hotspot is always in native endian.  However, it is possible
+// to read (by the JDK) in alternate endian format.  Primarily, this is during
+// cross platform scenarios.  Ex, where javac needs to read an embedded image
+// to access classes for crossing compilation.
 //
 
+// Prime used to generate hash for Perfect Hashing.
+static const u4 HASH_MULTIPLIER = 0x01000193;
+
+class ImageFileReader; // forward declaration
 
 // Manage image file string table.
 class ImageStrings {
 private:
-  // Data bytes for strings.
-  u1* _data;
-  // Number of bytes in the string table.
-  u4 _size;
+  u1* _data; // Data bytes for strings.
+  u4 _size; // Number of bytes in the string table.
 
 public:
-  // Prime used to generate hash for Perfect Hashing.
-  static const u4 HASH_MULTIPLIER = 0x01000193;
+  // Not found result from find routine.
+  static const s4 NOT_FOUND = -1;
 
   ImageStrings(u1* data, u4 size) : _data(data), _size(size) {}
 
   // Return the UTF-8 string beginning at offset.
   inline const char* get(u4 offset) const {
-    assert(offset < _size, "offset exceeds string table size");
+    guarantee(offset < _size, "offset exceeds string table size");
     return (const char*)(_data + offset);
   }
 
@@ -155,16 +171,26 @@
   }
 
   // Compute the Perfect Hashing hash code for the supplied string, starting at seed.
-  static u4 hash_code(const char* string, u4 seed);
+  static s4 hash_code(const char* string, s4 seed);
+
+  // Match up a string in the perfect hash table.  Still needs validation
+  // for exact match.
+  static s4 find(Endian* endian, const char* name, s4* redirect, u4 length);
 
   // Test to see if string begins with start.  If so returns remaining portion
   // of string.  Otherwise, NULL.  Used to test sections of a path without
   // copying.
   static const char* starts_with(const char* string, const char* start);
 
+  // Test to see if string begins with start char.  If so returns remaining portion
+  // of string.  Otherwise, NULL.  Used to test sections of a path without
+  // copying.
+  inline static const char* starts_with(const char* string, const char ch) {
+    return *string == ch ? string + 1 : NULL;
+  }
 };
 
-// Manage image file location attribute streams.  Within an image, a location's
+// Manage image file location attribute data.  Within an image, a location's
 // attributes are compressed into a stream of bytes.  An attribute stream is
 // composed of individual attribute sequences.  Each attribute sequence begins with
 // a header byte containing the attribute 'kind' (upper 5 bits of header) and the
@@ -188,7 +214,7 @@
 //    stream.
 //  - ATTRIBUTE_OFFSET represents the number of bytes from the beginning of the region
 //    storing the resources.  Thus, in an image this represents the number of bytes
-//    after the directory.
+//    after the index.
 //  - Currently, compressed resources are represented by having a non-zero
 //    ATTRIBUTE_COMPRESSED value.  This represents the number of bytes stored in the
 //    image, and the value of ATTRIBUTE_UNCOMPRESSED represents number of bytes of the
@@ -200,15 +226,17 @@
 //
 class ImageLocation {
 public:
-  // Attribute kind enumeration.
-  static const u1 ATTRIBUTE_END = 0; // End of attribute stream marker
-  static const u1 ATTRIBUTE_BASE = 1; // String table offset of resource path base
-  static const u1 ATTRIBUTE_PARENT = 2; // String table offset of resource path parent
-  static const u1 ATTRIBUTE_EXTENSION = 3; // String table offset of resource path extension
-  static const u1 ATTRIBUTE_OFFSET = 4; // Container byte offset of resource
-  static const u1 ATTRIBUTE_COMPRESSED = 5; // In image byte size of the compressed resource
-  static const u1 ATTRIBUTE_UNCOMPRESSED = 6; // In memory byte size of the uncompressed resource
-  static const u1 ATTRIBUTE_COUNT = 7; // Number of attribute kinds
+  enum {
+    ATTRIBUTE_END,          // End of attribute stream marker
+    ATTRIBUTE_MODULE,       // String table offset of module name
+    ATTRIBUTE_PARENT,       // String table offset of resource path parent
+    ATTRIBUTE_BASE,         // String table offset of resource path base
+    ATTRIBUTE_EXTENSION,    // String table offset of resource path extension
+    ATTRIBUTE_OFFSET,       // Container byte offset of resource
+    ATTRIBUTE_COMPRESSED,   // In image byte size of the compressed resource
+    ATTRIBUTE_UNCOMPRESSED, // In memory byte size of the uncompressed resource
+    ATTRIBUTE_COUNT         // Number of attribute kinds
+  };
 
 private:
   // Values of inflated attributes.
@@ -222,13 +250,13 @@
   // Return the attribute kind.
   inline static u1 attribute_kind(u1 data) {
     u1 kind = data >> 3;
-    assert(kind < ATTRIBUTE_COUNT, "invalid attribute kind");
+    guarantee(kind < ATTRIBUTE_COUNT, "invalid attribute kind");
     return kind;
   }
 
   // Return the attribute length.
   inline static u8 attribute_value(u1* data, u1 n) {
-    assert(0 < n && n <= 8, "invalid attribute value length");
+    guarantee(0 < n && n <= 8, "invalid attribute value length");
     u8 value = 0;
 
     // Most significant bytes first.
@@ -245,7 +273,7 @@
 
   // Retrieve an attribute value from the inflated array.
   inline u8 get_attribute(u1 kind) const {
-    assert(ATTRIBUTE_END < kind && kind < ATTRIBUTE_COUNT, "invalid attribute kind");
+    guarantee(ATTRIBUTE_END < kind && kind < ATTRIBUTE_COUNT, "invalid attribute kind");
     return _attributes[kind];
   }
 
@@ -255,89 +283,301 @@
   }
 };
 
-// Manage the image file.
-class ImageFile: public CHeapObj<mtClass> {
-private:
-  // Image file marker.
-  static const u4 IMAGE_MAGIC = 0xCAFEDADA;
-  // Image file major version number.
-  static const u2 MAJOR_VERSION = 0;
-  // Image file minor version number.
-  static const u2 MINOR_VERSION = 1;
+//
+// NOTE: needs revision.
+// Each loader requires set of module meta data to identify which modules and
+// packages are managed by that loader.  Currently, there is one image file per
+// loader, so only one  module meta data resource per file.
+//
+// Each element in the module meta data is a native endian 4 byte integer.  Note
+// that entries with zero offsets for string table entries should be ignored (
+// padding for hash table lookup.)
+//
+// Format:
+//    Count of package to module entries
+//    Count of module to package entries
+//    Perfect Hash redirect table[Count of package to module entries]
+//    Package to module entries[Count of package to module entries]
+//        Offset to package name in string table
+//        Offset to module name in string table
+//    Perfect Hash redirect table[Count of module to package entries]
+//    Module to package entries[Count of module to package entries]
+//        Offset to module name in string table
+//        Count of packages in module
+//        Offset to first package in packages table
+//    Packages[]
+//        Offset to package name in string table
+//
+// Manage the image module meta data.
+class ImageModuleData : public CHeapObj<mtClass> {
+  class Header {
+  private:
+    u4 _ptm_count;      // Count of package to module entries
+    u4 _mtp_count;      // Count of module to package entries
 
-  struct ImageHeader {
-    u4 _magic;          // Image file marker
-    u2 _major_version;  // Image file major version number
-    u2 _minor_version;  // Image file minor version number
-    u4 _location_count; // Number of locations managed in index.
-    u4 _locations_size; // Number of bytes in attribute table.
-    u4 _strings_size;   // Number of bytes in string table.
+  public:
+    inline u4 ptm_count(Endian* endian) const { return endian->get(_ptm_count); }
+    inline u4 mtp_count(Endian* endian) const { return endian->get(_mtp_count); }
   };
 
-  char* _name;          // Name of image
-  int _fd;              // File descriptor
-  bool _memory_mapped;  // Is file memory mapped
-  ImageHeader _header;  // Image header
-  u8 _index_size;       // Total size of index
-  u1* _index_data;      // Raw index data
-  s4* _redirect_table;  // Perfect hash redirect table
-  u4* _offsets_table;   // Location offset table
-  u1* _location_bytes;  // Location attributes
-  u1* _string_bytes;    // String table
+  // Hashtable entry
+  class HashData {
+  private:
+    u4 _name_offset;    // Name offset in string table
+  public:
+    inline s4 name_offset(Endian* endian) const { return endian->get(_name_offset); }
+  };
+
+  // Package to module hashtable entry
+  class PTMData : public HashData {
+  private:
+    u4 _module_name_offset; // Module name offset in string table
+  public:
+    inline s4 module_name_offset(Endian* endian) const { return endian->get(_module_name_offset); }
+  };
+
+  // Module to package hashtable entry
+  class MTPData : public HashData {
+  private:
+    u4 _package_count;     // Number of packages in module
+    u4 _package_offset;    // Offset in package list
+  public:
+    inline u4 package_count(Endian* endian)  const { return endian->get(_package_count); }
+    inline u4 package_offset(Endian* endian) const { return endian->get(_package_offset); }
+  };
+
+  const ImageFileReader* _image_file; // Source image file
+  Endian* _endian;                    // Endian handler
+  ImageStrings _strings;              // Image file strings
+  u1* _data;                          // Module data resource data
+  u8 _data_size;                      // Size of resource data
+  Header* _header;                    // Module data header
+  s4* _ptm_redirect;                  // Package to module hashtable redirect
+  PTMData* _ptm_data;                 // Package to module data
+  s4* _mtp_redirect;                  // Module to packages hashtable redirect
+  MTPData* _mtp_data;                 // Module to packages data
+  s4* _mtp_packages;                  // Package data (name offsets)
+
+  // Return a string from the string table.
+  inline const char* get_string(u4 offset) {
+    return _strings.get(offset);
+  }
+
+  inline u4 mtp_package(u4 index) {
+    return _endian->get(_mtp_packages[index]);
+  }
+
+public:
+  ImageModuleData(const ImageFileReader* image_file, const char* module_data_name);
+  ~ImageModuleData();
+
+  // Return the name of tthe module data resource.
+  static void module_data_name(char* buffer, const char* image_file_name);
+
+  // Return the module name a package resides.  Returns NULL if not found.
+  const char* package_to_module(const char* package_name);
+
+  // Returns all the package names in a module.  Returns NULL if not found.
+  GrowableArray<const char*>* module_to_packages(const char* module_name);
+};
+
+// Image file marker.
+static const u4 IMAGE_MAGIC = 0xCAFEDADA;
+// Endian inverted Image file marker.
+static const u4 IMAGE_MAGIC_INVERT = 0xDADAFECA;
+// Image file major version number.
+static const u4 MAJOR_VERSION = 1;
+// Image file minor version number.
+static const u4 MINOR_VERSION = 0;
+
+// Image file header, starting at offset 0.
+class ImageHeader {
+private:
+  u4 _magic;           // Image file marker
+  u4 _version;         // Image file major version number
+  u4 _flags;           // Image file flags
+  u4 _resource_count;  // Number of resources in file
+  u4 _table_length;    // Number of slots in index tables
+  u4 _locations_size;  // Number of bytes in attribute table
+  u4 _strings_size;    // Number of bytes in string table
+
+public:
+  u4 magic() const { return _magic; }
+  u4 magic(Endian* endian) const { return endian->get(_magic); }
+  void set_magic(Endian* endian, u4 magic) { return endian->set(_magic, magic); }
+
+  u4 major_version(Endian* endian) const { return endian->get(_version) >> 16; }
+  u4 minor_version(Endian* endian) const { return endian->get(_version) & 0xFFFF; }
+  void set_version(Endian* endian, u4 major_version, u4 minor_version) {
+    return endian->set(_version, major_version << 16 | minor_version);
+  }
+
+  u4 flags(Endian* endian) const { return endian->get(_flags); }
+  void set_flags(Endian* endian, u4 value) { return endian->set(_flags, value); }
+
+  u4 resource_count(Endian* endian) const { return endian->get(_resource_count); }
+  void set_resource_count(Endian* endian, u4 count) { return endian->set(_resource_count, count); }
+
+  u4 table_length(Endian* endian) const { return endian->get(_table_length); }
+  void set_table_length(Endian* endian, u4 count) { return endian->set(_table_length, count); }
+
+  u4 locations_size(Endian* endian) const { return endian->get(_locations_size); }
+  void set_locations_size(Endian* endian, u4 size) { return endian->set(_locations_size, size); }
+
+  u4 strings_size(Endian* endian) const { return endian->get(_strings_size); }
+  void set_strings_size(Endian* endian, u4 size) { return endian->set(_strings_size, size); }
+};
+
+// Manage the image file.
+// ImageFileReader manages the content of an image file.
+// Initially, the header of the image file is read for validation.  If valid,
+// values in the header are used calculate the size of the image index.  The
+// index is then memory mapped to allow load on demand and sharing.  The
+// -XX:+MemoryMapImage flag determines if the entire file is loaded (server use.)
+// An image can be used by Hotspot and multiple reference points in the JDK, thus
+// it is desirable to share a reader.  To accomodate sharing, a share table is
+// defined (see ImageFileReaderTable in imageFile.cpp)  To track the number of
+// uses, ImageFileReader keeps a use count (_use).  Use is incremented when
+// 'opened' by reference point and decremented when 'closed'.  Use of zero
+// leads the ImageFileReader to be actually closed and discarded.
+class ImageFileReader : public CHeapObj<mtClass> {
+private:
+  // Manage a number of image files such that an image can be shared across
+  // multiple uses (ex. loader.)
+  static GrowableArray<ImageFileReader*>* _reader_table;
+
+  char* _name;         // Name of image
+  s4 _use;             // Use count
+  int _fd;             // File descriptor
+  Endian* _endian;     // Endian handler
+  ImageHeader _header; // Image header
+  size_t _index_size;  // Total size of index
+  u1* _index_data;     // Raw index data
+  s4* _redirect_table; // Perfect hash redirect table
+  u4* _offsets_table;  // Location offset table
+  u1* _location_bytes; // Location attributes
+  u1* _string_bytes;   // String table
+
+  ImageFileReader(const char* name, bool big_endian);
+  ~ImageFileReader();
 
   // Compute number of bytes in image file index.
   inline u8 index_size() {
     return sizeof(ImageHeader) +
-    _header._location_count * sizeof(u4) * 2 +
-    _header._locations_size +
-    _header._strings_size;
+      table_length() * sizeof(u4) * 2 + locations_size() + strings_size();
   }
 
 public:
-  ImageFile(const char* name);
-  ~ImageFile();
+  enum {
+    IMAGE_VERIFIED = 1 // Indicates that the image file has been verified
+  };
+
+  // Open an image file, reuse structure if file already open.
+  static ImageFileReader* open(const char* name, bool big_endian = Endian::is_big_endian());
+
+  // Close an image file if the file is not in use elsewhere.
+  static void close(ImageFileReader *reader);
+
+  // Return an id for the specifed ImageFileReader.
+  static u8 readerToID(ImageFileReader *reader);
+
+  // Return an id for the specifed ImageFileReader.
+  static ImageFileReader* idToReader(u8 id);
 
   // Open image file for access.
   bool open();
+
   // Close image file.
   void close();
 
+  inline bool is_verified() const {
+    return (_header.flags(_endian) & IMAGE_VERIFIED) != 0;
+  }
+
+  // Read directly from the file.
+  bool read_at(u1* data, u8 size, u8 offset) const;
+
+  inline Endian* endian() const { return _endian; }
+
   // Retrieve name of image file.
   inline const char* name() const {
     return _name;
   }
 
+  // Return first address of index data.
+  inline u1* get_index_address() const {
+    return _index_data;
+  }
+
+  // Return first address of resource data.
+  inline u1* get_data_address() const {
+    return _index_data + _index_size;
+  }
+
+  // Get the size of the index data.
+  size_t get_index_size() const {
+    return _index_size;
+  }
+
+  inline u4 table_length() const {
+    return _header.table_length(_endian);
+  }
+
+  inline u4 locations_size() const {
+    return _header.locations_size(_endian);
+  }
+
+  inline u4 strings_size()const  {
+    return _header.strings_size(_endian);
+  }
+
+  inline u4* offsets_table() const {
+    return _offsets_table;
+  }
+
+  // Increment use count.
+  inline void inc_use() {
+    _use++;
+  }
+
+  // Decrement use count.
+  inline bool dec_use() {
+    return --_use == 0;
+  }
+
   // Return a string table accessor.
   inline const ImageStrings get_strings() const {
-    return ImageStrings(_string_bytes, _header._strings_size);
+    return ImageStrings(_string_bytes, _header.strings_size(_endian));
   }
 
-  // Return number of locations in image file index.
-  inline u4 get_location_count() const {
-    return _header._location_count;
+  // Return location attribute stream at offset.
+  inline u1* get_location_offset_data(u4 offset) const {
+    guarantee((u4)offset < _header.locations_size(_endian), "offset exceeds location attributes size");
+    return offset != 0 ? _location_bytes + offset : NULL;
   }
 
   // Return location attribute stream for location i.
-  inline u1* get_location_data(u4 i) const {
-    u4 offset = _offsets_table[i];
+  inline u1* get_location_data(u4 index) const {
+    guarantee((u4)index < _header.table_length(_endian), "index exceeds location count");
+    u4 offset = _endian->get(_offsets_table[index]);
 
-    return offset != 0 ? _location_bytes + offset : NULL;
+    return get_location_offset_data(offset);
   }
 
   // Return the attribute stream for a named resourced.
   u1* find_location_data(const char* path) const;
 
+  // Assemble the location path.
+  void location_path(ImageLocation& location, char* path, size_t max) const;
+
   // Verify that a found location matches the supplied path.
   bool verify_location(ImageLocation& location, const char* path) const;
 
   // Return the resource for the supplied location info.
-  u1* get_resource(ImageLocation& location) const;
+  u1* get_resource(ImageLocation& location, bool is_C_heap) const;
 
   // Return the resource associated with the path else NULL if not found.
-  void get_resource(const char* path, u1*& buffer, u8& size) const;
-
-  // Return an array of packages for a given module
-  GrowableArray<const char*>* packages(const char* name);
+  void get_resource(const char* path, u1*& buffer, u8& size,
+        bool is_C_heap = false) const;
 };
-
 #endif // SHARE_VM_CLASSFILE_IMAGEFILE_HPP
--- a/src/share/vm/classfile/javaClasses.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/javaClasses.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -25,6 +25,7 @@
 #include "precompiled.hpp"
 #include "classfile/altHashing.hpp"
 #include "classfile/javaClasses.inline.hpp"
+#include "classfile/moduleEntry.hpp"
 #include "classfile/stringTable.hpp"
 #include "classfile/vmSymbols.hpp"
 #include "code/debugInfo.hpp"
@@ -565,7 +566,7 @@
       }
     }
   }
-  create_mirror(k, Handle(NULL), Handle(NULL), CHECK);
+  create_mirror(k, Handle(NULL), Handle(NULL), Handle(NULL), CHECK);
 }
 
 void java_lang_Class::initialize_mirror_fields(KlassHandle k,
@@ -586,7 +587,7 @@
 }
 
 void java_lang_Class::create_mirror(KlassHandle k, Handle class_loader,
-                                    Handle protection_domain, TRAPS) {
+                                    Handle module, Handle protection_domain, TRAPS) {
   assert(k->java_mirror() == NULL, "should only assign mirror once");
   // Use this moment of initialization to cache modifier_flags also,
   // to support Class.getModifiers().  Instance classes recalculate
@@ -646,6 +647,10 @@
     assert(class_loader() == k->class_loader(), "should be same");
     set_class_loader(mirror(), class_loader());
 
+    // set the module field in the java_lang_Class instance
+    // This may be null during bootstrap but will get fixed up later on.
+    set_module(mirror(), module());
+
     // Setup indirection from klass->mirror last
     // after any exceptions can happen during allocations.
     if (!k.is_null()) {
@@ -659,8 +664,26 @@
     }
     fixup_mirror_list()->push(k());
   }
-}
-
+  // Keep list of classes needing java.base module fixup.
+  if (!ModuleEntryTable::javabase_created()) {
+    if (fixup_jlrM_list() == NULL) {
+      GrowableArray<Klass*>* list =
+        new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true);
+      set_fixup_jlrM_list(list);
+    }
+    if (k->oop_is_instance()) {
+      fixup_jlrM_list()->push(k());
+    } else if (k->oop_is_objArray()) {
+      ObjArrayKlass* obj_arr_klass = ObjArrayKlass::cast(k());
+      fixup_jlrM_list()->push(obj_arr_klass->bottom_klass());
+    }
+  }
+}
+
+void java_lang_Class::fixup_jlrM(KlassHandle k, Handle module, TRAPS) {
+  assert(_module_offset != 0, "must have been computed already");
+  java_lang_Class::set_module(k->java_mirror(), module());
+}
 
 int  java_lang_Class::oop_size(oop java_class) {
   assert(_oop_size_offset != 0, "must be set");
@@ -728,6 +751,16 @@
   return java_class->obj_field(_class_loader_offset);
 }
 
+oop java_lang_Class::module(oop java_class) {
+  assert(_module_offset != 0, "must be set");
+  return java_class->obj_field(_module_offset);
+}
+
+void java_lang_Class::set_module(oop java_class, oop md) {
+  assert(_module_offset != 0, "must be set");
+  java_class->obj_field_put(_module_offset, md);
+}
+
 oop java_lang_Class::create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS) {
   // This should be improved by adding a field at the Java level or by
   // introducing a new VM klass (see comment in ClassFileParser)
@@ -897,6 +930,10 @@
                  k, vmSymbols::componentType_name(),
                  vmSymbols::class_signature());
 
+  compute_offset(_module_offset,
+                 k, vmSymbols::module_name(),
+                 vmSymbols::module_signature());
+
   // Init lock is a C union with component_mirror.  Only instanceKlass mirrors have
   // init_lock and only ArrayKlass mirrors have component_mirror.  Since both are oops
   // GC treats them the same.
@@ -1482,28 +1519,42 @@
     }
   }
 
+  char *module_name = NULL, *module_version = NULL;
+  ModuleEntry* module = holder->module();
+  if (module != NULL) {
+    module_name = module->name()->as_C_string();
+    buf_len += (int)strlen(module_name);
+    module_version = module->version()->as_C_string();
+    buf_len += (int)strlen(module_version);
+  }
+
   // Allocate temporary buffer with extra space for formatting and line number
   char* buf = NEW_RESOURCE_ARRAY(char, buf_len + 64);
 
   // Print stack trace line in buffer
-  sprintf(buf, "\tat %s.%s", klass_name, method_name);
+  sprintf(buf, "\tat %s.%s(", klass_name, method_name);
+
+  // Print module information
+  if (module_name != NULL) {
+    sprintf(buf + (int)strlen(buf), "%s@%s/", module_name, module_version);
+  }
 
   if (!version_matches(method, version)) {
-    strcat(buf, "(Redefined)");
+    strcat(buf, "Redefined)");
   } else {
     int line_number = get_line_number(method, bci);
     if (line_number == -2) {
-      strcat(buf, "(Native Method)");
+      strcat(buf, "Native Method)");
     } else {
       if (source_file_name != NULL && (line_number != -1)) {
         // Sourcename and linenumber
-        sprintf(buf + (int)strlen(buf), "(%s:%d)", source_file_name, line_number);
+        sprintf(buf + (int)strlen(buf), "%s:%d)", source_file_name, line_number);
       } else if (source_file_name != NULL) {
         // Just sourcename
-        sprintf(buf + (int)strlen(buf), "(%s)", source_file_name);
+        sprintf(buf + (int)strlen(buf), "%s)", source_file_name);
       } else {
         // Neither sourcename nor linenumber
-        sprintf(buf + (int)strlen(buf), "(Unknown Source)");
+        sprintf(buf + (int)strlen(buf), "Unknown Source)");
       }
       nmethod* nm = method->code();
       if (WizardMode && nm != NULL) {
@@ -1889,6 +1940,16 @@
   oop methodname = StringTable::intern(method->name(), CHECK_0);
   java_lang_StackTraceElement::set_methodName(element(), methodname);
 
+  // Fill in module name
+  ModuleEntry* module = holder->module();
+  if (module != NULL) {
+    int len = module->name()->utf8_length() + module->version()->utf8_length() + 1 + 1;
+    char* buf = NEW_RESOURCE_ARRAY(char, len);
+    jio_snprintf(buf, len, "%s@%s", module->name()->as_utf8(), module->version()->as_utf8());
+    oop module_id = StringTable::intern(buf, CHECK_0);
+    java_lang_StackTraceElement::set_moduleId(element(), module_id);
+  }
+
   if (!version_matches(method, version)) {
     // The method was redefined, accurate line number information isn't available
     java_lang_StackTraceElement::set_fileName(element(), NULL);
@@ -2445,6 +2506,54 @@
 }
 
 
+int java_lang_reflect_Module::loader_offset;
+int java_lang_reflect_Module::name_offset;
+
+Handle java_lang_reflect_Module::create(Handle loader, Handle module_name, TRAPS) {
+  assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
+
+  Symbol* name = vmSymbols::java_lang_reflect_Module();
+  Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
+  instanceKlassHandle klass (THREAD, k);
+
+  Handle jlrmh = klass->allocate_instance_handle(CHECK_NH);
+  JavaValue result(T_VOID);
+  JavaCalls::call_special(&result, jlrmh, KlassHandle(THREAD, klass()),
+                          vmSymbols::object_initializer_name(),
+                          vmSymbols::java_lang_reflect_module_init_signature(),
+                          loader, module_name, CHECK_NH);
+  return jlrmh;
+}
+
+void java_lang_reflect_Module::compute_offsets() {
+  Klass* k = SystemDictionary::reflect_Module_klass();
+  if(NULL != k) {
+    compute_offset(loader_offset,  k, vmSymbols::loader_name(),  vmSymbols::classloader_signature());
+    compute_offset(name_offset,    k, vmSymbols::name_name(),    vmSymbols::string_signature());
+  }
+}
+
+
+oop java_lang_reflect_Module::loader(oop module) {
+  assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
+  return module->obj_field(loader_offset);
+}
+
+void java_lang_reflect_Module::set_loader(oop module, oop value) {
+  assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
+  module->obj_field_put(loader_offset, value);
+}
+
+oop java_lang_reflect_Module::name(oop module) {
+  assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
+  return module->obj_field(name_offset);
+}
+
+void java_lang_reflect_Module::set_name(oop module, oop value) {
+  assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
+  module->obj_field_put(name_offset, value);
+}
+
 Handle sun_reflect_ConstantPool::create(TRAPS) {
   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
   Klass* k = SystemDictionary::reflect_ConstantPool_klass();
@@ -3162,11 +3271,13 @@
 int java_lang_Class::_oop_size_offset;
 int java_lang_Class::_static_oop_field_count_offset;
 int java_lang_Class::_class_loader_offset;
+int java_lang_Class::_module_offset;
 int java_lang_Class::_protection_domain_offset;
 int java_lang_Class::_component_mirror_offset;
 int java_lang_Class::_init_lock_offset;
 int java_lang_Class::_signers_offset;
 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
+GrowableArray<Klass*>* java_lang_Class::_fixup_jlrM_list = NULL;
 int java_lang_Throwable::backtrace_offset;
 int java_lang_Throwable::detailMessage_offset;
 int java_lang_Throwable::cause_offset;
@@ -3226,6 +3337,7 @@
 int java_lang_StackTraceElement::methodName_offset;
 int java_lang_StackTraceElement::fileName_offset;
 int java_lang_StackTraceElement::lineNumber_offset;
+int java_lang_StackTraceElement::moduleId_offset;
 int java_lang_AssertionStatusDirectives::classes_offset;
 int java_lang_AssertionStatusDirectives::classEnabled_offset;
 int java_lang_AssertionStatusDirectives::packages_offset;
@@ -3255,6 +3367,10 @@
   element->int_field_put(lineNumber_offset, value);
 }
 
+void java_lang_StackTraceElement::set_moduleId(oop element, oop value) {
+  element->obj_field_put(moduleId_offset, value);
+}
+
 
 // Support for java Assertions - java_lang_AssertionStatusDirectives.
 
@@ -3349,6 +3465,7 @@
   java_lang_System::static_security_offset = java_lang_System::hc_static_security_offset * x;
 
   // java_lang_StackTraceElement
+  java_lang_StackTraceElement::moduleId_offset = java_lang_StackTraceElement::hc_moduleId_offset * x + header;
   java_lang_StackTraceElement::declaringClass_offset = java_lang_StackTraceElement::hc_declaringClass_offset  * x + header;
   java_lang_StackTraceElement::methodName_offset = java_lang_StackTraceElement::hc_methodName_offset * x + header;
   java_lang_StackTraceElement::fileName_offset   = java_lang_StackTraceElement::hc_fileName_offset   * x + header;
@@ -3387,6 +3504,7 @@
   sun_reflect_ConstantPool::compute_offsets();
   sun_reflect_UnsafeStaticFieldAccessorImpl::compute_offsets();
   java_lang_reflect_Parameter::compute_offsets();
+  java_lang_reflect_Module::compute_offsets();
 
   // generated interpreter code wants to know about the offsets we just computed:
   AbstractAssembler::update_delayed_values();
--- a/src/share/vm/classfile/javaClasses.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/javaClasses.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -239,26 +239,32 @@
   static int _init_lock_offset;
   static int _signers_offset;
   static int _class_loader_offset;
+  static int _module_offset;
   static int _component_mirror_offset;
 
   static bool offsets_computed;
   static int classRedefinedCount_offset;
 
   static GrowableArray<Klass*>* _fixup_mirror_list;
+  static GrowableArray<Klass*>* _fixup_jlrM_list;
 
   static void set_init_lock(oop java_class, oop init_lock);
   static void set_protection_domain(oop java_class, oop protection_domain);
   static void set_class_loader(oop java_class, oop class_loader);
+  static void set_module(oop java_class, oop module);
   static void set_component_mirror(oop java_class, oop comp_mirror);
   static void initialize_mirror_fields(KlassHandle k, Handle mirror, Handle protection_domain, TRAPS);
  public:
   static void compute_offsets();
 
   // Instance creation
-  static void create_mirror(KlassHandle k, Handle class_loader,
+  static void create_mirror(KlassHandle k, Handle class_loader, Handle module,
                             Handle protection_domain, TRAPS);
   static void fixup_mirror(KlassHandle k, TRAPS);
   static oop  create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
+
+  static void fixup_jlrM(KlassHandle k, Handle module, TRAPS);
+
   // Conversion
   static Klass* as_Klass(oop java_class);
   static void set_klass(oop java_class, Klass* klass);
@@ -295,18 +301,28 @@
   static void set_signers(oop java_class, objArrayOop signers);
 
   static oop class_loader(oop java_class);
+  static oop module(oop java_class);
 
   static int oop_size(oop java_class);
   static void set_oop_size(oop java_class, int size);
   static int static_oop_field_count(oop java_class);
   static void set_static_oop_field_count(oop java_class, int size);
 
+
   static GrowableArray<Klass*>* fixup_mirror_list() {
     return _fixup_mirror_list;
   }
   static void set_fixup_mirror_list(GrowableArray<Klass*>* v) {
     _fixup_mirror_list = v;
   }
+
+  static GrowableArray<Klass*>* fixup_jlrM_list() {
+    return _fixup_jlrM_list;
+  }
+  static void set_fixup_jlrM_list(GrowableArray<Klass*>* v) {
+    _fixup_jlrM_list = v;
+  }
+
   // Debugging
   friend class JavaClasses;
   friend class InstanceKlass;   // verification code accesses offsets
@@ -785,6 +801,26 @@
   friend class JavaClasses;
 };
 
+class java_lang_reflect_Module {
+  private:
+    static int loader_offset;
+    static int name_offset;
+    static void compute_offsets();
+
+  public:
+    // Allocation
+    static Handle create(Handle loader, Handle module_name, TRAPS);
+
+    // Accessors
+    static oop loader(oop module);
+    static void set_loader(oop module, oop value);
+
+    static oop name(oop module);
+    static void set_name(oop module, oop value);
+
+  friend class JavaClasses;
+};
+
 // Interface to sun.reflect.ConstantPool objects
 class sun_reflect_ConstantPool {
  private:
@@ -1295,12 +1331,14 @@
 class java_lang_StackTraceElement: AllStatic {
  private:
   enum {
-    hc_declaringClass_offset  = 0,
-    hc_methodName_offset = 1,
-    hc_fileName_offset   = 2,
-    hc_lineNumber_offset = 3
+    hc_moduleId_offset = 0,
+    hc_declaringClass_offset = 1,
+    hc_methodName_offset = 2,
+    hc_fileName_offset   = 3,
+    hc_lineNumber_offset = 4
   };
 
+  static int moduleId_offset;
   static int declaringClass_offset;
   static int methodName_offset;
   static int fileName_offset;
@@ -1308,6 +1346,7 @@
 
  public:
   // Setters
+  static void set_moduleId(oop element, oop value);
   static void set_declaringClass(oop element, oop value);
   static void set_methodName(oop element, oop value);
   static void set_fileName(oop element, oop value);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/classfile/moduleEntry.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -0,0 +1,334 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "classfile/classLoaderData.hpp"
+#include "classfile/javaClasses.hpp"
+#include "classfile/moduleEntry.hpp"
+#include "memory/resourceArea.hpp"
+#include "oops/oop.inline.hpp"
+#include "oops/symbol.hpp"
+#include "prims/jni.h"
+#include "runtime/handles.inline.hpp"
+#include "runtime/safepoint.hpp"
+#include "trace/traceMacros.hpp"
+#include "utilities/events.hpp"
+#include "utilities/growableArray.hpp"
+#include "utilities/hashtable.inline.hpp"
+
+bool ModuleEntryTable::_javabase_created = false;
+
+// Returns true if this module can read module m
+bool ModuleEntry::can_read(ModuleEntry* m) const {
+  assert(m != NULL, "No module to lookup in this module's reads list");
+  MutexLocker m1(Module_lock);
+  if (_reads == NULL) {
+    return false;
+  } else {
+    return _reads->contains(m);
+  }
+}
+
+// Add a new module to this module's reads list
+void ModuleEntry::add_read(ModuleEntry* m) {
+  assert(m != NULL, "No module to add to this module's reads list");
+  MutexLocker m1(Module_lock);
+  if (_reads == NULL) {
+    // Lazily create a module's reads list
+    // Initial size is 101.
+    _reads = new (ResourceObj::C_HEAP, mtClass) GrowableArray<ModuleEntry*>(101, true);
+  }
+  _reads->append_if_missing(m);
+}
+
+bool ModuleEntry::has_reads() const {
+  return _reads != NULL && !_reads->is_empty();
+}
+
+// Purge dead module entries out of reads list.
+void ModuleEntry::purge_reads() {
+  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
+  if (_reads != NULL) {
+    // Go backwards because this removes entries that are dead.
+    int len = _reads->length();
+    for (int idx = len - 1; idx >= 0; idx--) {
+      ModuleEntry* module_idx = _reads->at(idx);
+      ClassLoaderData* cld = module_idx->loader();
+      if (cld->is_unloading()) {
+        _reads->delete_at(idx);
+      }
+    }
+  }
+}
+
+void ModuleEntry::delete_reads() {
+  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
+  delete _reads;
+  _reads = NULL;
+}
+
+ModuleEntryTable::ModuleEntryTable(int table_size)
+  : Hashtable<oop, mtClass>(table_size, sizeof(ModuleEntry))
+{
+}
+
+ModuleEntryTable::~ModuleEntryTable() {
+  assert_locked_or_safepoint(Module_lock);
+
+  // Walk through all buckets and all entries in each bucket,
+  // freeing each entry.
+  for (int i = 0; i < table_size(); ++i) {
+    for (ModuleEntry* m = bucket(i); m != NULL;) {
+      ModuleEntry* to_remove = m;
+      // read next before freeing.
+      m = m->next();
+
+      if (TraceModules) {
+        ResourceMark rm;
+        tty->print("[deleting module: %s, ", to_remove->name()->as_C_string());
+        to_remove->loader()->print_value();
+        tty->cr();
+      }
+
+      // Clean out the C heap allocated reads list first before freeing the entry
+      to_remove->delete_reads();
+      to_remove->name()->decrement_refcount();
+      to_remove->version()->decrement_refcount();
+      if (to_remove->location() != NULL) {
+        to_remove->location()->decrement_refcount();
+      }
+
+      // Unlink from the Hashtable prior to freeing
+      unlink_entry(to_remove);
+      FREE_C_HEAP_ARRAY(char, to_remove);
+    }
+  }
+  assert(number_of_entries() == 0, "should have removed all entries");
+  assert(new_entry_free_list() == NULL, "entry present on ModuleEntryTable's free list");
+  free_buckets();
+}
+
+ModuleEntry* ModuleEntryTable::new_entry(unsigned int hash, oop module, Symbol* name,
+                                         Symbol* version, Symbol* location,
+                                         ClassLoaderData* class_loader) {
+  assert_locked_or_safepoint(Module_lock);
+
+  ModuleEntry* entry = (ModuleEntry*) NEW_C_HEAP_ARRAY2(char, entry_size(), mtClass, CURRENT_PC);
+
+  // Initialize everything BasicHashtable would
+  entry->set_next(NULL);
+  entry->set_hash(hash);
+  entry->set_literal(module);
+
+  // Initialize fields specific to a ModuleEntry
+  entry->init();
+  entry->set_name(name);
+  name->increment_refcount();
+  entry->set_loader(class_loader);
+  entry->set_version(version);
+  version->increment_refcount();
+  vmassert(entry->location() == NULL, "Unexpected value");
+  if (location != NULL) {
+    entry->set_location(location);
+    location->increment_refcount();
+  }
+  TRACE_INIT_MODULE_ID(entry);
+
+  return entry;
+}
+
+void ModuleEntryTable::add_entry(int index, ModuleEntry* new_entry) {
+  assert_locked_or_safepoint(Module_lock);
+  Hashtable<oop, mtClass>::add_entry(index, (HashtableEntry<oop, mtClass>*)new_entry);
+}
+
+ModuleEntry* ModuleEntryTable::locked_create_entry_or_null(oop module, Symbol* module_name,
+                                                           Symbol *module_version,
+                                                           Symbol *module_location,
+                                                           ClassLoaderData* loader) {
+  assert_locked_or_safepoint(Module_lock);
+  // Check if module already exists.
+  if (lookup_only(module_name) != NULL) {
+    return NULL;
+  } else {
+    ModuleEntry* entry = new_entry(compute_hash(module), module, module_name,
+                                   module_version, module_location, loader);
+    add_entry(index_for(module), entry);
+    return entry;
+  }
+}
+
+// lookup_only by Symbol* to find a ModuleEntry. Before a java.lang.reflect.Module
+// exists only the module name is available.
+ModuleEntry* ModuleEntryTable::lookup_only(Symbol* name) {
+  for (int i = 0; i < table_size(); i++) {
+    for (ModuleEntry* m = bucket(i); m != NULL; m = m->next()) {
+      if (m->name()->fast_compare(name) == 0) {
+        return m;
+      }
+    }
+  }
+  return NULL;
+}
+
+ModuleEntry* ModuleEntryTable::lookup_only(oop module) {
+  int index = index_for(module);
+  for (ModuleEntry* m = bucket(index); m != NULL; m = m->next()) {
+    if (m->module() == module) {
+      return m;
+    }
+  }
+  return NULL;
+}
+
+// Once a j.l.r.Module has been created for java.base during
+// VM initialization, set its corresponding ModuleEntry correctly.
+void ModuleEntryTable::set_javabase_entry(oop m) {
+  Thread* THREAD = Thread::current();
+
+  ModuleEntry* jb_module = lookup_only(vmSymbols::java_base());
+  if (jb_module == NULL) {
+    vm_exit_during_initialization("No module entry for java.base located");
+  }
+
+  // Set the j.l.r.M for java.base's ModuleEntry as well as the static
+  // field within all ModuleEntryTables.
+  jb_module->set_module(m);
+  _javabase_created = true;
+}
+
+void ModuleEntryTable::patch_javabase_entries(TRAPS) {
+  ResourceMark rm;
+
+  // Create the java.lang.reflect.Module object for module 'java.base'.
+  Handle java_base = java_lang_String::create_from_str(vmSymbols::java_base()->as_C_string(), CHECK);
+  Handle jlrM_handle = java_lang_reflect_Module::create(
+                         Handle(ClassLoaderData::the_null_class_loader_data()->class_loader()), java_base, CHECK);
+  if (jlrM_handle.is_null()) {
+    fatal("Cannot create java.lang.reflect.Module object for java.base");
+  }
+
+  if (TraceModules) {
+    tty->print_cr("[MET::patch_javabase_entries, j.l.r.Module for java.base created]");
+  }
+
+  // Set jlrM_handle for java.base module in module entry table.
+  ClassLoaderData::the_null_class_loader_data()->modules()->set_javabase_entry(jlrM_handle());
+
+  // Do the fixups for classes that have already been created.
+  GrowableArray <Klass*>* list = java_lang_Class::fixup_jlrM_list();
+  int list_length = list->length();
+  for (int i = 0; i < list_length; i++) {
+    Klass* k = list->at(i);
+    assert(k->is_klass(), "List should only hold classes");
+    EXCEPTION_MARK;
+    KlassHandle kh(THREAD, k);
+    java_lang_Class::fixup_jlrM(kh, jlrM_handle, CATCH);
+    if (TraceModules) {
+      tty->print_cr("[MET::patch_javabase_entries, patching class %s]", k->external_name());
+    }
+  }
+  delete java_lang_Class::fixup_jlrM_list();
+  java_lang_Class::set_fixup_jlrM_list(NULL);
+
+  if (TraceModules) {
+    tty->print_cr("[MET::patch_javabase_entries, patching complete, fixup array deleted]");
+  }
+}
+
+void ModuleEntryTable::oops_do(OopClosure* f) {
+  for (int i = 0; i < table_size(); i++) {
+    for (ModuleEntry* probe = bucket(i);
+                              probe != NULL;
+                              probe = probe->next()) {
+      probe->oops_do(f);
+    }
+  }
+}
+
+// Remove dead modules from all other alive modules' reads list.
+// This should only occur at class unloading.
+void ModuleEntryTable::purge_all_module_reads() {
+  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
+  for (int i = 0; i < table_size(); i++) {
+    for (ModuleEntry* entry = bucket(i);
+                      entry != NULL;
+                      entry = entry->next()) {
+      entry->purge_reads();
+    }
+  }
+}
+
+#ifndef PRODUCT
+void ModuleEntryTable::print() {
+  tty->print_cr("Module Entry Table (table_size=%d, entries=%d)",
+                table_size(), number_of_entries());
+  for (int i = 0; i < table_size(); i++) {
+    for (ModuleEntry* probe = bucket(i);
+                              probe != NULL;
+                              probe = probe->next()) {
+      probe->print();
+    }
+  }
+}
+
+void ModuleEntry::print() {
+  ResourceMark rm;
+  tty->print_cr("entry "PTR_FORMAT" oop "PTR_FORMAT" name %s loader %s version %s location %s pkgs_with_qexports %d next "PTR_FORMAT,
+                p2i(this), p2i(literal()), name()->as_C_string(), loader()->loader_name(),
+                version()->as_C_string(), location() != NULL ? location()->as_C_string() : "NULL",
+                _pkgs_with_qexports, p2i(next()));
+}
+#endif
+
+void ModuleEntryTable::verify() {
+  int element_count = 0;
+  for (int i = 0; i < table_size(); i++) {
+    for (ModuleEntry* probe = bucket(i);
+                              probe != NULL;
+                              probe = probe->next()) {
+      probe->verify();
+      element_count++;
+    }
+  }
+  guarantee(number_of_entries() == element_count,
+            "Verify of Module Entry Table failed");
+  debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
+}
+
+void ModuleEntry::verify() {
+  guarantee(literal()->is_oop(), "must be an oop");
+}
+
+void ModuleEntry::module_reads_do(ModuleClosure* const f) {
+  assert_locked_or_safepoint(Module_lock);
+  assert(f != NULL, "invariant");
+
+  if (_reads != NULL) {
+    int reads_len = _reads->length();
+    for (int i = 0; i < reads_len; ++i) {
+      f->do_module(_reads->at(i));
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/classfile/moduleEntry.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ */
+
+#ifndef SHARE_VM_CLASSFILE_MODULEENTRY_HPP
+#define SHARE_VM_CLASSFILE_MODULEENTRY_HPP
+
+#include "classfile/classLoaderData.hpp"
+#include "classfile/vmSymbols.hpp"
+#include "oops/symbol.hpp"
+#include "prims/jni.h"
+#include "runtime/mutexLocker.hpp"
+#include "trace/traceMacros.hpp"
+#include "utilities/growableArray.hpp"
+#include "utilities/hashtable.hpp"
+
+class ModuleClosure;
+
+// A ModuleEntry describes a module that has been defined by a call to JVM_DefineModule.
+// It contains:
+//   - a pointer to the java.lang.reflect.Module object for this module.
+//   - Symbol* containing the module's name.
+//   - ClassLoaderData*, class loader of this module.
+//   - a growable array containg other module entries that this module can read.
+//   - a flag indicating if any of the packages defined within this module have qualified
+//     exports.
+//
+class ModuleEntry : public HashtableEntry<oop, mtClass> {
+private:
+  Symbol* _name;
+  ClassLoaderData* _loader;
+  GrowableArray<ModuleEntry*>* _reads; // list of modules that are readable by this module
+  Symbol* _version;   // module version number
+  Symbol* _location;  // module location
+  bool _pkgs_with_qexports; // this module contains 1 or more packages with qualified exports
+  TRACE_DEFINE_TRACE_ID_FIELD;
+
+public:
+  void init() {
+    _name = NULL;
+    _loader = NULL;
+    _reads = NULL;
+    _version = NULL;
+    _location = NULL;
+    _pkgs_with_qexports = false;
+  }
+
+  oop                module() const                 { return literal(); }
+  void               set_module(oop m)              { set_literal(m); }
+
+  Symbol*            name() const                   { return _name; }
+  void               set_name(Symbol* n)            { _name = n; }
+
+  ClassLoaderData*   loader() const                 { return _loader; }
+  void               set_loader(ClassLoaderData* l) { _loader = l; }
+
+  Symbol*            version() const                { return _version; }
+  void               set_version(Symbol* version)   { _version = version; }
+
+  Symbol*            location() const               { return _location; }
+  void               set_location(Symbol* location) { _location = location; }
+
+  bool               can_read(ModuleEntry* m) const;
+  bool               has_reads() const;
+  void               add_read(ModuleEntry* m);
+
+  bool               pkgs_with_qexports()           { return _pkgs_with_qexports; }
+  void               set_pkgs_with_qexports(bool q) { _pkgs_with_qexports = q; }
+
+  ModuleEntry* next() const {
+    return (ModuleEntry*)HashtableEntry<oop, mtClass>::next();
+  }
+  ModuleEntry** next_addr() {
+    return (ModuleEntry**)HashtableEntry<oop, mtClass>::next_addr();
+  }
+
+  // GC support
+  void oops_do(OopClosure* f) {
+    f->do_oop(literal_addr());
+  }
+
+  // iteration support for readability
+  void module_reads_do(ModuleClosure* const f);
+
+  TRACE_DEFINE_TRACE_ID_METHODS;
+
+  // Purge dead weak references out of reads list when any given class loader is unloaded.
+  void purge_reads();
+  void delete_reads();
+
+  void print() PRODUCT_RETURN;
+  void verify();
+};
+
+// Iterator interface
+class ModuleClosure: public StackObj {
+ public:
+  virtual void do_module(ModuleEntry* const module) = 0;
+};
+
+
+// The ModuleEntryTable is a Hashtable containing a list of all modules defined
+// by a particular class loader.  Each module is represented as a ModuleEntry node.
+//
+// Each ModuleEntryTable contains a _javabase_created field indicating if java.base's
+// corresponding j.l.r.Module has been created.  Having this field provided a way to create a
+// ModuleEntry node for java.base very early in bootstrapping in order to obtain
+// java.base's containing packages.  This occurs prior to creation of the j.l.r.Module
+// for java.base during VM initialization.  java.base is the only module that does
+// not have a corresponding JVM_DefineModule() invocation.  It is the JVM's
+// responsibility to create.  Note, within the null boot class loader's ModulEntry table,
+// the ModuleEntry for java.base is hashed at bucket 0.
+//
+// The ModuleEntryTable's lookup is lock free.  Note, that the fastest lookup is to
+// invoke lookup_only with a j.l.r.M.  A lookup_only capability based on a module's
+// name is also provided.
+//
+class ModuleEntryTable : public Hashtable<oop, mtClass> {
+  friend class VMStructs;
+public:
+  enum Constants {
+    _moduletable_entry_size  = 1009  // number of entries in module entry table
+  };
+
+private:
+  static bool _javabase_created;
+
+  ModuleEntry* new_entry(unsigned int hash, oop module, Symbol* name, Symbol* version,
+                         Symbol* location, ClassLoaderData* class_loader);
+  void set_javabase_entry(oop m);
+  void add_entry(int index, ModuleEntry* new_entry);
+
+public:
+  ModuleEntryTable(int table_size);
+  ~ModuleEntryTable();
+
+  int entry_size() const { return BasicHashtable<mtClass>::entry_size(); }
+
+  // Create module in loader's module entry table, if already exists then
+  // return null.  Assume Module_lock has been locked by caller.
+  ModuleEntry* locked_create_entry_or_null(oop module, Symbol* module_name,
+                                           Symbol* module_version,
+                                           Symbol* module_location,
+                                           ClassLoaderData* loader);
+
+  // only lookup module within loader's module entry table
+  ModuleEntry* lookup_only(Symbol* name);
+  ModuleEntry* lookup_only(oop module);
+
+  ModuleEntry* bucket(int i) {
+    return (ModuleEntry*)Hashtable<oop, mtClass>::bucket(i);
+  }
+
+  ModuleEntry** bucket_addr(int i) {
+    return (ModuleEntry**)Hashtable<oop, mtClass>::bucket_addr(i);
+  }
+
+  static bool javabase_created() { return _javabase_created; }
+  static void patch_javabase_entries(TRAPS);
+
+  unsigned int compute_hash(oop module) {
+    if (module == NULL) {
+      // java.base prior to creation of its j.l.r.M
+      return 0;
+    }
+
+    ModuleEntryTable* met = ClassLoaderData::the_null_class_loader_data()->modules();
+    assert(met != NULL, "The null class loader's moduleEntry table should be defined");
+    if (_javabase_created && (module == met->lookup_only(vmSymbols::java_base())->module())) {
+      // java.base after creation of its j.l.r.M
+      return 0;
+    } else {
+      return (unsigned int)(module->identity_hash());
+    }
+  }
+
+  int index_for(oop module) {
+    return hash_to_index(compute_hash(module));
+  }
+
+  // GC support
+  void oops_do(OopClosure* f);
+
+  // purge dead weak references out of reads list
+  void purge_all_module_reads();
+
+  void print() PRODUCT_RETURN;
+  void verify();
+};
+
+#endif // SHARE_VM_CLASSFILE_MODULEENTRY_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/classfile/modules.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -0,0 +1,695 @@
+/*
+* Copyright (c) 2015, 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.
+*
+*/
+
+#include "precompiled.hpp"
+#include "classfile/classLoader.hpp"
+#include "classfile/classLoaderData.inline.hpp"
+#include "classfile/javaAssertions.hpp"
+#include "classfile/javaClasses.hpp"
+#include "classfile/moduleEntry.hpp"
+#include "classfile/modules.hpp"
+#include "classfile/packageEntry.hpp"
+#include "classfile/stringTable.hpp"
+#include "classfile/symbolTable.hpp"
+#include "classfile/vmSymbols.hpp"
+#include "oops/instanceKlass.hpp"
+#include "oops/objArrayKlass.hpp"
+#include "oops/objArrayOop.inline.hpp"
+#include "runtime/arguments.hpp"
+#include "runtime/handles.inline.hpp"
+#include "runtime/reflection.hpp"
+#include "utilities/utf8.hpp"
+
+
+static bool verify_module_name(char *module_name) {
+  if (module_name == NULL) return false;
+  int len = (int)strlen(module_name);
+  return (len > 0 && len <= Symbol::max_length() &&
+    UTF8::is_legal_utf8((unsigned char *)module_name, len, false) &&
+    ClassFileParser::verify_unqualified_name(module_name, len,
+    ClassFileParser::LegalModule));
+}
+
+bool Modules::verify_package_name(char *package_name) {
+  if (package_name == NULL) return false;
+  int len = (int)strlen(package_name);
+  return (len > 0 && len <= Symbol::max_length() &&
+    UTF8::is_legal_utf8((unsigned char *)package_name, len, false) &&
+    ClassFileParser::verify_unqualified_name(package_name, len,
+    ClassFileParser::LegalClass));
+}
+
+static ModuleEntryTable* get_module_entry_table(Handle h_loader, TRAPS) {
+  // This code can be called during start-up, before the classLoader's classLoader data got
+  // created.  So, call register_loader() to make sure the classLoader data gets created.
+  ClassLoaderData *loader_cld = SystemDictionary::register_loader(h_loader, CHECK_NULL);
+  return loader_cld->modules();
+}
+
+static PackageEntryTable* get_package_entry_table(Handle h_loader, TRAPS) {
+  // This code can be called during start-up, before the classLoader's classLoader data got
+  // created.  So, call register_loader() to make sure the classLoader data gets created.
+  ClassLoaderData *loader_cld = SystemDictionary::register_loader(h_loader, CHECK_NULL);
+  return loader_cld->packages();
+}
+
+static PackageEntry* get_package_entry_by_name(Symbol* package,
+                                               Handle h_loader,
+                                               TRAPS) {
+  if (package != NULL) {
+    ResourceMark rm;
+    if (Modules::verify_package_name(package->as_C_string())) {
+      PackageEntryTable* const package_entry_table =
+        get_package_entry_table(h_loader, THREAD);
+      assert(package_entry_table != NULL, "Unexpected null package entry table");
+      return package_entry_table->lookup_only(package);
+    }
+  }
+  return NULL;
+}
+
+static ModuleEntry* get_module_entry_by_package_name(Symbol* package,
+                                                     Handle h_loader,
+                                                     TRAPS) {
+  const PackageEntry* const pkg_entry =
+    get_package_entry_by_name(package, h_loader, THREAD);
+
+  return pkg_entry != NULL ? pkg_entry->module() : NULL;
+}
+
+// Check if -Xoverride:<path> was specified.  If so, prepend <path>/module_name,
+// if it exists, to bootpath so boot loader can find the class files.  Also, if
+// using exploded modules, prepend <java.home>/modules/module_name, if it exists,
+// to bootpath so that its class files can be found by the boot loader.
+static void add_to_boot_loader_list(char *module_name, TRAPS) {
+  // java.base should be handled by argument parsing.
+  assert(strcmp(module_name, "java.base") != 0, "Unexpected java.base module name");
+  char file_sep = os::file_separator()[0];
+  size_t module_len = strlen(module_name);
+
+  // If -Xoverride is set then add path <override-dir>/module_name.
+  char* prefix_path = NULL;
+  if (Arguments::override_dir() != NULL) {
+    size_t len = strlen(Arguments::override_dir()) + module_len + 2;
+    prefix_path = NEW_C_HEAP_ARRAY(char, len, mtInternal);
+    jio_snprintf(prefix_path, len, "%s%c%s", Arguments::override_dir(), file_sep, module_name);
+    struct stat st;
+    // See if Xoverride module path exists.
+    if ((os::stat(prefix_path, &st) != 0)) {
+      FREE_C_HEAP_ARRAY(char, prefix_path);
+      prefix_path = NULL;
+    }
+  }
+
+  // If bootmodules.jimage does not exist then assume exploded form
+  // ${java.home}/modules/<module-name>
+  char* path = NULL;
+  if (!ClassLoader::has_bootmodules_jimage()) {
+    const char* home = Arguments::get_java_home();
+    size_t len = strlen(home) + module_len + 32;
+    path = NEW_C_HEAP_ARRAY(char, len, mtInternal);
+    jio_snprintf(path, len, "%s%cmodules%c%s", home, file_sep, file_sep, module_name);
+    struct stat st;
+    // See if exploded module path exists.
+    if ((os::stat(path, &st) != 0)) {
+      FREE_C_HEAP_ARRAY(char, path);
+      path = NULL;
+    }
+  }
+
+  if (prefix_path != NULL || path != NULL) {
+    HandleMark hm;
+    Handle loader_lock = Handle(THREAD, SystemDictionary::system_loader_lock());
+    ObjectLocker ol(loader_lock, THREAD);
+
+    if (prefix_path != NULL) {
+      if (TraceClassLoading) tty->print_cr("[Opened -Xoverride %s]", prefix_path);
+      ClassLoader::add_to_list(prefix_path);
+    }
+    if (path != NULL) {
+      if (TraceClassLoading) tty->print_cr("[Opened %s]", path);
+      ClassLoader::add_to_list(path);
+    }
+  }
+}
+
+static ModuleEntry* get_module_entry(jobject module, TRAPS) {
+  Handle h_module(THREAD, JNIHandles::resolve(module));
+  oop loader = java_lang_reflect_Module::loader(h_module());
+  Handle h_loader = Handle(loader);
+  ModuleEntryTable* module_table = get_module_entry_table(h_loader, CHECK_NULL);
+  assert(module_table != NULL, "Unexpected null module entry table");
+  return module_table->lookup_only(h_module());
+}
+
+static PackageEntry* get_package_entry(ModuleEntry* module_entry, jstring package, TRAPS) {
+  ResourceMark rm;
+  if (package == NULL) return NULL;
+  const char *package_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(package));
+  if (package_name == NULL) return NULL;
+  TempNewSymbol pkg_symbol = SymbolTable::new_symbol(package_name, CHECK_NULL);
+  PackageEntryTable* package_entry_table = module_entry->loader()->packages();
+  assert(package_entry_table != NULL, "Unexpected null package entry table");
+  return package_entry_table->lookup_only(pkg_symbol);
+}
+
+
+static const char* get_module_version(jstring version) {
+  char* module_version;
+  if (version == NULL) {
+    module_version = (char *)Modules::default_version();
+  } else {
+    module_version = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(version));
+    if (module_version == NULL) module_version = (char *)Modules::default_version();
+  }
+  return module_version;
+}
+
+static char* get_module_name(oop module, TRAPS) {
+  oop name_oop = java_lang_reflect_Module::name(module);
+  if (name_oop == NULL) {
+    THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), "Null module name");
+  }
+  char* module_name = java_lang_String::as_utf8_string(name_oop);
+  if (!verify_module_name(module_name)) {
+    THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
+                   err_msg("Invalid module name: %s",
+                           module_name != NULL ? module_name : "NULL"));
+  }
+  if (strcmp(module_name, vmSymbols::java_base()->as_C_string()) == 0) {
+    THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
+                   "Module java.base is already defined");
+  }
+  return module_name;
+}
+
+
+void Modules::define_module(JNIEnv *env, jobject module, jstring version,
+                            jstring location, jobjectArray packages) {
+  JavaThread *THREAD = JavaThread::thread_from_jni_environment(env);
+  ResourceMark rm(THREAD);
+
+  if (module == NULL) {
+    THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object");
+  }
+  Handle jlrM_handle(THREAD, JNIHandles::resolve(module));
+
+  char* module_name = get_module_name(jlrM_handle(), CHECK);
+  const char* module_version = get_module_version(version);
+
+  if (TraceModules) {
+    tty->print_cr("In define_module(): Start defining module %s, version: %s]",
+                  module_name, module_version);
+  }
+
+  objArrayOop packages_oop = objArrayOop(JNIHandles::resolve(packages));
+  objArrayHandle packages_h(THREAD, packages_oop);
+  int num_packages = (packages_h == NULL ? 0 : packages_h->length());
+
+  // Check that the list of packages has no duplicates and that the
+  // packages are syntactically ok.
+  GrowableArray<Symbol*>* pkg_list = new GrowableArray<Symbol*>(num_packages);
+  for (int x = 0; x < num_packages; x++) {
+    oop string_obj = packages_h->obj_at(x);
+
+    if (string_obj == NULL || !string_obj->is_a(SystemDictionary::String_klass())) {
+      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+                err_msg("Bad package name for module: %s", module_name));
+    }
+    char *package_name = java_lang_String::as_utf8_string(string_obj);
+    if (!verify_package_name(package_name)) {
+      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+                 err_msg("Invalid package name: %s for module: %s",
+                         package_name, module_name));
+    }
+    Symbol* pkg_symbol = SymbolTable::new_symbol(package_name, CHECK);
+    // append_if_missing() returns FALSE if entry already exists.
+    if (!pkg_list->append_if_missing(pkg_symbol)) {
+      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+                err_msg("Duplicate package name: %s for module %s",
+                        package_name, module_name));
+    }
+  }
+
+  oop loader = java_lang_reflect_Module::loader(jlrM_handle());
+  // Make sure loader is not the sun.reflect.DelegatingClassLoader.
+  if (loader != java_lang_ClassLoader::non_reflection_class_loader(loader)) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              "Class loader is an invalid delegating class loader");
+  }
+  Handle h_loader = Handle(THREAD, loader);
+
+  // Check that loader is a subclass of java.lang.ClassLoader.
+  if (loader != NULL && !java_lang_ClassLoader::is_subclass(h_loader->klass())) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              "Class loader is not a subclass of java.lang.ClassLoader");
+  }
+
+  ModuleEntryTable* module_table = get_module_entry_table(h_loader, CHECK);
+  assert(module_table != NULL, "module entry table shouldn't be null");
+
+  // Create symbol* entry for module name.
+  TempNewSymbol module_symbol = SymbolTable::new_symbol(module_name, CHECK);
+
+  int dupl_pkg_index = -1;
+  bool dupl_modules = false;
+  {
+    MutexLocker ml(Module_lock, THREAD);
+
+    PackageEntryTable* package_table = NULL;
+    if (num_packages > 0) {
+      package_table = get_package_entry_table(h_loader, CHECK);
+      assert(package_table != NULL, "Missing package_table");
+
+      // Check that none of the packages exist in the class loader's package table.
+      for (int x = 0; x < pkg_list->length(); x++) {
+        if (package_table->lookup_only(pkg_list->at(x))) {
+          // This could be because the module was already defined.  If so,
+          // report that error instead of the package error.
+          if (module_table->lookup_only(module_symbol) != NULL) {
+            dupl_modules = true;
+          } else {
+            dupl_pkg_index = x;
+          }
+          break;
+        }
+      }
+    }  // if (num_packages > 0)...
+
+    // Add the module and its packages.
+    if (!dupl_modules && dupl_pkg_index == -1) {
+      // Create the entry for this module in the class loader's module entry table.
+
+      // Create symbol* entry for module version.
+      TempNewSymbol version_symbol = SymbolTable::new_symbol(module_version, CHECK);
+
+      // Create symbol* entry for module location.
+      const char* module_location = NULL;
+      TempNewSymbol location_symbol = NULL;
+      if (location != NULL) {
+        module_location =
+          java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(location));
+        if (module_location != NULL) {
+          location_symbol = SymbolTable::new_symbol(module_location, CHECK);
+        }
+      }
+
+      ClassLoaderData* loader_data =
+        ClassLoaderData::class_loader_data_or_null(h_loader());
+      assert(loader_data != NULL, "class loader data shouldn't be null");
+      ModuleEntry* module_entry =
+        module_table->locked_create_entry_or_null(jlrM_handle(), module_symbol,
+          version_symbol, location_symbol, loader_data);
+
+      if (module_entry == NULL) {
+        dupl_modules = true;
+      } else {
+        if (TraceModules) {
+          tty->print("In define_module(): creation of module: %s, version: %s, location: %s, ",
+            module_name, module_version, module_location != NULL ? module_location : "NULL");
+          loader_data->print_value();
+          tty->print_cr(", package #: %d]", pkg_list->length());
+        }
+
+        // Add the packages.
+        assert(pkg_list->length() == 0 || package_table != NULL, "Bad package table");
+        PackageEntry* pkg;
+        for (int y = 0; y < pkg_list->length(); y++) {
+          pkg = package_table->locked_create_entry_or_null(pkg_list->at(y), module_entry);
+          assert(pkg != NULL, "Unable to create a module's package entry");
+
+          if (TraceModules || TracePackages) {
+            tty->print_cr("[In define_module(): creation of package %s for module %s]",
+                          (pkg_list->at(y))->as_C_string(), module_name);
+          }
+
+          // Unable to have a GrowableArray of TempNewSymbol.  Must decrement the refcount of
+          // the Symbol* that was created above for each package. The refcount was incremented
+          // by SymbolTable::new_symbol and as well by the PackageEntry creation.
+          pkg_list->at(y)->decrement_refcount();
+        }
+      }
+    }
+  }  // Release the lock
+
+  // any errors ?
+  if (dupl_modules) {
+     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+               err_msg("Module %s is already defined", module_name));
+  }
+  if (dupl_pkg_index != -1) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              err_msg("Package %s for module %s already exists for class loader",
+                       pkg_list->at(dupl_pkg_index)->as_C_string(), module_name));
+  }
+
+  if (loader == NULL && !Universe::is_module_initialized()) {
+    // Now that the module is defined, if it is in the bootloader, make sure that
+    // its classes can be found.  Check if -Xoverride:<path> was specified.  If
+    // so prepend <path>/module_name, if it exists, to bootpath.  Also, if using
+    // exploded modules, prepend <java.home>/modules/module_name, if it exists,
+    // to bootpath.
+    add_to_boot_loader_list(module_name, CHECK);
+  }
+}
+
+void Modules::add_module_exports(JNIEnv *env, jobject from_module, jstring package, jobject to_module) {
+  JavaThread *THREAD = JavaThread::thread_from_jni_environment(env);
+
+  if (package == NULL) {
+    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
+              "package is null");
+  }
+  if (from_module == NULL) {
+    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
+              "from_module is null");
+  }
+  ModuleEntry* from_module_entry = get_module_entry(from_module, CHECK);
+  if (from_module_entry == NULL) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              "from_module cannot be found");
+  }
+  ModuleEntry* to_module_entry;
+  if (to_module == NULL) {
+    to_module_entry = NULL;  // It's the unnamed module.
+  }
+  else {
+    to_module_entry = get_module_entry(to_module, CHECK);
+    if (to_module_entry == NULL) {
+      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+                "to_module is invalid");
+    }
+  }
+
+  PackageEntry *package_entry = get_package_entry(from_module_entry, package, CHECK);
+
+  if (package_entry == NULL) {
+    ResourceMark rm;
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              err_msg("Package %s not found in from_module %s",
+                      java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(package)),
+                      from_module_entry->name()->as_C_string()));
+  }
+  if (package_entry->module() != from_module_entry) {
+    ResourceMark rm;
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              err_msg("Package: %s found in module %s, not in from_module: %s",
+                      package_entry->name()->as_C_string(),
+                      package_entry->module()->name()->as_C_string(),
+                      from_module_entry->name()->as_C_string()));
+  }
+
+  if (TraceModules) {
+    ResourceMark rm;
+    tty->print_cr("[add_module_exports(): package:module %s:%s is exported to module %s]",
+                  package_entry->name()->as_C_string(),
+                  from_module_entry->name()->as_C_string(),
+                  ((to_module_entry == NULL) ? NULL : to_module_entry->name()->as_C_string()));
+  }
+
+  // If this is a qualified export, make sure the entry has not already been exported
+  // unqualifiedly.
+  if (to_module_entry != NULL && package_entry->is_unqual_exported()) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              err_msg("Bad qualifed export, package %s in module %s is already unqualifiedly exported",
+                      package_entry->name()->as_C_string(),
+                      from_module_entry->name()->as_C_string()));
+  }
+
+  // Do nothing if modules are the same.
+  if (from_module_entry != to_module_entry) {
+    package_entry->set_exported(to_module_entry);
+  }
+}
+
+void Modules::add_reads_module(JNIEnv *env, jobject from_module, jobject to_module) {
+  JavaThread *THREAD = JavaThread::thread_from_jni_environment(env);
+
+  if (from_module == NULL) {
+    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
+              "from_module is null");
+  }
+  if (to_module == NULL) {
+    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
+              "to_module is null");
+  }
+
+  ModuleEntry* from_module_entry = get_module_entry(from_module, CHECK);
+  if (from_module_entry == NULL) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              "from_module is not valid");
+  }
+  ModuleEntry* to_module_entry = get_module_entry(to_module, CHECK);
+  if (to_module_entry == NULL) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              "to_module is invalid");
+  }
+
+  if (TraceModules) {
+    ResourceMark rm;
+    tty->print_cr("[add_reads_module(): Adding read from module %s to module %s]",
+      from_module_entry->name()->as_C_string(),
+      to_module_entry->name()->as_C_string());
+  }
+
+  // if modules are the same, no need to add the read.
+  if (from_module_entry != to_module_entry) {
+    from_module_entry->add_read(to_module_entry);
+  }
+}
+
+jboolean Modules::can_read_module(JNIEnv *env, jobject asking_module, jobject target_module) {
+  JavaThread *THREAD = JavaThread::thread_from_jni_environment(env);
+
+  if (asking_module == NULL) {
+    THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
+               "asking_module is null", JNI_FALSE);
+  }
+
+  ModuleEntry* asking_module_entry = get_module_entry(asking_module, CHECK_false);
+  if (asking_module_entry == NULL) {
+    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
+               "asking_module is invalid", JNI_FALSE);
+  }
+
+  if (target_module == NULL) {
+    return JNI_TRUE;  // Unnamed module is always readable.
+  }
+
+  ModuleEntry* target_module_entry = get_module_entry(target_module, CHECK_false);
+  if (target_module_entry == NULL) {
+    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
+               "target_module is invalid", JNI_FALSE);
+  }
+
+  if (TraceModules) {
+    ResourceMark rm;
+    tty->print_cr("[can_read_module(): module %s trying to read module %s, allowed = %s",
+                  asking_module_entry->name()->as_C_string(),
+                  target_module_entry->name()->as_C_string(),
+                  BOOL_TO_STR((asking_module_entry == target_module_entry) ||
+                    (asking_module_entry->can_read(target_module_entry))));
+  }
+
+  if (asking_module_entry == target_module_entry) {
+    return true;
+  }
+  return asking_module_entry->can_read(target_module_entry);
+}
+
+jboolean Modules::is_exported_to_module(JNIEnv *env, jobject from_module, jstring package, jobject to_module) {
+  JavaThread *THREAD = JavaThread::thread_from_jni_environment(env);
+
+  if (package == NULL) {
+    THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
+               "package is null", JNI_FALSE);
+  }
+  if (from_module == NULL) {
+    THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
+               "from_module is null", JNI_FALSE);
+  }
+  ModuleEntry* from_module_entry = get_module_entry(from_module, CHECK_false);
+  if (from_module_entry == NULL) {
+    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
+               "from_module is invalid", JNI_FALSE);
+  }
+  ModuleEntry* to_module_entry;
+  if (to_module == NULL) {
+    to_module_entry = NULL;
+  }
+  else {
+    to_module_entry = get_module_entry(to_module, CHECK_false);
+    if (to_module_entry == NULL) {
+      THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
+                 "to_module is invalid", JNI_FALSE);
+    }
+  }
+
+  PackageEntry *package_entry = get_package_entry(from_module_entry, package,
+    CHECK_false);
+  if (package_entry == NULL) {
+    ResourceMark rm;
+    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
+               err_msg("Package not found in from_module: %s",
+                       from_module_entry->name()->as_C_string()), JNI_FALSE);
+  }
+  if (package_entry->module() != from_module_entry) {
+    ResourceMark rm;
+    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
+               err_msg("Package: %s found in module %s, not in from_module: %s",
+                       package_entry->name()->as_C_string(),
+                       package_entry->module()->name()->as_C_string(),
+                       from_module_entry->name()->as_C_string()), JNI_FALSE);
+  }
+
+  if (TracePackages) {
+    ResourceMark rm;
+    tty->print_cr("[is_exported_to_module: package %s from module %s checking if exported to module %s, exported? = %s",
+                  package_entry->name()->as_C_string(),
+                  from_module_entry->name()->as_C_string(),
+                  to_module_entry != NULL ? to_module_entry->name()->as_C_string() : "unnamed",
+                  BOOL_TO_STR(package_entry->is_unqual_exported() ||
+                    (to_module != NULL && package_entry->is_qexported_to(to_module_entry)) ||
+                    (from_module_entry == to_module_entry)));
+  }
+
+  return (package_entry->is_unqual_exported() ||
+          (from_module_entry == to_module_entry) ||
+          (to_module != NULL && package_entry->is_qexported_to(to_module_entry)));
+}
+
+jobject Modules::get_module(JNIEnv *env, jclass clazz) {
+  oop mirror = JNIHandles::resolve_non_null(clazz);
+  if (mirror == NULL || java_lang_Class::is_primitive(mirror)) {
+    if (TraceModules) {
+      tty->print_cr("[get_module(): returning NULL]");
+    }
+    return NULL;
+  }
+
+  Klass* klass = java_lang_Class::as_Klass(mirror);
+  assert(klass->oop_is_instance() || klass->oop_is_objArray() ||
+    klass->oop_is_typeArray(), "Bad Klass");
+
+  oop module;
+  if (klass->oop_is_instance()) {
+    module = java_lang_Class::module(mirror);
+  }
+  else if (klass->oop_is_objArray()) {
+    ObjArrayKlass* obj_arr_klass = ObjArrayKlass::cast(klass);
+    Klass* bottom_klass = obj_arr_klass->bottom_klass();
+    module = java_lang_Class::module(bottom_klass->java_mirror());
+  }
+  else if (klass->oop_is_typeArray()) {
+    Klass* obj_k = SystemDictionary::Object_klass();
+    module = java_lang_Class::module(obj_k->java_mirror());
+  }
+
+  if (TraceModules) {
+    ResourceMark rm;
+    if (module != NULL) {
+      oop module_name = java_lang_reflect_Module::name(module);
+      tty->print("[get_module(): module ");
+      java_lang_String::print(module_name, tty);
+    }
+    else {
+      tty->print("[get_module(): unamed module");
+    }
+    tty->print_cr(" for class %s]", klass->external_name());
+  }
+
+  return JNIHandles::make_local(env, module);
+}
+
+jobject Modules::get_module(Symbol* package_name,
+                           Handle h_loader,
+                           TRAPS) {
+
+  const ModuleEntry* const module =
+    get_module_entry_by_package_name(package_name,
+                                     h_loader,
+                                     THREAD);
+
+  return module != NULL ?
+    JNIHandles::make_local(THREAD, module->literal()) : NULL;
+}
+
+void Modules::add_module_package(JNIEnv *env, jobject module, jstring package) {
+  JavaThread *THREAD = JavaThread::thread_from_jni_environment(env);
+  ResourceMark rm;
+
+  if (module == NULL) {
+    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
+              "module is null");
+  }
+  if (package == NULL) {
+    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
+              "package is null");
+  }
+  ModuleEntry* module_entry = get_module_entry(module, CHECK);
+  if (module_entry == NULL) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              "module is invalid");
+  }
+  char *package_name = java_lang_String::as_utf8_string(
+    JNIHandles::resolve_non_null(package));
+  if (package_name == NULL) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Bad package");
+  }
+  if (!verify_package_name(package_name)) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              err_msg("Invalid package name: %s", package_name));
+  }
+
+  if (TraceModules) {
+    ResourceMark rm;
+    tty->print_cr("[add_module_package(): Adding package %s to module %s]",
+                  package_name, module_entry->name()->as_C_string());
+  }
+
+  TempNewSymbol pkg_symbol = SymbolTable::new_symbol(package_name, CHECK);
+  PackageEntryTable* package_table = module_entry->loader()->packages();
+  assert(package_table != NULL, "Missing package_table");
+
+  bool pkg_exists = false;
+  {
+    MutexLocker ml(Module_lock, THREAD);
+
+    // Check that the package does not exist in the class loader's package table.
+    if (!package_table->lookup_only(pkg_symbol)) {
+      PackageEntry* pkg = package_table->locked_create_entry_or_null(pkg_symbol, module_entry);
+      assert(pkg != NULL, "Unable to create a module's package entry");
+    } else {
+      pkg_exists = true;
+    }
+  }
+  if (pkg_exists) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              err_msg("Package %s already exists for class loader", package_name));
+  }
+}
+
+bool Modules::is_package_defined(Symbol* package, Handle h_loader, TRAPS) {
+  return get_package_entry_by_name(package, h_loader, THREAD) != NULL;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/classfile/modules.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -0,0 +1,115 @@
+/*
+* Copyright (c) 2015, 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.
+*
+*/
+
+#ifndef SHARE_VM_CLASSFILE_MODULES_HPP
+#define SHARE_VM_CLASSFILE_MODULES_HPP
+
+#include "memory/allocation.hpp"
+#include "runtime/handles.hpp"
+
+class Symbol;
+
+class Modules : AllStatic {
+
+public:
+  // define_module defines a module containing the specified packages. It binds the
+  // module to its class loader by creating the ModuleEntry record in the
+  // ClassLoader's ModuleEntry table, creates PackageEntry records in the class
+  // loader's PackageEntry table, and, if successful, creates and returns a
+  // java.lang.reflect.Module object.  As in JVM_DefineClass the jstring format
+  // for all package names must use "/" and not "."
+  //
+  //  IllegalArgumentExceptions are thrown for the following :
+  // * Class loader already has a module with that name
+  // * Class loader has already defined types for any of the module's packages
+  // * Module_name is 'java.base'
+  // * Module_name is syntactically bad
+  // * Packages contains an illegal package name
+  // * Packages contains a duplicate package name
+  // * A package already exists in another module for this class loader
+  // * Class loader is not a subclass of java.lang.ClassLoader
+  //  NullPointerExceptions are thrown if module is null.
+  static void define_module(JNIEnv *env, jobject module, jstring version,
+                             jstring location, jobjectArray packages);
+
+  // This either does a qualified export of package in module from_module to module
+  // to_module or, if to_module is null, does an unqualified export of package.
+  // The format for the package name must use "/' not ".".
+  //
+  // Error conditions causing IlegalArgumentException to be throw :
+  // * Module from_module does not exist
+  // * Module to_module is not null and does not exist
+  // * Package is not syntactically correct
+  // * Package is not defined for from_module's class loader
+  // * Package is not in module from_module.
+  static void add_module_exports(JNIEnv *env, jobject from_module, jstring package, jobject to_module);
+
+  // add_reads_module adds module to_module to the list of modules that from_module
+  // can read.If from_module is the same as to_module then this is a no - op.
+  // An IllegalArgumentException is thrown if either from_module or to_module is null or does not exist.
+  static void add_reads_module(JNIEnv *env, jobject from_module, jobject to_module);
+
+  // can_read_module returns TRUE if module asking_module can read module target_module
+  // or if they are the same module.
+  //
+  // Throws IllegalArgumentException if:
+  // * either asking_module or target_module is not a java.lang.reflect.Module
+  static jboolean can_read_module(JNIEnv *env, jobject asking_module, jobject target_module);
+
+  // If package is valid then this returns TRUE if module from_module exports
+  // package to module to_module, if from_module and to_module are the same
+  // module, or if package is exported without qualification.
+  //
+  // IllegalArgumentException is throw if:
+  // * Either to_module or from_module does not exist
+  // * package is syntactically incorrect
+  // * package is not in from_module
+  static jboolean is_exported_to_module(JNIEnv *env, jobject from_module, jstring package, jobject to_module);
+
+  // Return the java.lang.reflect.Module object for this class object.
+  static jobject get_module(JNIEnv *env, jclass clazz);
+
+  // If package is defined by loader, return the
+  // java.lang.reflect.Module object for the module in which the package is defined.
+  // Returns NULL if package is invalid or not defined by loader.
+  static jobject get_module(Symbol* package_name, Handle h_loader, TRAPS);
+
+  // This adds package to module.
+  // It throws IllegalArgumentException if:
+  // * Module is bad
+  // * Package is not syntactically correct
+  // * Package is already defined for module's class loader.
+  static void add_module_package(JNIEnv *env, jobject module, jstring package);
+
+  // Return TRUE if package_name is syntactically valid, false otherwise.
+  static bool verify_package_name(char *package_name);
+
+  // Return TRUE iff package is defined by loader
+  static bool is_package_defined(Symbol* package_name, Handle h_loader, TRAPS);
+
+  static const char* default_version() { return "9.0"; }
+
+};
+
+#endif // SHARE_VM_CLASSFILE_MODULES_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/classfile/packageEntry.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -0,0 +1,305 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "classfile/moduleEntry.hpp"
+#include "classfile/packageEntry.hpp"
+#include "memory/resourceArea.hpp"
+#include "oops/symbol.hpp"
+#include "runtime/handles.inline.hpp"
+#include "trace/traceMacros.hpp"
+#include "utilities/events.hpp"
+#include "utilities/growableArray.hpp"
+#include "utilities/hashtable.inline.hpp"
+
+// Return true if this package is exported to m.
+bool PackageEntry::is_qexported_to(ModuleEntry* m) const {
+  assert(m != NULL, "No module to lookup in this package's qualified exports list");
+  MutexLocker m1(Module_lock);
+  if (!_is_exported || _qualified_exports == NULL) {
+    return false;
+  } else {
+    return _qualified_exports->contains(m);
+  }
+}
+
+// Add a module to the package's qualified export list.
+void PackageEntry::add_qexport(ModuleEntry* m) {
+  assert(_is_exported == true, "Adding a qualified export to a package that is not exported");
+  MutexLocker m1(Module_lock);
+  if (_qualified_exports == NULL) {
+    // Lazily create a package's qualified exports list.
+    // Initial size is 43, do not anticipate export lists to be large.
+    _qualified_exports = new (ResourceObj::C_HEAP, mtClass) GrowableArray<ModuleEntry*>(43, true);
+  }
+  _qualified_exports->append_if_missing(m);
+  m->set_pkgs_with_qexports(true);
+}
+
+// Set the package's exported state based on the value of the ModuleEntry.
+void PackageEntry::set_exported(ModuleEntry* m) {
+  if (_exported_pending_delete != NULL) {
+    // The qualified exports lists is pending safepoint deletion, a prior
+    // transition occurred from qualified to unqualified.
+    return;
+  }
+
+  if (m == NULL) {
+    // NULL indicates the package is being unqualifiedly exported
+    if (_is_exported && _qualified_exports != NULL) {
+      // Legit to transition a package from being qualifiedly exported
+      // to unqualified.  Clean up the qualified lists at the next
+      // safepoint.
+      _exported_pending_delete = _qualified_exports;
+    }
+
+    // Mark package as unqualifiedly exported
+    _is_exported = true;
+    _qualified_exports = NULL;
+
+  } else {
+    if (_is_exported && _qualified_exports == NULL) {
+      // An exception could be thrown, but choose to simply ignore.
+      // Illegal to convert an unqualified exported package to be qualifiedly exported
+      return;
+    }
+
+    // Add the exported module
+    _is_exported = true;
+    add_qexport(m);
+  }
+}
+
+// Remove dead module entries within the package's exported list.
+void PackageEntry::purge_qualified_exports() {
+  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
+  if (_qualified_exports != NULL) {
+    // Go backwards because this removes entries that are dead.
+    int len = _qualified_exports->length();
+    for (int idx = len - 1; idx >= 0; idx--) {
+      ModuleEntry* module_idx = _qualified_exports->at(idx);
+      ClassLoaderData* cld = module_idx->loader();
+      if (cld->is_unloading()) {
+        _qualified_exports->delete_at(idx);
+      }
+    }
+  }
+}
+
+void PackageEntry::delete_qualified_exports() {
+  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
+  if (_exported_pending_delete != NULL) {
+    // If a transition occurred from qualified to unqualified, the _qualified_exports
+    // field should have been NULL'ed out.
+    assert(_qualified_exports == NULL, "Package's exported pending delete, exported list should not be active");
+    delete _exported_pending_delete;
+  }
+
+  if (_qualified_exports != NULL) {
+    delete _qualified_exports;
+  }
+
+  _exported_pending_delete = NULL;
+  _qualified_exports = NULL;
+}
+
+PackageEntryTable::PackageEntryTable(int table_size)
+  : Hashtable<Symbol*, mtClass>(table_size, sizeof(PackageEntry))
+{
+}
+
+PackageEntryTable::~PackageEntryTable() {
+  assert_locked_or_safepoint(Module_lock);
+
+  // Walk through all buckets and all entries in each bucket,
+  // freeing each entry.
+  for (int i = 0; i < table_size(); ++i) {
+    for (PackageEntry* p = bucket(i); p != NULL;) {
+      PackageEntry* to_remove = p;
+      // read next before freeing.
+      p = p->next();
+
+      // Clean out the C heap allocated qualified exports list first before freeing the entry
+      to_remove->delete_qualified_exports();
+      to_remove->name()->decrement_refcount();
+
+      // Unlink from the Hashtable prior to freeing
+      unlink_entry(to_remove);
+      FREE_C_HEAP_ARRAY(char, to_remove);
+    }
+  }
+  assert(number_of_entries() == 0, "should have removed all entries");
+  assert(new_entry_free_list() == NULL, "entry present on PackageEntryTable's free list");
+  free_buckets();
+}
+
+PackageEntry* PackageEntryTable::new_entry(unsigned int hash, Symbol* name, ModuleEntry* module) {
+  assert_locked_or_safepoint(Module_lock);
+  PackageEntry* entry = (PackageEntry*) NEW_C_HEAP_ARRAY2(char, entry_size(), mtClass, CURRENT_PC);
+
+  // Initialize everything BasicHashtable would
+  entry->set_next(NULL);
+  entry->set_hash(hash);
+  entry->set_literal(name);
+
+  TRACE_INIT_PACKAGE_ID(entry);
+
+  // Initialize fields specific to a PackageEntry
+  entry->init();
+  entry->name()->increment_refcount();
+  if (module == NULL) {
+    // Indicates the unnamed module.
+    // Set the exported state to true because all packages
+    // within the unnamed module are unqualifiedly exported
+    entry->set_exported(true);
+  } else {
+    entry->set_module(module);
+  }
+
+  return entry;
+}
+
+void PackageEntryTable::add_entry(int index, PackageEntry* new_entry) {
+  assert_locked_or_safepoint(Module_lock);
+  Hashtable<Symbol*, mtClass>::add_entry(index, (HashtableEntry<Symbol*, mtClass>*)new_entry);
+}
+
+// Create package in loader's package entry table and return the entry.
+// If entry already exists, return null.  Assume Module lock was taken by caller.
+PackageEntry* PackageEntryTable::locked_create_entry_or_null(Symbol* name, ModuleEntry* module) {
+  assert_locked_or_safepoint(Module_lock);
+  // Check if package already exists.  Return NULL if it does.
+  if (lookup_only(name) != NULL) {
+    return NULL;
+  } else {
+    PackageEntry* entry = new_entry(compute_hash(name), name, module);
+    add_entry(index_for(name), entry);
+    return entry;
+  }
+}
+
+PackageEntry* PackageEntryTable::lookup(Symbol* name, ModuleEntry* module) {
+  PackageEntry* p = lookup_only(name);
+  if (p != NULL) {
+    return p;
+  } else {
+    // If not found, add to table. Grab the PackageEntryTable lock first.
+    MutexLocker ml(Module_lock);
+
+    // Since look-up was done lock-free, we need to check if another thread beat
+    // us in the race to insert the package.
+    PackageEntry* test = lookup_only(name);
+    if (test != NULL) {
+      // A race occurred and another thread introduced the package.
+      return test;
+    } else {
+      PackageEntry* entry = new_entry(compute_hash(name), name, module);
+      add_entry(index_for(name), entry);
+      return entry;
+    }
+  }
+}
+
+PackageEntry* PackageEntryTable::lookup_only(Symbol* name) {
+  int index = index_for(name);
+  for (PackageEntry* p = bucket(index); p != NULL; p = p->next()) {
+    if (p->name()->fast_compare(name) == 0) {
+      return p;
+    }
+  }
+  return NULL;
+}
+
+// Remove dead entries from all packages' exported list
+void PackageEntryTable::purge_all_package_exports() {
+  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
+  for (int i = 0; i < table_size(); i++) {
+    for (PackageEntry* entry = bucket(i);
+                       entry != NULL;
+                       entry = entry->next()) {
+      if (entry->exported_pending_delete()) {
+        // exported list is pending deletion due to a transition
+        // from qualified to unqualified
+        entry->delete_qualified_exports();
+      } else if (entry->is_qual_exported()) {
+        entry->purge_qualified_exports();
+      }
+    }
+  }
+}
+
+#ifndef PRODUCT
+void PackageEntryTable::print() {
+  tty->print_cr("Package Entry Table (table_size=%d, entries=%d)",
+                table_size(), number_of_entries());
+  for (int i = 0; i < table_size(); i++) {
+    for (PackageEntry* probe = bucket(i);
+                              probe != NULL;
+                              probe = probe->next()) {
+      probe->print();
+    }
+  }
+}
+
+void PackageEntry::print() {
+  ResourceMark rm;
+  tty->print_cr("package entry "PTR_FORMAT" name %s module %s is_exported %d next "PTR_FORMAT,
+                p2i(this), name()->as_C_string(),
+                ((module() == NULL) ? "[unnamed]" : module()->name()->as_C_string()),
+                _is_exported, p2i(next()));
+}
+#endif
+
+void PackageEntryTable::verify() {
+  int element_count = 0;
+  for (int index = 0; index < table_size(); index++) {
+    for (PackageEntry* probe = bucket(index);
+                              probe != NULL;
+                              probe = probe->next()) {
+      probe->verify();
+      element_count++;
+    }
+  }
+  guarantee(number_of_entries() == element_count,
+            "Verify of Package Entry Table failed");
+  debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
+}
+
+void PackageEntry::verify() {
+  guarantee(name() != NULL, "A package entry must have a corresponding symbol name.");
+}
+
+// iteration of qualified exports
+void PackageEntry::package_exports_do(ModuleClosure* const f) {
+  assert_locked_or_safepoint(Module_lock);
+  assert(f != NULL, "invariant");
+
+  if (is_qual_exported()) {
+    int qe_len = _qualified_exports->length();
+
+    for (int i = 0; i < qe_len; ++i) {
+      f->do_module(_qualified_exports->at(i));
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/classfile/packageEntry.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ */
+
+#ifndef SHARE_VM_CLASSFILE_PACKAGEENTRY_HPP
+#define SHARE_VM_CLASSFILE_PACKAGEENTRY_HPP
+
+#include "classfile/moduleEntry.hpp"
+#include "oops/symbol.hpp"
+#include "utilities/growableArray.hpp"
+#include "utilities/hashtable.hpp"
+
+// A PackageEntry basically represents a Java package.  It contains:
+//   - Symbol* containing the package's name.
+//   - ModuleEntry* for this package's containing module.
+//     NULL if the package was defined within the unnamed module.
+//   - a growable array containing other module entries that this
+//     package is exported to.
+//   - a flag indicating if package is exported, either qualifiedly or
+//     unqualifiedly.
+//
+// Packages that are:
+//   - not exported:        _qualified_exports = NULL  && _is_exported is false
+//   - qualified exports:   _qualified_exports != NULL && _is_exported is true
+//   - unqualified exports: _qualified_exports = NULL  && _is_exported is true
+//
+class PackageEntry : public HashtableEntry<Symbol*, mtClass> {
+private:
+  ModuleEntry* _module;
+  bool _is_exported;
+  GrowableArray<ModuleEntry*>* _exported_pending_delete; // transitioned from qualified to unqualified, delete at safepoint
+  GrowableArray<ModuleEntry*>* _qualified_exports;
+  TRACE_DEFINE_TRACE_ID_FIELD;
+
+public:
+  void init() {
+    _module = NULL;
+    _is_exported = false;
+    _exported_pending_delete = NULL;
+    _qualified_exports = NULL;
+  }
+
+  // package name
+  Symbol*            name() const               { return literal(); }
+  void               set_name(Symbol* n)        { set_literal(n); }
+
+  // the module containing the package definition
+  ModuleEntry*       module() const             { return _module; }
+  void               set_module(ModuleEntry* m) { _module = m; }
+
+  // package's export state
+  bool               is_exported() const                 { return _is_exported; } // qualifiedly or unqualifiedly exported
+  bool               is_qual_exported() const            { return (_is_exported && (_qualified_exports != NULL)); }
+  bool               is_unqual_exported() const          { return (_is_exported && (_qualified_exports == NULL)); }
+  bool               exported_pending_delete() const     { return (_exported_pending_delete != NULL); }
+
+  void               set_exported(bool e)                { _is_exported = e; }
+  void               set_exported(ModuleEntry* m);
+
+  // returns true if the package is defined in the unnamed module
+  bool               in_unnamed_module() const  { return (_module == NULL); }
+
+  // returns true if the package specifies m as a qualified export
+  bool               is_qexported_to(ModuleEntry* m) const;
+
+  // add the module to the package's qualified exports
+  void               add_qexport(ModuleEntry* m);
+
+  PackageEntry* next() const {
+    return (PackageEntry*)HashtableEntry<Symbol*, mtClass>::next();
+  }
+
+  PackageEntry** next_addr() {
+    return (PackageEntry**)HashtableEntry<Symbol*, mtClass>::next_addr();
+  }
+
+  // iteration of qualified exports
+  void package_exports_do(ModuleClosure* const f);
+
+  TRACE_DEFINE_TRACE_ID_METHODS;
+
+  // Purge dead weak references out of exported list when any given class loader is unloaded.
+  void purge_qualified_exports();
+  void delete_qualified_exports();
+
+  void print() PRODUCT_RETURN;
+  void verify();
+};
+
+// The PackageEntryTable is a Hashtable containing a list of all packages defined
+// by a particular class loader.  Each package is represented as a PackageEntry node.
+// The PackageEntryTable's lookup is lock free.
+//
+class PackageEntryTable : public Hashtable<Symbol*, mtClass> {
+  friend class VMStructs;
+public:
+  enum Constants {
+    _packagetable_entry_size = 1009  // number of entries in package entry table
+  };
+
+private:
+  PackageEntry* new_entry(unsigned int hash, Symbol* name, ModuleEntry* module);
+  void add_entry(int index, PackageEntry* new_entry);
+
+public:
+  PackageEntryTable(int table_size);
+  ~PackageEntryTable();
+
+  int entry_size() const { return BasicHashtable<mtClass>::entry_size(); }
+
+  // Create package in loader's package entry table and return the entry.
+  // If entry already exists, return null.  Assume Module lock was taken by caller.
+  PackageEntry* locked_create_entry_or_null(Symbol* name, ModuleEntry* module);
+
+  // lookup Package with loader's package entry table, if not found add
+  PackageEntry* lookup(Symbol* name, ModuleEntry* module);
+
+  // only lookup Package within loader's package entry table
+  PackageEntry* lookup_only(Symbol* Package);
+
+  PackageEntry* bucket(int i) {
+    return (PackageEntry*)Hashtable<Symbol*, mtClass>::bucket(i);
+  }
+
+  PackageEntry** bucket_addr(int i) {
+    return (PackageEntry**)Hashtable<Symbol*, mtClass>::bucket_addr(i);
+  }
+
+  static unsigned int compute_hash(Symbol* name) {
+    return (unsigned int)(name->identity_hash());
+  }
+
+  int index_for(Symbol* name) const {
+    return hash_to_index(compute_hash(name));
+  }
+
+  // purge dead weak references out of exported list
+  void purge_all_package_exports();
+
+  void print() PRODUCT_RETURN;
+  void verify();
+};
+
+#endif // SHARE_VM_CLASSFILE_PACKAGEENTRY_HPP
--- a/src/share/vm/classfile/systemDictionary.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/systemDictionary.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -27,6 +27,7 @@
 #include "classfile/dictionary.hpp"
 #include "classfile/javaClasses.inline.hpp"
 #include "classfile/loaderConstraints.hpp"
+#include "classfile/packageEntry.hpp"
 #include "classfile/placeholders.hpp"
 #include "classfile/resolutionErrors.hpp"
 #include "classfile/stringTable.hpp"
@@ -46,6 +47,7 @@
 #include "oops/objArrayKlass.hpp"
 #include "oops/objArrayOop.inline.hpp"
 #include "oops/oop.inline.hpp"
+#include "oops/symbol.hpp"
 #include "oops/typeArrayKlass.hpp"
 #include "prims/jvmtiEnvBase.hpp"
 #include "prims/methodHandles.hpp"
@@ -169,7 +171,7 @@
   if (class_loader.is_null()) {
     return false;
   }
-  return (class_loader->klass()->name() == vmSymbols::sun_misc_Launcher_ExtClassLoader());
+  return (class_loader->klass()->name() == vmSymbols::sun_misc_ClassLoaders_ExtClassLoader());
 }
 
 // ----------------------------------------------------------------------------
@@ -1263,22 +1265,81 @@
 
 instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
   instanceKlassHandle nh = instanceKlassHandle(); // null Handle
+
   if (class_loader.is_null()) {
+    int length;
+    TempNewSymbol pkg_name = NULL;
+    PackageEntry* pkg_entry = NULL;
+    bool search_only_bootloader_append = false;
+    ClassLoaderData *loader_data = class_loader_data(class_loader);
+
+    // Find the package in the boot loader's package entry table.
+    const jbyte* pkg_string = InstanceKlass::package_from_name(class_name, length);
+    if (pkg_string != NULL) {
+      pkg_name = SymbolTable::new_symbol((const char*)pkg_string, length, CHECK_(nh));
+      pkg_entry = loader_data->packages()->lookup_only(pkg_name);
+    }
+
+    // Prior to attempting to load the class, enforce the boot loader's
+    // visibility boundaries.
+    if (!Universe::is_module_initialized()) {
+      // During bootstrapping, prior to module initialization, any
+      // class attempting to be loaded must be checked against the
+      // java.base packages in the boot loader's PackageEntryTable.
+      // No class outside of java.base is allowed to be loaded during
+      // this bootstrapping window.
+      if (!DumpSharedSpaces) {
+        if (pkg_entry == NULL || pkg_entry->in_unnamed_module()) {
+          // Class is either in the unnamed package or in
+          // a named package within the unnamed module.  Either
+          // case is outside of java.base, do not attempt to
+          // load the class.
+          return nh;
+        } else {
+          // Check that the class' package is defined within java.base.
+          ModuleEntry* mod_entry = pkg_entry->module();
+          Symbol* mod_entry_name = mod_entry->name();
+          if (mod_entry_name->fast_compare(vmSymbols::java_base()) != 0) {
+            return nh;
+          }
+        }
+      }
+    } else {
+      assert(!DumpSharedSpaces, "Archive dumped after module system initialization");
+      // After the module system has been initialized, check if the class'
+      // package is in a module defined to the boot loader.
+      if (pkg_string == NULL || pkg_entry == NULL || pkg_entry->in_unnamed_module()) {
+        // Class is either in the unnamed package, in a named package
+        // within a module not defined to the boot loader or in a
+        // a named package within the unnamed module.  In all cases,
+        // limit visibility to search for the class only in the boot
+        // loader's append path.
+        search_only_bootloader_append = true;
+      }
+    }
+
+    // Prior to bootstrapping's module initialization, never load a class outside
+    // of the boot loader's module path
+    assert(Universe::is_module_initialized() || DumpSharedSpaces ||
+           !search_only_bootloader_append,
+           "Attempt to load a class outside of boot loader's module path");
 
     // Search the shared system dictionary for classes preloaded into the
     // shared spaces.
     instanceKlassHandle k;
     {
 #if INCLUDE_CDS
-      PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
-      k = load_shared_class(class_name, class_loader, THREAD);
+      if (!search_only_bootloader_append) {
+        PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
+        k = load_shared_class(class_name, class_loader, THREAD);
+      }
 #endif
     }
 
     if (k.is_null()) {
       // Use VM class loader
       PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
-      k = ClassLoader::load_classfile(class_name, CHECK_(nh));
+      k = ClassLoader::load_classfile(class_name, search_only_bootloader_append, CHECK_(nh));
     }
 
     // find_or_define_instance_class may return a different InstanceKlass
@@ -1603,7 +1664,7 @@
 }
 
 
-// Get the next class in the diictionary.
+// Get the next class in the dictionary.
 Klass* SystemDictionary::try_get_next_class() {
   return dictionary()->try_get_next_class();
 }
@@ -1872,6 +1933,12 @@
 
 void SystemDictionary::initialize_preloaded_classes(TRAPS) {
   assert(WK_KLASS(Object_klass) == NULL, "preloaded classes should only be initialized once");
+
+  // Define packages for module java.base from either the exploded build or the
+  // bootmodules.jimage file. This call needs to be done here, after vmSymbols::initialize()
+  // is called but before any classes are pre-loaded.
+  ClassLoader::define_javabase();
+
   // Preload commonly used klasses
   WKID scan = FIRST_WKID;
   // first do Object, then String, Class
--- a/src/share/vm/classfile/systemDictionary.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/systemDictionary.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -136,6 +136,7 @@
   do_klass(Properties_klass,                            java_util_Properties,                      Pre                 ) \
   do_klass(reflect_AccessibleObject_klass,              java_lang_reflect_AccessibleObject,        Pre                 ) \
   do_klass(reflect_Field_klass,                         java_lang_reflect_Field,                   Pre                 ) \
+  do_klass(reflect_Module_klass,                        java_lang_reflect_Module,                  Pre                 ) \
   do_klass(reflect_Parameter_klass,                     java_lang_reflect_Parameter,               Opt                 ) \
   do_klass(reflect_Method_klass,                        java_lang_reflect_Method,                  Pre                 ) \
   do_klass(reflect_Constructor_klass,                   java_lang_reflect_Constructor,             Pre                 ) \
@@ -174,7 +175,7 @@
   do_klass(URLClassLoader_klass,                        java_net_URLClassLoader,                   Pre                 ) \
   do_klass(URL_klass,                                   java_net_URL,                              Pre                 ) \
   do_klass(Jar_Manifest_klass,                          java_util_jar_Manifest,                    Pre                 ) \
-  do_klass(sun_misc_Launcher_klass,                     sun_misc_Launcher,                         Pre                 ) \
+  do_klass(sun_misc_ClassLoaders_klass,                 sun_misc_ClassLoaders,                     Pre                 ) \
   do_klass(CodeSource_klass,                            java_security_CodeSource,                  Pre                 ) \
                                                                                                                          \
   /* It's NULL in non-1.4 JDKs. */                                                                                       \
--- a/src/share/vm/classfile/vmSymbols.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/classfile/vmSymbols.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -48,7 +48,8 @@
 // Mapping function names to values. New entries should be added below.
 
 #define VM_SYMBOLS_DO(template, do_alias)                                                         \
-  /* commonly used class names */                                                                 \
+  /* commonly used class, package, module names */                                                \
+  template(java_base,                                 "java.base")                                \
   template(java_lang_System,                          "java/lang/System")                         \
   template(java_lang_Object,                          "java/lang/Object")                         \
   template(java_lang_Class,                           "java/lang/Class")                          \
@@ -85,6 +86,7 @@
   template(java_lang_reflect_Method,                  "java/lang/reflect/Method")                 \
   template(java_lang_reflect_Constructor,             "java/lang/reflect/Constructor")            \
   template(java_lang_reflect_Field,                   "java/lang/reflect/Field")                  \
+  template(java_lang_reflect_Module,                  "java/lang/reflect/Module")                 \
   template(java_lang_reflect_Parameter,               "java/lang/reflect/Parameter")              \
   template(java_lang_reflect_Array,                   "java/lang/reflect/Array")                  \
   template(java_lang_StringBuffer,                    "java/lang/StringBuffer")                   \
@@ -113,17 +115,23 @@
   template(java_util_Hashtable,                       "java/util/Hashtable")                      \
   template(java_lang_Compiler,                        "java/lang/Compiler")                       \
   template(sun_misc_Signal,                           "sun/misc/Signal")                          \
-  template(sun_misc_Launcher,                         "sun/misc/Launcher")                        \
+  template(sun_misc_ClassLoaders,                     "sun/misc/ClassLoaders")                    \
   template(java_lang_AssertionStatusDirectives,       "java/lang/AssertionStatusDirectives")      \
   template(getBootClassPathEntryForClass_name,        "getBootClassPathEntryForClass")            \
   template(sun_misc_PostVMInitHook,                   "sun/misc/PostVMInitHook")                  \
-  template(sun_misc_Launcher_ExtClassLoader,          "sun/misc/Launcher$ExtClassLoader")         \
+  template(sun_misc_ClassLoaders_ExtClassLoader,      "sun/misc/ClassLoaders$ExtClassLoader")     \
                                                                                                   \
   /* Java runtime version access */                                                               \
   template(sun_misc_Version,                          "sun/misc/Version")                         \
   template(java_runtime_name_name,                    "java_runtime_name")                        \
   template(java_runtime_version_name,                 "java_runtime_version")                     \
                                                                                                   \
+  /* system initialization */                                                                     \
+  template(initPhase1_name,                           "initPhase1")                               \
+  template(initPhase2_name,                           "initPhase2")                               \
+  template(initPhase3_name,                           "initPhase3")                               \
+  template(java_lang_reflect_module_init_signature,   "(Ljava/lang/ClassLoader;Ljava/lang/String;)V") \
+                                                                                                  \
   /* class file format tags */                                                                    \
   template(tag_source_file,                           "SourceFile")                               \
   template(tag_inner_classes,                         "InnerClasses")                             \
@@ -327,7 +335,6 @@
   template(run_finalization_name,                     "runFinalization")                          \
   template(run_finalizers_on_exit_name,               "runFinalizersOnExit")                      \
   template(dispatchUncaughtException_name,            "dispatchUncaughtException")                \
-  template(initializeSystemClass_name,                "initializeSystemClass")                    \
   template(loadClass_name,                            "loadClass")                                \
   template(loadClassInternal_name,                    "loadClassInternal")                        \
   template(get_name,                                  "get")                                      \
@@ -401,6 +408,8 @@
   template(signers_name,                              "signers_name")                             \
   template(loader_data_name,                          "loader_data")                              \
   template(dependencies_name,                         "dependencies")                             \
+  template(loader_name,                               "loader")                                   \
+  template(module_name,                               "module")                                   \
   template(input_stream_void_signature,               "(Ljava/io/InputStream;)V")                 \
   template(getFileURL_name,                           "getFileURL")                               \
   template(getFileURL_signature,                      "(Ljava/io/File;)Ljava/net/URL;")           \
@@ -502,6 +511,7 @@
   template(string_signature,                          "Ljava/lang/String;")                                       \
   template(reference_signature,                       "Ljava/lang/ref/Reference;")                                \
   template(executable_signature,                      "Ljava/lang/reflect/Executable;")                           \
+  template(module_signature,                          "Ljava/lang/reflect/Module;")                               \
   template(concurrenthashmap_signature,               "Ljava/util/concurrent/ConcurrentHashMap;")                 \
   template(String_StringBuilder_signature,            "(Ljava/lang/String;)Ljava/lang/StringBuilder;")            \
   template(int_StringBuilder_signature,               "(I)Ljava/lang/StringBuilder;")                             \
--- a/src/share/vm/interpreter/bytecodeInterpreter.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/interpreter/bytecodeInterpreter.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015, 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
@@ -2260,10 +2260,8 @@
               // Decrement counter at checkcast.
               BI_PROFILE_SUBTYPECHECK_FAILED(objKlass);
               ResourceMark rm(THREAD);
-              const char* objName = objKlass->external_name();
-              const char* klassName = klassOf->external_name();
               char* message = SharedRuntime::generate_class_cast_message(
-                objName, klassName);
+                objKlass, klassOf);
               VM_JAVA_ERROR(vmSymbols::java_lang_ClassCastException(), message, note_classCheck_trap);
             }
             // Profile checkcast with null_seen and receiver.
--- a/src/share/vm/interpreter/interpreterRuntime.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/interpreter/interpreterRuntime.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -360,7 +360,7 @@
 
   ResourceMark rm(thread);
   char* message = SharedRuntime::generate_class_cast_message(
-    thread, obj->klass()->external_name());
+    thread, obj->klass());
 
   if (ProfileTraps) {
     note_trap(thread, Deoptimization::Reason_class_check, CHECK);
--- a/src/share/vm/interpreter/linkResolver.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/interpreter/linkResolver.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -216,18 +216,25 @@
 // Klass resolution
 
 void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
-  if (!Reflection::verify_class_access(ref_klass(),
-                                       sel_klass(),
-                                       true)) {
+  Reflection::VerifyClassAccessResults vca_result =
+    Reflection::verify_class_access(ref_klass(), sel_klass(), true);
+  if (vca_result != Reflection::ACCESS_OK) {
     ResourceMark rm(THREAD);
-    Exceptions::fthrow(
-      THREAD_AND_LOCATION,
-      vmSymbols::java_lang_IllegalAccessError(),
-      "tried to access class %s from class %s",
-      sel_klass->external_name(),
-      ref_klass->external_name()
-    );
-    return;
+    char* msg = Reflection::verify_class_access_msg(ref_klass(), sel_klass(), vca_result);
+    if (msg == NULL) {
+      Exceptions::fthrow(
+        THREAD_AND_LOCATION,
+        vmSymbols::java_lang_IllegalAccessError(),
+        "failed to access class %s from class %s",
+        sel_klass->external_name(),
+        ref_klass->external_name());
+    } else {
+      // Use module specific message returned by verify_class_access_msg().
+      Exceptions::fthrow(
+        THREAD_AND_LOCATION,
+        vmSymbols::java_lang_IllegalAccessError(),
+        "%s", msg);
+    }
   }
 }
 
--- a/src/share/vm/memory/filemap.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/memory/filemap.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -224,6 +224,9 @@
             }
             ent->_filesize = -1;
           } else {
+            // This class path entry is neither a jar file nor a directory.  Set
+            // _filesize to -2 to indicate that it is not a jar file nor a directory.
+            assert(strncmp(name + strlen(name) - 7, ".jimage", 7) == 0, "expect *.jimage file");
             ent->_filesize = -2;
           }
         }
--- a/src/share/vm/memory/filemap.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/memory/filemap.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -46,6 +46,8 @@
   const char *_name;
   time_t _timestamp;          // jar timestamp,  0 if is directory or other
   long   _filesize;           // jar file size, -1 if is directory, -2 if other
+
+  // The _timestamp only gets set for jar files.
   bool is_jar() {
     return _timestamp != 0;
   }
--- a/src/share/vm/memory/universe.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/memory/universe.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -144,6 +144,7 @@
 
 int             Universe::_base_vtable_size = 0;
 bool            Universe::_bootstrapping = false;
+bool            Universe::_module_initialized = false;
 bool            Universe::_fully_initialized = false;
 
 size_t          Universe::_heap_capacity_at_last_gc;
@@ -900,6 +901,10 @@
   Universe::genesis(CATCH);
 }
 
+// Set after initialization of the module runtime, call_initModuleRuntime
+void universe_post_module_init() {
+  Universe::_module_initialized = true;
+}
 
 bool universe_post_init() {
   assert(!is_init_completed(), "Error: initialization not yet completed!");
--- a/src/share/vm/memory/universe.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/memory/universe.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -111,6 +111,7 @@
   friend jint  universe_init();
   friend void  universe2_init();
   friend bool  universe_post_init();
+  friend void  universe_post_module_init();
 
  private:
   // Known classes in the VM
@@ -201,6 +202,7 @@
 
   // Initialization
   static bool _bootstrapping;                         // true during genesis
+  static bool _module_initialized;                    // true after call_initPhase2 called
   static bool _fully_initialized;                     // true after universe_init and initialize_vtables called
 
   // the array of preallocated errors with backtraces
@@ -420,6 +422,7 @@
 
   // Testers
   static bool is_bootstrapping()                      { return _bootstrapping; }
+  static bool is_module_initialized()                 { return _module_initialized; }
   static bool is_fully_initialized()                  { return _fully_initialized; }
 
   static inline bool element_type_should_be_aligned(BasicType type);
--- a/src/share/vm/oops/arrayKlass.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/oops/arrayKlass.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -102,7 +102,7 @@
   ResourceMark rm(THREAD);
   k->initialize_supers(super_klass(), CHECK);
   k->vtable()->initialize_vtable(false, CHECK);
-  java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(NULL), CHECK);
+  java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(NULL), Handle(NULL), CHECK);
 }
 
 GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots) {
--- a/src/share/vm/oops/instanceKlass.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/oops/instanceKlass.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -237,6 +237,7 @@
   init_implementor();
   set_fields(NULL, 0);
   set_constants(NULL);
+  set_package(NULL);
   set_class_loader_data(NULL);
   set_source_file_name_index(0);
   set_source_debug_extension(NULL, 0);
@@ -2352,8 +2353,9 @@
 }
 
 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
+  instanceKlassHandle ik(THREAD, this);
+  ik->set_package(ik->name(), loader_data, CHECK);
   Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
-  instanceKlassHandle ik(THREAD, this);
 
   Array<Method*>* methods = ik->methods();
   int num_methods = methods->length();
@@ -2556,26 +2558,103 @@
   return dest;
 }
 
-// different verisons of is_same_class_package
+const jbyte* InstanceKlass::package_from_name(Symbol* name, int& length) {
+  ResourceMark rm;
+  length = 0;
+  if (name == NULL) {
+    return NULL;
+  } else {
+    const jbyte* base_name = name->base();
+    const jbyte* last_slash = UTF8::strrchr(base_name, name->utf8_length(), '/');
+
+    if (last_slash == NULL) {
+      // No package name
+      return NULL;
+    } else {
+      // Skip over '['s
+      if (*base_name == '[') {
+        do {
+          base_name++;
+        } while (*base_name == '[');
+        if (*base_name != 'L') {
+          // Fully qualified class names should not contain a 'L'.
+          // Set length to -1 to indicate that the package name
+          // could not be obtained due to an error condition.
+          // In this situtation, is_same_class_package returns false.
+          length = -1;
+          return NULL;
+        }
+      }
+
+      // Found the package name, look it up in the symbol table.
+      length = last_slash - base_name;
+      assert(length > 0, "Bad length for package name");
+      return base_name;
+    }
+  }
+}
+
+void InstanceKlass::set_package(Symbol* name, ClassLoaderData* loader, TRAPS) {
+  int length;
+  const jbyte* base_name = package_from_name(name, length);
+
+  if (base_name != NULL && loader != NULL) {
+    TempNewSymbol pkg_name = SymbolTable::new_symbol((const char*)base_name, length, CHECK);
+
+    // Find in class loader's package entry table.
+    _package_entry = loader->packages()->lookup_only(pkg_name);
+
+    // If the package name is not found in the loader's package
+    // entry table, it is an indication that the package has not
+    // been defined. Consider it defined within the unnamed module.
+    if (_package_entry == NULL) {
+      ResourceMark rm;
+      _package_entry = loader->packages()->lookup(pkg_name, NULL);
+      // A package should have been successfully created
+      assert(_package_entry != NULL, err_msg("Package entry for class %s not found, loader %s",
+                                             name->as_C_string(), loader->loader_name()));
+    }
+
+    if (TracePackages) {
+      ResourceMark rm;
+      ModuleEntry* m = _package_entry->module();
+      tty->print_cr("[Setting package: class %s, package = %s, module = %s]",
+                    external_name(),
+                    pkg_name->as_C_string(),
+                    ((m == NULL) ? "[unnamed]" : m->name()->as_C_string()));
+    }
+  }
+}
+
+// different versions of is_same_class_package
 bool InstanceKlass::is_same_class_package(Klass* class2) {
-  Klass* class1 = this;
-  oop classloader1 = InstanceKlass::cast(class1)->class_loader();
-  Symbol* classname1 = class1->name();
+  oop classloader1 = this->class_loader();
+  PackageEntry* classpkg1 = this->package();
 
   if (class2->oop_is_objArray()) {
     class2 = ObjArrayKlass::cast(class2)->bottom_klass();
   }
+
   oop classloader2;
+  PackageEntry* classpkg2;
   if (class2->oop_is_instance()) {
     classloader2 = InstanceKlass::cast(class2)->class_loader();
+    classpkg2 = InstanceKlass::cast(class2)->package();
   } else {
     assert(class2->oop_is_typeArray(), "should be type array");
     classloader2 = NULL;
+    classpkg2 = NULL;
   }
-  Symbol* classname2 = class2->name();
-
-  return InstanceKlass::is_same_class_package(classloader1, classname1,
-                                              classloader2, classname2);
+
+  // Same package is determined by comparing class loader
+  // and package entries. Both must be the same. This rule
+  // applies even to classes that are defined in the unnamed
+  // package, they still must have the same class loader.
+  if ((classloader1 == classloader2) && (classpkg1 == classpkg2)) {
+    return true;
+  }
+
+  return false;
 }
 
 bool InstanceKlass::is_same_class_package(oop classloader2, Symbol* classname2) {
@@ -2601,43 +2680,24 @@
     // The Symbol*'s are in UTF8 encoding. Since we only need to check explicitly
     // for ASCII characters ('/', 'L', '['), we can keep them in UTF8 encoding.
     // Otherwise, we just compare jbyte values between the strings.
-    const jbyte *name1 = class_name1->base();
-    const jbyte *name2 = class_name2->base();
-
-    const jbyte *last_slash1 = UTF8::strrchr(name1, class_name1->utf8_length(), '/');
-    const jbyte *last_slash2 = UTF8::strrchr(name2, class_name2->utf8_length(), '/');
-
-    if ((last_slash1 == NULL) || (last_slash2 == NULL)) {
+    int length1;
+    int length2;
+    const jbyte *name1 = package_from_name(class_name1, length1);
+    const jbyte *name2 = package_from_name(class_name2, length2);
+
+    if ((length1 < 0) || (length2 < 0)) {
+      // error occurred parsing package name.
+      return false;
+    }
+
+    if ((name1 == NULL) || (name2 == NULL)) {
       // One of the two doesn't have a package.  Only return true
       // if the other one also doesn't have a package.
-      return last_slash1 == last_slash2;
-    } else {
-      // Skip over '['s
-      if (*name1 == '[') {
-        do {
-          name1++;
-        } while (*name1 == '[');
-        if (*name1 != 'L') {
-          // Something is terribly wrong.  Shouldn't be here.
-          return false;
-        }
-      }
-      if (*name2 == '[') {
-        do {
-          name2++;
-        } while (*name2 == '[');
-        if (*name2 != 'L') {
-          // Something is terribly wrong.  Shouldn't be here.
-          return false;
-        }
-      }
-
-      // Check that package part is identical
-      int length1 = last_slash1 - name1;
-      int length2 = last_slash2 - name2;
-
-      return UTF8::equal(name1, length1, name2, length2);
+      return name1 == name2;
     }
+
+    // Check that package part is identical
+    return UTF8::equal(name1, length1, name2, length2);
   }
 }
 
@@ -2676,7 +2736,7 @@
   instanceKlassHandle class2(THREAD, class2_oop);
 
   // must be in same package before we try anything else
-  if (!class1->is_same_class_package(class2->class_loader(), class2->name()))
+  if (!class1->is_same_class_package(class2()))
     return false;
 
   // As long as there is an outer1.getEnclosingClass,
--- a/src/share/vm/oops/instanceKlass.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/oops/instanceKlass.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -26,6 +26,8 @@
 #define SHARE_VM_OOPS_INSTANCEKLASS_HPP
 
 #include "classfile/classLoaderData.hpp"
+#include "classfile/packageEntry.hpp"
+#include "classfile/moduleEntry.hpp"
 #include "memory/referenceType.hpp"
 #include "memory/specialized_oop_closures.hpp"
 #include "oops/annotations.hpp"
@@ -155,6 +157,8 @@
  protected:
   // Annotations for this class
   Annotations*    _annotations;
+  // Package this class is defined in
+  PackageEntry*   _package_entry;
   // Array classes holding elements of this class.
   Klass*          _array_klasses;
   // Constant pool for this class.
@@ -400,6 +404,11 @@
   bool is_override(methodHandle super_method, Handle targetclassloader, Symbol* targetclassname, TRAPS);
 
   // package
+  PackageEntry* package() const     { return _package_entry; }
+  ModuleEntry* module() const       { return (in_unnamed_package() ? NULL : _package_entry->module()); }
+  bool in_unnamed_package() const   { return (_package_entry == NULL); }
+  void set_package(PackageEntry* p) { _package_entry = p; }
+  void set_package(Symbol* name, ClassLoaderData* loader, TRAPS);
   bool is_same_class_package(Klass* class2);
   bool is_same_class_package(oop classloader2, Symbol* classname2);
   static bool is_same_class_package(oop class_loader1, Symbol* class_name1, oop class_loader2, Symbol* class_name2);
@@ -785,7 +794,7 @@
 
   // support for stub routines
   static ByteSize init_state_offset()  { return in_ByteSize(offset_of(InstanceKlass, _init_state)); }
-  TRACE_DEFINE_OFFSET;
+  TRACE_DEFINE_KLASS_TRACE_ID_OFFSET;
   static ByteSize init_thread_offset() { return in_ByteSize(offset_of(InstanceKlass, _init_thread)); }
 
   // subclass/subinterface checks
@@ -986,6 +995,7 @@
 
   // Naming
   const char* signature_name() const;
+  static const jbyte* package_from_name(Symbol* name, int& length);
 
   // Iterators
   int oop_oop_iterate(oop obj, ExtendedOopClosure* blk) {
--- a/src/share/vm/oops/klass.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/oops/klass.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -25,6 +25,7 @@
 #include "precompiled.hpp"
 #include "classfile/javaClasses.hpp"
 #include "classfile/dictionary.hpp"
+#include "classfile/packageEntry.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
 #include "gc_implementation/shared/markSweep.inline.hpp"
@@ -184,7 +185,7 @@
   set_subklass(NULL);
   set_next_sibling(NULL);
   set_next_link(NULL);
-  TRACE_INIT_ID(this);
+  TRACE_INIT_KLASS_ID(this);
 
   set_prototype_header(markOopDesc::prototype());
   set_biased_lock_revocation_count(0);
@@ -350,7 +351,6 @@
   return NULL;
 }
 
-
 InstanceKlass* Klass::superklass() const {
   assert(super() == NULL || super()->oop_is_instance(), "must be instance klass");
   return _super == NULL ? NULL : InstanceKlass::cast(_super);
@@ -511,7 +511,7 @@
 }
 
 void Klass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
-  TRACE_INIT_ID(this);
+  TRACE_INIT_KLASS_ID(this);
   // If an exception happened during CDS restore, some of these fields may already be
   // set.  We leave the class on the CLD list, even if incomplete so that we don't
   // modify the CLD list outside a safepoint.
@@ -529,7 +529,15 @@
   // gotten an OOM later but keep the mirror if it was created.
   if (java_mirror() == NULL) {
     Handle loader = loader_data->class_loader();
-    java_lang_Class::create_mirror(this, loader, protection_domain, CHECK);
+    ModuleEntry* module_entry = NULL;
+    // Obtain klass' module.
+    if (oop_is_instance()) {
+      InstanceKlass* ik = (InstanceKlass*) this;
+      module_entry = ik->module();
+    }
+    // Obtain j.l.r.Module if available
+    Handle class_module(THREAD, ((module_entry == NULL) ? (oop)NULL : module_entry->module()));
+    java_lang_Class::create_mirror(this, loader, class_module, protection_domain, CHECK);
   }
 }
 
--- a/src/share/vm/oops/klass.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/oops/klass.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -142,7 +142,7 @@
   markOop  _prototype_header;   // Used when biased locking is both enabled and disabled for this type
   jint     _biased_lock_revocation_count;
 
-  TRACE_DEFINE_KLASS_TRACE_ID;
+  TRACE_DEFINE_TRACE_ID_FIELD;
 
   // Remembered sets support for the oops in the klasses.
   jbyte _modified_oops;             // Card Table Equivalent (YC/CMS support)
@@ -566,7 +566,7 @@
   jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
   void  set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
 
-  TRACE_DEFINE_KLASS_METHODS;
+  TRACE_DEFINE_TRACE_ID_METHODS;
 
   // garbage collection support
   void oops_do(OopClosure* cl);
--- a/src/share/vm/opto/library_call.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/opto/library_call.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -3075,7 +3075,7 @@
   Node* cls = null_check(argument(1), T_OBJECT);
   Node* kls = load_klass_from_mirror(cls, false, NULL, 0);
   kls = null_check(kls, T_OBJECT);
-  ByteSize offset = TRACE_ID_OFFSET;
+  ByteSize offset = TRACE_KLASS_TRACE_ID_OFFSET;
   Node* insp = basic_plus_adr(kls, in_bytes(offset));
   Node* tvalue = make_load(NULL, insp, TypeLong::LONG, T_LONG, MemNode::unordered);
   Node* bits = longcon(~0x03l); // ignore bit 0 & 1
--- a/src/share/vm/precompiled/precompiled.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/precompiled/precompiled.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -57,7 +57,12 @@
 # include "classfile/classFileParser.hpp"
 # include "classfile/classFileStream.hpp"
 # include "classfile/classLoader.hpp"
+# include "classfile/imageDecompressor.hpp"
+# include "classfile/imageFile.hpp"
 # include "classfile/javaClasses.hpp"
+# include "classfile/moduleEntry.hpp"
+# include "classfile/modules.hpp"
+# include "classfile/packageEntry.hpp"
 # include "classfile/symbolTable.hpp"
 # include "classfile/systemDictionary.hpp"
 # include "classfile/vmSymbols.hpp"
@@ -234,6 +239,7 @@
 # include "utilities/constantTag.hpp"
 # include "utilities/copy.hpp"
 # include "utilities/debug.hpp"
+# include "utilities/endian.hpp"
 # include "utilities/exceptions.hpp"
 # include "utilities/globalDefinitions.hpp"
 # include "utilities/growableArray.hpp"
--- a/src/share/vm/prims/jni.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/prims/jni.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -28,6 +28,7 @@
 #include "classfile/altHashing.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/javaClasses.hpp"
+#include "classfile/modules.hpp"
 #include "classfile/symbolTable.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
@@ -3434,6 +3435,19 @@
   return JNI_OK;
 JNI_END
 
+
+DT_RETURN_MARK_DECL(GetModule, jobject, HOTSPOT_JNI_GETMODULE_RETURN(_ret_ref));
+
+JNI_ENTRY(jobject, jni_GetModule(JNIEnv* env, jclass clazz))
+  JNIWrapper("GetModule");
+  HOTSPOT_JNI_GETMODULE_ENTRY(env, clazz);
+  jobject res;
+  DT_RETURN_MARK(GetModule, jobject, (const jobject&)res);
+  res = Modules::get_module(env, clazz);;
+  return res;
+JNI_END
+
+
 // Structure containing all jni functions
 struct JNINativeInterface_ jni_NativeInterface = {
     NULL,
@@ -3713,7 +3727,11 @@
 
     // New 1_6 features
 
-    jni_GetObjectRefType
+    jni_GetObjectRefType,
+
+    // Module features
+
+    jni_GetModule
 };
 
 
--- a/src/share/vm/prims/jni.h	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/prims/jni.h	Thu Apr 16 21:23:06 2015 -0700
@@ -765,6 +765,11 @@
 
     jobjectRefType (JNICALL *GetObjectRefType)
         (JNIEnv* env, jobject obj);
+
+    /* Module Features */
+
+    jobject (JNICALL *GetModule)
+       (JNIEnv* env, jclass clazz);
 };
 
 /*
@@ -1857,6 +1862,12 @@
         return functions->GetObjectRefType(this, obj);
     }
 
+    /* Module Features */
+
+    jobject GetModule(jclass clazz) {
+        return functions->GetModule(this, clazz);
+    }
+
 #endif /* __cplusplus */
 };
 
--- a/src/share/vm/prims/jniCheck.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/prims/jniCheck.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -1987,7 +1987,17 @@
     return result;
 JNI_END
 
-
+JNI_ENTRY_CHECKED(jobject,
+  checked_jni_GetModule(JNIEnv *env,
+                        jclass clazz))
+    functionEnter(thr);
+    IN_VM(
+        jniCheck::validate_class(thr, clazz, false);
+    )
+    jobject result = UNCHECKED()->GetModule(env,clazz);
+    functionExit(thr);
+    return result;
+JNI_END
 
 /*
  * Structure containing all checked jni functions
@@ -2270,7 +2280,11 @@
 
     // New 1.6 Features
 
-    checked_jni_GetObjectRefType
+    checked_jni_GetObjectRefType,
+
+    // Module Features
+
+    checked_jni_GetModule
 };
 
 
--- a/src/share/vm/prims/jvm.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/prims/jvm.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -24,8 +24,14 @@
 
 #include "precompiled.hpp"
 #include "classfile/classLoader.hpp"
+#include "classfile/classLoaderData.inline.hpp"
+#include "classfile/imageDecompressor.hpp"
+#include "classfile/imageFile.hpp"
 #include "classfile/javaAssertions.hpp"
 #include "classfile/javaClasses.inline.hpp"
+#include "classfile/moduleEntry.hpp"
+#include "classfile/modules.hpp"
+#include "classfile/packageEntry.hpp"
 #include "classfile/stringTable.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
@@ -69,6 +75,7 @@
 #include "utilities/copy.hpp"
 #include "utilities/defaultStream.hpp"
 #include "utilities/dtrace.hpp"
+#include "utilities/endian.hpp"
 #include "utilities/events.hpp"
 #include "utilities/histogram.hpp"
 #include "utilities/macros.hpp"
@@ -435,6 +442,19 @@
     }
   }
 
+  // -Xoverride
+  if (Arguments::override_dir() != NULL) {
+    PUTPROP(props, "jdk.runtime.override", Arguments::override_dir());
+  }
+
+  // Additional module dependences and exports
+  if (AddModuleRequires != NULL) {
+    PUTPROP(props, "jdk.runtime.addModuleRequires", AddModuleRequires);
+  }
+  if (AddModuleExports != NULL) {
+    PUTPROP(props, "jdk.runtime.addModuleExports", AddModuleExports);
+  }
+
   return properties;
 JVM_END
 
@@ -983,6 +1003,39 @@
             (jclass) JNIHandles::make_local(env, k->java_mirror());
 JVM_END
 
+// Module support //////////////////////////////////////////////////////////////////////////////
+
+JVM_ENTRY(void, JVM_DefineModule(JNIEnv *env, jobject module, jstring version, jstring location,
+                                 jobjectArray packages))
+  JVMWrapper("JVM_DefineModule");
+  Modules::define_module(env, module, version, location, packages);
+JVM_END
+
+JVM_ENTRY(void, JVM_AddModuleExports(JNIEnv *env, jobject from_module, jstring package, jobject to_module))
+  JVMWrapper("JVM_AddModuleExports");
+  Modules::add_module_exports(env, from_module, package, to_module);
+JVM_END
+
+JVM_ENTRY (void, JVM_AddReadsModule(JNIEnv *env, jobject from_module, jobject to_module))
+  JVMWrapper("JVM_AddReadsModule");
+  Modules::add_reads_module(env, from_module, to_module);
+JVM_END
+
+JVM_ENTRY(jboolean, JVM_CanReadModule(JNIEnv *env, jobject asking_module, jobject target_module))
+  JVMWrapper("JVM_CanReadModule");
+  return Modules::can_read_module(env, asking_module, target_module);
+JVM_END
+
+JVM_ENTRY(jboolean, JVM_IsExportedToModule(JNIEnv *env, jobject from_module, jstring package, jobject to_module))
+  JVMWrapper("JVM_IsExportedToModule");
+  return Modules::is_exported_to_module(env, from_module, package, to_module);
+JVM_END
+
+JVM_ENTRY (void, JVM_AddModulePackage(JNIEnv *env, jobject module, jstring package))
+  JVMWrapper("JVM_AddModulePackage");
+  Modules::add_module_package(env, module, package);
+JVM_END
+
 
 // Reflection support //////////////////////////////////////////////////////////////////////////////
 
@@ -3702,3 +3755,125 @@
   info->is_attachable = AttachListener::is_attach_supported();
 }
 JVM_END
+
+// jdk.internal.jimage /////////////////////////////////////////////////////////
+
+JNIEXPORT jlong JNICALL
+JVM_ImageOpen(JNIEnv *env, jstring path, jboolean big_endian) {
+  const char *nativePath = env->GetStringUTFChars(path, NULL);
+  ImageFileReader* reader = ImageFileReader::open(nativePath, big_endian != JNI_FALSE);
+  env->ReleaseStringUTFChars(path, nativePath);
+  return ImageFileReader::readerToID(reader);
+}
+
+JNIEXPORT void JNICALL
+JVM_ImageClose(JNIEnv *env, jlong id) {
+  ImageFileReader* reader = ImageFileReader::idToReader(id);
+  ImageFileReader::close(reader);
+}
+
+JNIEXPORT jlong JNICALL
+JVM_ImageGetIndexAddress(JNIEnv *env, jlong id) {
+  ImageFileReader* reader = ImageFileReader::idToReader(id);
+  return (jlong)reader->get_index_address();
+}
+
+JNIEXPORT jlong JNICALL
+JVM_ImageGetDataAddress(JNIEnv *env, jlong id) {
+  ImageFileReader* reader = ImageFileReader::idToReader(id);
+  return MemoryMapImage ? (jlong)reader->get_data_address() : 0L;
+}
+
+JNIEXPORT jboolean JNICALL
+JVM_ImageRead(JNIEnv *env, jlong id, jlong offset,
+              jobject uncompressedBuffer, jlong uncompressed_size) {
+  ImageFileReader* reader = ImageFileReader::idToReader(id);
+  u1* uncompressedAddress = (u1*)env->GetDirectBufferAddress(uncompressedBuffer);
+  return (jboolean)reader->read_at(uncompressedAddress, uncompressed_size,
+                                   reader->get_index_size() + offset);
+}
+
+JNIEXPORT jboolean JNICALL
+JVM_ImageReadCompressed(JNIEnv *env,
+                    jlong id, jlong offset,
+                    jobject compressedBuffer, jlong compressed_size,
+                    jobject uncompressedBuffer, jlong uncompressed_size) {
+  ImageFileReader* reader = ImageFileReader::idToReader(id);
+  u1* compressedAddress = (u1*)env->GetDirectBufferAddress(compressedBuffer);
+  u1* uncompressedAddress = (u1*)env->GetDirectBufferAddress(uncompressedBuffer);
+  bool is_read = reader->read_at(compressedAddress, compressed_size,
+                                 reader->get_index_size() + offset);
+  if (is_read) {
+    const ImageStrings strings = reader->get_strings();
+    ImageDecompressor::decompress_resource(compressedAddress, uncompressedAddress,
+    uncompressed_size, &strings, true);
+  }
+  return (jboolean)is_read;
+}
+
+JNIEXPORT jbyteArray JNICALL
+JVM_ImageGetStringBytes(JNIEnv *env, jlong id, jint offset) {
+  ImageFileReader* reader = ImageFileReader::idToReader(id);
+  ImageStrings strings = reader->get_strings();
+  const char* data = strings.get(offset);
+  size_t size = strlen(data);
+  jbyteArray byteArray = env->NewByteArray((jsize)size);
+  jbyte* rawBytes = env->GetByteArrayElements(byteArray, NULL);
+  memcpy(rawBytes, data, size);
+  env->ReleaseByteArrayElements(byteArray, rawBytes, 0);
+  return byteArray;
+}
+
+static jlongArray image_expand_location(JNIEnv *env, ImageLocation& location) {
+  jlongArray attributes = env->NewLongArray(ImageLocation::ATTRIBUTE_COUNT);
+  jlong* rawAttributes = env->GetLongArrayElements(attributes, NULL);
+  for (int kind = ImageLocation::ATTRIBUTE_END + 1;
+           kind < ImageLocation::ATTRIBUTE_COUNT;
+           kind++) {
+    rawAttributes[kind] = location.get_attribute(kind);
+  }
+  env->ReleaseLongArrayElements(attributes, rawAttributes, 0);
+  return attributes;
+}
+
+JNIEXPORT jlongArray JNICALL
+JVM_ImageGetAttributes(JNIEnv *env, jlong id, jint offset) {
+  ImageFileReader* reader = ImageFileReader::idToReader(id);
+  u1* data = reader->get_location_offset_data(offset);
+  if (!data) return NULL;
+  ImageLocation location(data);
+  return image_expand_location(env, location);
+}
+
+JNIEXPORT jlongArray JNICALL
+JVM_ImageFindAttributes(JNIEnv *env, jlong id, jbyteArray utf8) {
+  ResourceMark rm;
+  ImageFileReader* reader = ImageFileReader::idToReader(id);
+  jsize size = env->GetArrayLength(utf8);
+  char* path = NEW_RESOURCE_ARRAY(char, size + 1);
+  jbyte* rawBytes = env->GetByteArrayElements(utf8, NULL);
+  memcpy(path, rawBytes, size);
+  env->ReleaseByteArrayElements(utf8, rawBytes, 0);
+  path[size] = '\0';
+  u1* data = reader->find_location_data(path);
+  if (!data) return NULL;
+  ImageLocation location(data);
+  if (!reader->verify_location(location, path)) return NULL;
+  return image_expand_location(env, location);
+}
+
+JNIEXPORT jintArray JNICALL
+JVM_ImageAttributeOffsets(JNIEnv *env, jlong id) {
+  ImageFileReader* reader = ImageFileReader::idToReader(id);
+  Endian* endian = reader->endian();
+  u4 length = reader->table_length();
+  u4* offsets_table = reader->offsets_table();
+  jintArray offsets = env->NewIntArray(length);
+  jint* rawOffsets = env->GetIntArrayElements(offsets, NULL);
+  for (u4 i = 0; i < length; i++) {
+    rawOffsets[i] = endian->get(offsets_table[i]);
+  }
+  env->ReleaseIntArrayElements(offsets, rawOffsets, 0);
+  return offsets;
+}
+
--- a/src/share/vm/prims/jvm.h	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/prims/jvm.h	Thu Apr 16 21:23:06 2015 -0700
@@ -390,6 +390,29 @@
                               jboolean verify);
 
 /*
+ * Module support funcions
+ */
+
+JNIEXPORT void JNICALL
+JVM_DefineModule(JNIEnv *env, jobject module, jstring version, jstring location,
+                 jobjectArray packages);
+
+JNIEXPORT void JNICALL
+JVM_AddModuleExports(JNIEnv *env, jobject from_module, jstring package, jobject to_module);
+
+JNIEXPORT void JNICALL
+JVM_AddReadsModule(JNIEnv *env, jobject from_module, jobject to_module);
+
+JNIEXPORT jboolean JNICALL
+JVM_CanReadModule(JNIEnv *env, jobject asking_module, jobject target_module);
+
+JNIEXPORT jboolean JNICALL
+JVM_IsExportedToModule(JNIEnv *env, jobject from_module, jstring package, jobject to_module);
+
+JNIEXPORT void JNICALL
+JVM_AddModulePackage(JNIEnv* env,  jobject module, jstring package);
+
+/*
  * Reflection support functions
  */
 
@@ -568,6 +591,43 @@
 JNIEXPORT jboolean JNICALL
 JVM_SupportsCX8(void);
 
+/*
+ * jdk.internal.jimage
+ */
+
+JNIEXPORT jlong JNICALL
+JVM_ImageOpen(JNIEnv *env, jstring path, jboolean big_endian);
+
+JNIEXPORT void JNICALL
+JVM_ImageClose(JNIEnv *env, jlong id);
+
+JNIEXPORT jlong JNICALL
+JVM_ImageGetIndexAddress(JNIEnv *env, jlong id);
+
+JNIEXPORT jlong JNICALL
+JVM_ImageGetDataAddress(JNIEnv *env,jlong id);
+
+JNIEXPORT jboolean JNICALL
+JVM_ImageRead(JNIEnv *env, jlong id, jlong offset,
+          jobject uncompressedBuffer, jlong uncompressed_size);
+
+JNIEXPORT jboolean JNICALL
+JVM_ImageReadCompressed(JNIEnv *env, jlong id, jlong offset,
+                    jobject compressedBuffer, jlong compressed_size,
+                    jobject uncompressedBuffer, jlong uncompressed_size);
+
+JNIEXPORT jbyteArray JNICALL
+JVM_ImageGetStringBytes(JNIEnv *env, jlong id, jint offset);
+
+JNIEXPORT jlongArray JNICALL
+JVM_ImageGetAttributes(JNIEnv *env, jlong id, jint offset);
+
+JNIEXPORT jlongArray JNICALL
+JVM_ImageFindAttributes(JNIEnv *env, jlong id, jbyteArray utf8);
+
+JNIEXPORT jintArray JNICALL
+JVM_ImageAttributeOffsets(JNIEnv *env, jlong id);
+
 /*************************************************************************
  PART 2: Support for the Verifier and Class File Format Checker
  ************************************************************************/
@@ -878,6 +938,7 @@
 #define JVM_ACC_SYNTHETIC     0x1000  /* compiler-generated class, method or field */
 #define JVM_ACC_ANNOTATION    0x2000  /* annotation type */
 #define JVM_ACC_ENUM          0x4000  /* field is declared as element of enum */
+#define JVM_ACC_MODULE        0x8000  /* module-info class file */
 
 #define JVM_ACC_PUBLIC_BIT        0
 #define JVM_ACC_PRIVATE_BIT       1
--- a/src/share/vm/prims/methodHandles.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/prims/methodHandles.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -1109,9 +1109,9 @@
     if (reference_klass != NULL && reference_klass->oop_is_instance()) {
       // Emulate LinkResolver::check_klass_accessability.
       Klass* caller = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh));
-      if (!Reflection::verify_class_access(caller,
-                                           reference_klass,
-                                           true)) {
+      if (Reflection::verify_class_access(caller,
+                                          reference_klass,
+                                          true) != Reflection::ACCESS_OK) {
         THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), reference_klass->external_name());
       }
     }
--- a/src/share/vm/prims/whitebox.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/prims/whitebox.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -27,6 +27,8 @@
 #include <new>
 
 #include "classfile/classLoaderData.hpp"
+#include "classfile/modules.hpp"
+#include "classfile/imageFile.hpp"
 #include "classfile/stringTable.hpp"
 #include "code/codeCache.hpp"
 #include "jvmtifiles/jvmtiEnv.hpp"
@@ -1098,6 +1100,32 @@
   MetadataFactory::free_array(cld, (Array<u1>*)(uintptr_t)addr);
 WB_END
 
+WB_ENTRY(void, WB_DefineModule(JNIEnv* env, jobject o, jobject module, jstring version, jstring location,
+                                jobjectArray packages))
+  Modules::define_module(env, module, version, location, packages);
+WB_END
+
+WB_ENTRY(void, WB_AddModuleExports(JNIEnv* env, jobject o, jobject from_module, jstring package, jobject to_module))
+  Modules::add_module_exports(env, from_module, package, to_module);
+WB_END
+
+WB_ENTRY(void, WB_AddReadsModule(JNIEnv* env, jobject o, jobject from_module, jobject to_module))
+  Modules::add_reads_module(env, from_module, to_module);
+WB_END
+
+WB_ENTRY(jboolean, WB_CanReadModule(JNIEnv* env, jobject o, jobject asking_module, jobject target_module))
+  return Modules::can_read_module(env, asking_module, target_module);
+WB_END
+
+WB_ENTRY(jboolean, WB_IsExportedToModule(JNIEnv* env, jobject o, jobject from_module, jstring package, jobject to_module))
+  return Modules::is_exported_to_module(env, from_module, package, to_module);
+WB_END
+
+WB_ENTRY(void, WB_AddModulePackage(JNIEnv* env, jobject o, jclass module, jstring package))
+  Modules::add_module_package(env, module, package);
+WB_END
+
+
 WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc))
   if (inc < 0) {
     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
@@ -1125,6 +1153,11 @@
   return (jlong) MetaspaceGC::capacity_until_GC();
 WB_END
 
+WB_ENTRY(jboolean, WB_ReadImageFile(JNIEnv* env, jobject wb, jstring imagefile))
+  const char* filename = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(imagefile));
+  return ImageFileReader::open(filename) != NULL;
+WB_END
+
 WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue))
   Monitor::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ?
                                            Monitor::_safepoint_check_always :
@@ -1411,6 +1444,19 @@
   {CC"getCodeBlob",        CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob        },
   {CC"getThreadStackSize", CC"()J",                   (void*)&WB_GetThreadStackSize },
   {CC"getThreadRemainingStackSize", CC"()J",          (void*)&WB_GetThreadRemainingStackSize },
+  {CC"DefineModule",       CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
+                                                      (void*)&WB_DefineModule },
+  {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
+                                                      (void*)&WB_AddModuleExports },
+  {CC"AddReadsModule",     CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
+                                                      (void*)&WB_AddReadsModule },
+  {CC"CanReadModule",      CC"(Ljava/lang/Object;Ljava/lang/Object;)Z",
+                                                      (void*)&WB_CanReadModule },
+  {CC"IsExportedToModule", CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Z",
+                                                      (void*)&WB_IsExportedToModule },
+  {CC"AddModulePackage",   CC"(Ljava/lang/Object;Ljava/lang/String;)V",
+                                                      (void*)&WB_AddModulePackage },
+  {CC"readImageFile",     CC"(Ljava/lang/String;)Z",  (void*)&WB_ReadImageFile },
   {CC"assertMatchingSafepointCalls", CC"(ZZ)V",       (void*)&WB_AssertMatchingSafepointCalls },
   {CC"isMonitorInflated",  CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
--- a/src/share/vm/runtime/arguments.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/arguments.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -86,6 +86,8 @@
 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
 int    Arguments::_sun_java_launcher_pid        = -1;
 bool   Arguments::_sun_java_launcher_is_altjvm  = false;
+const char*  Arguments::_override_dir           = NULL;
+int    Arguments::_bootclassloader_append_index = -1;
 
 // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;
@@ -108,6 +110,7 @@
 SystemProperty *Arguments::_java_home = NULL;
 SystemProperty *Arguments::_java_class_path = NULL;
 SystemProperty *Arguments::_sun_boot_class_path = NULL;
+SystemProperty *Arguments::_jdk_boot_class_path_append = NULL;
 
 char* Arguments::_ext_dirs = NULL;
 
@@ -199,6 +202,7 @@
   _java_library_path = new SystemProperty("java.library.path", NULL,  true);
   _java_home =  new SystemProperty("java.home", NULL,  true);
   _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL,  true);
+  _jdk_boot_class_path_append = new SystemProperty("jdk.boot.class.path.append", NULL, true);
 
   _java_class_path = new SystemProperty("java.class.path", "",  true);
 
@@ -207,8 +211,11 @@
   PropertyList_add(&_system_properties, _java_library_path);
   PropertyList_add(&_system_properties, _java_home);
   PropertyList_add(&_system_properties, _java_class_path);
+  // Delete the next line to set property sun.boot.class.path to NULL.
   PropertyList_add(&_system_properties, _sun_boot_class_path);
 
+  PropertyList_add(&_system_properties, _jdk_boot_class_path_append);
+
   // Set OS specific system properties values
   os::init_system_properties_values();
 }
@@ -391,7 +398,7 @@
   // Array indices for the items that make up the sysclasspath.  All except the
   // base are allocated in the C heap and freed by this class.
   enum {
-    _scp_prefix,        // from -Xbootclasspath/p:...
+    _scp_prefix,        // was -Xbootclasspath/p:...
     _scp_base,          // the default sysclasspath
     _scp_suffix,        // from -Xbootclasspath/a:...
     _scp_nitems         // the number of items, must be last.
@@ -459,6 +466,10 @@
   // Get the lengths.
   int i;
   for (i = 0; i < _scp_nitems; ++i) {
+    if (i == _scp_suffix) {
+      // Record index of boot loader's append path.
+      Arguments::set_bootclassloader_append_index((int)total_len);
+    }
     if (_items[i] != NULL) {
       lengths[i] = strlen(_items[i]);
       // Include space for the separator char (or a NULL for the last item).
@@ -2721,16 +2732,18 @@
       JavaAssertions::setSystemClassDefault(enable);
     // -bootclasspath:
     } else if (match_option(option, "-Xbootclasspath:", &tail)) {
-      scp_p->reset_path(tail);
-      *scp_assembly_required_p = true;
+        jio_fprintf(defaultStream::output_stream(),
+          "-Xbootclasspath is no longer a supported option.\n");
+        return JNI_EINVAL;
     // -bootclasspath/a:
     } else if (match_option(option, "-Xbootclasspath/a:", &tail)) {
       scp_p->add_suffix(tail);
       *scp_assembly_required_p = true;
     // -bootclasspath/p:
     } else if (match_option(option, "-Xbootclasspath/p:", &tail)) {
-      scp_p->add_prefix(tail);
-      *scp_assembly_required_p = true;
+        jio_fprintf(defaultStream::output_stream(),
+          "-Xbootclasspath/p is no longer a supported option.\n");
+        return JNI_EINVAL;
     // -Xrun
     } else if (match_option(option, "-Xrun", &tail)) {
       if (tail != NULL) {
@@ -3062,6 +3075,15 @@
       } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) {
         return JNI_EINVAL;
       }
+    // -Xoverride
+    } else if (match_option(option, "-Xoverride:", &tail)) {
+      size_t len = strlen(tail);
+      char* dir = NEW_C_HEAP_ARRAY(char, len+16, mtInternal);
+      sprintf(dir, "%s%sjava.base", tail, os::file_separator());
+      scp_p->add_prefix(dir);
+      *scp_assembly_required_p = true;
+      dir[len] = '\0';
+      set_override_dir(dir);
     // -Xdebug
     } else if (match_option(option, "-Xdebug")) {
       // note this flag has been used, then ignore
@@ -3334,6 +3356,18 @@
   return JNI_OK;
 }
 
+// Set property jdk.boot.class.path.append to the contents of the bootclasspath
+// that follows either the jimage file or exploded module directories.  The
+// property will contain -Xbootclasspath/a and/or jvmti appended additions.
+void Arguments::set_jdkbootclasspath_append() {
+  char *sysclasspath = get_sysclasspath();
+  assert(sysclasspath != NULL, "NULL sysclasspath");
+  int bcp_a_idx = bootclassloader_append_index();
+  if (bcp_a_idx != -1 && bcp_a_idx < (int)strlen(sysclasspath)) {
+    _jdk_boot_class_path_append->set_value(sysclasspath + bcp_a_idx);
+  }
+}
+
 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
 //
 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
@@ -3464,6 +3498,11 @@
   if (scp_assembly_required) {
     // Assemble the bootclasspath elements into the final path.
     Arguments::set_sysclasspath(scp_p->combined_path());
+  } else {
+    // At this point in sysclasspath processing anything
+    // added would be considered in the boot loader's append path.
+    // Record this index, including +1 for the file separator character.
+    Arguments::set_bootclassloader_append_index(((int)strlen(Arguments::get_sysclasspath()))+1);
   }
 
   // This must be done after all arguments have been processed.
@@ -3626,6 +3665,11 @@
 
 void Arguments::set_shared_spaces_flags() {
   if (DumpSharedSpaces) {
+    if (Arguments::override_dir() != NULL) {
+      vm_exit_during_initialization(
+        "Cannot use -Xoverride when dumping the shared archive.", NULL);
+    }
+
     if (RequireSharedSpaces) {
       warning("cannot dump shared archive while using shared archive");
     }
--- a/src/share/vm/runtime/arguments.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/arguments.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -259,6 +259,7 @@
   static SystemProperty *_java_home;
   static SystemProperty *_java_class_path;
   static SystemProperty *_sun_boot_class_path;
+  static SystemProperty *_jdk_boot_class_path_append;
 
   // temporary: to emit warning if the default ext dirs are not empty.
   // remove this variable when the warning is no longer needed.
@@ -283,7 +284,7 @@
   // Value of the conservative maximum heap alignment needed
   static size_t  _conservative_max_heap_alignment;
 
-  static uintx _min_heap_size;
+  static uintx  _min_heap_size;
 
   // Used to store original flag values
   static uintx _min_heap_free_ratio;
@@ -312,6 +313,15 @@
   static void set_java_compiler(bool arg) { _java_compiler = arg; }
   static bool java_compiler()   { return _java_compiler; }
 
+  // Capture the index location of -Xbootclasspath\a within sysclasspath.
+  // Used when setting up the bootstrap search path in order to
+  // mark the boot loader's append path observability boundary.
+  static int _bootclassloader_append_index;
+
+  // -Xoverride flag
+  static const char* _override_dir;
+  static void set_override_dir(const char* dir) { _override_dir = dir; }
+
   // -Xdebug flag
   static bool _xdebug_mode;
   static void set_xdebug_mode(bool arg) { _xdebug_mode = arg; }
@@ -533,6 +543,17 @@
   static size_t min_heap_size()             { return _min_heap_size; }
   static void  set_min_heap_size(size_t v)  { _min_heap_size = v;  }
 
+  // -Xbootclasspath/a
+  static int  bootclassloader_append_index() {
+    return _bootclassloader_append_index;
+  }
+  static void set_bootclassloader_append_index(int value) {
+    _bootclassloader_append_index = value;
+  }
+
+  // -Xoverride
+  static const char* override_dir()         { return _override_dir; }
+
   // Returns the original values of -XX:MinHeapFreeRatio and -XX:MaxHeapFreeRatio
   static uintx min_heap_free_ratio()        { return _min_heap_free_ratio; }
   static uintx max_heap_free_ratio()        { return _max_heap_free_ratio; }
@@ -593,8 +614,15 @@
   static void set_java_home(char *value) { _java_home->set_value(value); }
   static void set_library_path(char *value) { _java_library_path->set_value(value); }
   static void set_ext_dirs(char *value)     { _ext_dirs = os::strdup_check_oom(value); }
-  static void set_sysclasspath(char *value) { _sun_boot_class_path->set_value(value); }
-  static void append_sysclasspath(const char *value) { _sun_boot_class_path->append_value(value); }
+  static void set_jdkbootclasspath_append();
+  static void set_sysclasspath(char *value) {
+    _sun_boot_class_path->set_value(value);
+    set_jdkbootclasspath_append();
+  }
+  static void append_sysclasspath(const char *value) {
+    _sun_boot_class_path->append_value(value);
+    set_jdkbootclasspath_append();
+  }
 
   static char* get_java_home() { return _java_home->value(); }
   static char* get_dll_dir() { return _sun_boot_library_path->value(); }
@@ -605,7 +633,7 @@
 
 
   // Operation modi
-  static Mode mode()                { return _mode; }
+  static Mode mode()                        { return _mode; }
   static bool is_interpreter_only() { return mode() == _int; }
 
 
--- a/src/share/vm/runtime/frame.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/frame.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -644,6 +644,13 @@
         m->name_and_sig_as_C_string(buf, buflen);
         st->print("j  %s", buf);
         st->print("+%d", this->interpreter_frame_bci());
+        ModuleEntry* module = m->method_holder()->module();
+        if (module != NULL) {
+          module->name()->as_C_string(buf, buflen);
+          st->print(" %s", buf);
+          module->version()->as_C_string(buf, buflen);
+          st->print("@%s", buf);
+        }
       } else {
         st->print("j  " PTR_FORMAT, pc());
       }
@@ -661,10 +668,19 @@
       Method* m = nm->method();
       if (m != NULL) {
         m->name_and_sig_as_C_string(buf, buflen);
-        st->print("J %d%s %s %s (%d bytes) @ " PTR_FORMAT " [" PTR_FORMAT "+0x%x]",
+        st->print("J %d%s %s %s",
                   nm->compile_id(), (nm->is_osr_method() ? "%" : ""),
                   ((nm->compiler() != NULL) ? nm->compiler()->name() : ""),
-                  buf, m->code_size(), _pc, _cb->code_begin(), _pc - _cb->code_begin());
+                  buf);
+        ModuleEntry* module = m->method_holder()->module();
+        if (module != NULL) {
+          module->name()->as_C_string(buf, buflen);
+          st->print(" %s", buf);
+          module->version()->as_C_string(buf, buflen);
+          st->print("@%s", buf);
+        }
+        st->print(" (%d bytes) @ " PTR_FORMAT " [" PTR_FORMAT "+0x%x]",
+                  m->code_size(), _pc, _cb->code_begin(), _pc - _cb->code_begin());
       } else {
         st->print("J  " PTR_FORMAT, pc());
       }
--- a/src/share/vm/runtime/globals.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/globals.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -1005,6 +1005,9 @@
   product(bool, AlwaysRestoreFPU, false,                                    \
           "Restore the FPU control word after every JNI call (expensive)")  \
                                                                             \
+  product(bool, MemoryMapImage, true,                                       \
+          "Memory map entire runtime image")                                \
+                                                                            \
   diagnostic(bool, PrintCompilation2, false,                                \
           "Print additional statistics per compilation")                    \
                                                                             \
@@ -1316,6 +1319,15 @@
           "Decay time (in milliseconds) to re-enable bulk rebiasing of a "  \
           "type after previous bulk rebias")                                \
                                                                             \
+  develop(bool, UseModuleBoundaries, true,                                  \
+          "Use access control to enforce module boundaries")                \
+                                                                            \
+  product(ccstr, AddModuleRequires, NULL,                                   \
+          "Additional module dependences, for example jtreg=java.xml")      \
+                                                                            \
+  product(ccstr, AddModuleExports, NULL,                                    \
+          "Additional module exports, for example java.base/sun.misc")      \
+                                                                            \
   /* tracing */                                                             \
                                                                             \
   notproduct(bool, TraceRuntimeCalls, false,                                \
@@ -1424,6 +1436,9 @@
   product(bool, TraceMonitorInflation, false,                               \
           "Trace monitor inflation in JVM")                                 \
                                                                             \
+  product(bool, TraceAccessControlErrors, false,                            \
+          "Trace access control errors")                                    \
+                                                                            \
   /* gc */                                                                  \
                                                                             \
   product(bool, UseSerialGC, false,                                         \
@@ -2330,6 +2345,12 @@
   develop(bool, TraceClassLoaderData, false,                                \
           "Trace class loader loader_data lifetime")                        \
                                                                             \
+  develop(bool, TraceModules, false,                                        \
+          "Trace module creation and lifetime")                             \
+                                                                            \
+  develop(bool, TracePackages, false,                                       \
+          "Trace package creation and lifetime")                            \
+                                                                            \
   product(size_t, InitialBootClassLoaderMetaspaceSize,                      \
           NOT_LP64(2200*K) LP64_ONLY(4*M),                                  \
           "Initial size of the boot class loader data metaspace")           \
--- a/src/share/vm/runtime/mutexLocker.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/mutexLocker.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -41,6 +41,7 @@
 Mutex*   Patching_lock                = NULL;
 Monitor* SystemDictionary_lock        = NULL;
 Mutex*   PackageTable_lock            = NULL;
+Mutex*   Module_lock                  = NULL;
 Mutex*   CompiledIC_lock              = NULL;
 Mutex*   InlineCacheBuffer_lock       = NULL;
 Mutex*   VMStatistic_lock             = NULL;
@@ -100,6 +101,8 @@
 Mutex*   ExceptionCache_lock          = NULL;
 Monitor* ObjAllocPost_lock            = NULL;
 Mutex*   OsrList_lock                 = NULL;
+Mutex*   ImageFileReaderTable_lock    = NULL;
+
 #ifndef PRODUCT
 Mutex*   FullGCALot_lock              = NULL;
 #endif
@@ -216,7 +219,8 @@
   def(JmethodIdCreation_lock       , Mutex  , leaf,        true,  Monitor::_safepoint_check_always);     // used for creating jmethodIDs.
 
   def(SystemDictionary_lock        , Monitor, leaf,        true,  Monitor::_safepoint_check_always);     // lookups done by VM thread
-  def(PackageTable_lock            , Mutex  , leaf,        false, Monitor::_safepoint_check_always);
+  def(PackageTable_lock            , Mutex  , nonleaf,     false, Monitor::_safepoint_check_always);
+  def(Module_lock                  , Mutex  , nonleaf  ,   true,  Monitor::_safepoint_check_always);
   def(InlineCacheBuffer_lock       , Mutex  , leaf,        true,  Monitor::_safepoint_check_always);
   def(VMStatistic_lock             , Mutex  , leaf,        false, Monitor::_safepoint_check_always);
   def(ExpandHeap_lock              , Mutex  , leaf,        true,  Monitor::_safepoint_check_always);     // Used during compilation by VM thread
@@ -227,6 +231,7 @@
   def(ProfilePrint_lock            , Mutex  , leaf,        false, Monitor::_safepoint_check_always);     // serial profile printing
   def(ExceptionCache_lock          , Mutex  , leaf,        false, Monitor::_safepoint_check_always);     // serial profile printing
   def(OsrList_lock                 , Mutex  , leaf,        true,  Monitor::_safepoint_check_never);
+  def(ImageFileReaderTable_lock    , Mutex  , leaf,        true,  Monitor::_safepoint_check_never);      // synchronize image readers open/close
   def(Debug1_lock                  , Mutex  , leaf,        true,  Monitor::_safepoint_check_never);
 #ifndef PRODUCT
   def(FullGCALot_lock              , Mutex  , leaf,        false, Monitor::_safepoint_check_always);     // a lock to make FullGCALot MT safe
--- a/src/share/vm/runtime/mutexLocker.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/mutexLocker.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -33,6 +33,7 @@
 extern Mutex*   Patching_lock;                   // a lock used to guard code patching of compiled code
 extern Monitor* SystemDictionary_lock;           // a lock on the system dictionary
 extern Mutex*   PackageTable_lock;               // a lock on the class loader package table
+extern Mutex*   Module_lock;                     // a lock on module related data structures
 extern Mutex*   CompiledIC_lock;                 // a lock used to guard compiled IC patching and access
 extern Mutex*   InlineCacheBuffer_lock;          // a lock used to guard the InlineCacheBuffer
 extern Mutex*   VMStatistic_lock;                // a lock used to guard statistics count increment
@@ -102,6 +103,7 @@
 extern Mutex*   ProfilePrint_lock;               // a lock used to serialize the printing of profiles
 extern Mutex*   ExceptionCache_lock;             // a lock used to synchronize exception cache updates
 extern Mutex*   OsrList_lock;                    // a lock used to serialize access to OSR queues
+extern Mutex*   ImageFileReaderTable_lock;       // a long used to synchronize image readers open/close
 
 #ifndef PRODUCT
 extern Mutex*   FullGCALot_lock;                 // a lock to make FullGCALot MT safe
--- a/src/share/vm/runtime/os.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/os.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -1167,67 +1167,14 @@
     return formatted_path;
 }
 
-// returns a PATH of all entries in the given directory that do not start with a '.'
-static char* expand_entries_to_path(char* directory, char fileSep, char pathSep) {
-  DIR* dir = os::opendir(directory);
-  if (dir == NULL) return NULL;
-
-  char* path = NULL;
-  size_t path_len = 0;  // path length including \0 terminator
-
-  size_t directory_len = strlen(directory);
-  struct dirent *entry;
-  char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal);
-  while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
-    const char* name = entry->d_name;
-    if (name[0] == '.') continue;
-
-    size_t name_len = strlen(name);
-    size_t needed = directory_len + name_len + 2;
-    size_t new_len = path_len + needed;
-    if (path == NULL) {
-      path = NEW_C_HEAP_ARRAY(char, new_len, mtInternal);
-    } else {
-      path = REALLOC_C_HEAP_ARRAY(char, path, new_len, mtInternal);
-    }
-    if (path == NULL)
-      break;
-
-    // append <pathSep>directory<fileSep>name
-    char* p = path;
-    if (path_len > 0) {
-      p += (path_len -1);
-      *p = pathSep;
-      p++;
-    }
-
-    strcpy(p, directory);
-    p += directory_len;
-
-    *p = fileSep;
-    p++;
-
-    strcpy(p, name);
-    p += name_len;
-
-    path_len = new_len;
-  }
-
-  FREE_C_HEAP_ARRAY(char, dbuf);
-  os::closedir(dir);
-
-  return path;
-}
-
 bool os::set_boot_path(char fileSep, char pathSep) {
   const char* home = Arguments::get_java_home();
   int home_len = (int)strlen(home);
 
-  char* sysclasspath = NULL;
   struct stat st;
 
   // modular image if bootmodules.jimage exists
-  char* jimage = format_boot_path("%/lib/modules/bootmodules.jimage", home, home_len, fileSep, pathSep);
+  char* jimage = format_boot_path("%/lib/modules/" BOOT_IMAGE_NAME, home, home_len, fileSep, pathSep);
   if (jimage == NULL) return false;
   bool has_jimage = (os::stat(jimage, &st) == 0);
   if (has_jimage) {
@@ -1237,21 +1184,15 @@
   FREE_C_HEAP_ARRAY(char, jimage);
 
   // check if developer build with exploded modules
-  char* modules_dir = format_boot_path("%/modules", home, home_len, fileSep, pathSep);
-  if (os::stat(modules_dir, &st) == 0) {
-    if ((st.st_mode & S_IFDIR) == S_IFDIR) {
-      sysclasspath = expand_entries_to_path(modules_dir, fileSep, pathSep);
-    }
+  char* base_classes = format_boot_path("%/modules/java.base", home, home_len, fileSep, pathSep);
+  if (base_classes == NULL) return false;
+  if (os::stat(base_classes, &st) == 0) {
+    Arguments::set_sysclasspath(base_classes);
+    return true;
   }
+  FREE_C_HEAP_ARRAY(char, base_classes);
 
-  // fallback to classes
-  if (sysclasspath == NULL)
-    sysclasspath = format_boot_path("%/classes", home, home_len, fileSep, pathSep);
-
-  if (sysclasspath == NULL) return false;
-  Arguments::set_sysclasspath(sysclasspath);
-
-  return true;
+  return false;
 }
 
 /*
--- a/src/share/vm/runtime/os.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/os.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -977,7 +977,6 @@
                                 char pathSep);
   static bool set_boot_path(char fileSep, char pathSep);
   static char** split_path(const char* path, int* n);
-
 };
 
 // Note that "PAUSE" is almost always used with synchronization
--- a/src/share/vm/runtime/reflection.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/reflection.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -24,6 +24,8 @@
 
 #include "precompiled.hpp"
 #include "classfile/javaClasses.hpp"
+#include "classfile/moduleEntry.hpp"
+#include "classfile/packageEntry.hpp"
 #include "classfile/stringTable.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/verifier.hpp"
@@ -411,23 +413,192 @@
 }
 
 
-bool Reflection::verify_class_access(Klass* current_class, Klass* new_class, bool classloader_only) {
+
+/*
+    Type Accessibility check for public types: Callee Type T is accessible to Caller Type S if:
+
+                        Callee T in             Callee T in package PT,
+                        unnamed module          runtime module MT
+ ------------------------------------------------------------------------------------------------
+
+ Caller S in package         YES                  If same classloader/package (PS == PT): YES
+ PS, runtime module MS                            If same runtime module: (MS == MT): YES
+
+                                                  Else if (MS can read MT (Establish readability) &&
+                                                    MT exports PT to MS or to all modules): YES
+
+ ------------------------------------------------------------------------------------------------
+ Caller S in unnamed         YES                   Readability exists because unnamed module
+ module                                                "reads" all modules
+                                                   if (MT exports PT to all modules): YES
+
+ ------------------------------------------------------------------------------------------------
+*/
+Reflection::VerifyClassAccessResults Reflection::verify_class_access(
+  Klass* current_class, Klass* new_class, bool classloader_only) {
+
   // Verify that current_class can access new_class.  If the classloader_only
   // flag is set, we automatically allow any accesses in which current_class
   // doesn't have a classloader.
   if ((current_class == NULL) ||
       (current_class == new_class) ||
-      (new_class->is_public()) ||
       is_same_class_package(current_class, new_class)) {
-    return true;
+    return ACCESS_OK;
   }
   // Allow all accesses from sun/reflect/MagicAccessorImpl subclasses to
   // succeed trivially.
   if (current_class->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
-    return true;
+    return ACCESS_OK;
   }
 
-  return can_relax_access_check_for(current_class, new_class, classloader_only);
+  // module boundaries
+  if (new_class->is_public()) {
+    // Ignore modules for DumpSharedSpaces because we do not have any package
+    // or module information for modules other than java.base.
+    if (!UseModuleBoundaries || DumpSharedSpaces) {
+      return ACCESS_OK;
+    }
+
+    // Find the module entry for current_class, the accessor
+    ModuleEntry* module_from = InstanceKlass::cast(current_class)->module();
+
+    // Find the module entry for new_class, the accessee
+    ModuleEntry* module_to = NULL;
+    if (new_class->oop_is_objArray()) {
+      new_class = ObjArrayKlass::cast(new_class)->bottom_klass();
+    }
+    if (current_class->oop_is_instance()) {
+      module_to = InstanceKlass::cast(new_class)->module();
+    }
+
+    // both in same module or unnamed module.
+    if (module_from == module_to)
+      return ACCESS_OK;
+
+    // Acceptable access to a type in the unamed module.
+    if (module_to == NULL)
+      return ACCESS_OK;
+
+    // Establish readability, check if module_from is allowed to read module_to.
+    if (module_from != NULL && !module_from->can_read(module_to)) {
+      if (TraceAccessControlErrors) {
+        ResourceMark rm;
+        tty->print_cr("Type in module %s (%s) cannot access type in module %s (%s), not readable",
+          module_from->name()->as_C_string(), current_class->external_name(),
+          module_to->name()->as_C_string(), new_class->external_name());
+      }
+      return MODULE_NOT_READABLE;
+    }
+
+    PackageEntry* package_to = InstanceKlass::cast(new_class)->package();
+    assert(package_to != NULL, "can not obtain new_class' package");
+
+    // Once readability is established, if module_to exports T unqualifiedly,
+    // (to all modules), than whether module_from is in the unnamed module
+    // or not does not matter, access is allowed.
+    if (package_to->is_unqual_exported()) {
+      return ACCESS_OK;
+    }
+
+    if (module_from != NULL) {
+      // Check the case where module_from, the requester, is in a named module.
+      // Access is allowed if both 1 & 2 hold:
+      //   1. Readability, module_from can read module_to (established above).
+      //   2. Either module_to exports T to module_from qualifiedly.
+      //      or
+      //      module_to exports T unqualifiedly to all modules (checked above).
+      bool okay = package_to->is_qexported_to(module_from);
+      if (!okay) {
+        if (TraceAccessControlErrors) {
+          ResourceMark rm;
+          tty->print_cr("Type in module %s (%s) cannot access type in module %s (%s), not exported",
+            module_from->name()->as_C_string(), current_class->external_name(),
+            module_to->name()->as_C_string(), new_class->external_name());
+        }
+        return TYPE_NOT_EXPORTED;
+      }
+      return ACCESS_OK;
+    } else {
+      // Check the case where module_from, the requester, is in the unnamed module.
+      // Access is allowed if both 1 & 2 hold:
+      //   1. Readability, unnamed module can read all modules.
+      //   2. module_to exports T unqualifiedly to all modules (checked above).
+      if (TraceAccessControlErrors) {
+        ResourceMark rm;
+        tty->print_cr("Type in the unnamed module (%s) cannot access type in module %s (%s), not unqualifiedly exported",
+          current_class->external_name(), module_to->name()->as_C_string(), new_class->external_name());
+      }
+      return TYPE_NOT_UNQ_EXPORTED;
+    }
+  }
+
+  if (can_relax_access_check_for(current_class, new_class, classloader_only)) {
+    return ACCESS_OK;
+  }
+  return OTHER_PROBLEM;
+}
+
+// Return an error message specific to the specified Klass*'s and result.
+// This function must be called from within a block containing a ResourceMark.
+char* Reflection::verify_class_access_msg(Klass* current_class,
+                                          Klass* new_class,
+                                          VerifyClassAccessResults result) {
+  assert(result != ACCESS_OK, "must be failure result");
+  char * msg = NULL;
+  if (result != OTHER_PROBLEM && new_class != NULL && current_class != NULL) {
+    ModuleEntry* module_to = InstanceKlass::cast(new_class)->module();
+    if (module_to != NULL) {
+      const char * new_class_name = new_class->external_name();
+      const char * current_class_name = current_class->external_name();
+      char * module_to_name = module_to->name()->as_C_string();
+      size_t len = 120 + strlen(current_class_name) + strlen(new_class_name) +
+        strlen(module_to_name);
+
+      if (result == TYPE_NOT_UNQ_EXPORTED) {
+        if (InstanceKlass::cast(new_class)->package() != NULL) {
+          const char * package_name =
+            InstanceKlass::cast(new_class)->package()->name()->as_klass_external_name();
+          len = len + strlen(package_name);
+          msg = NEW_RESOURCE_ARRAY(char, len);
+          jio_snprintf(msg, len - 1,
+            "class %s (in module: unnamed) cannot access class %s (in module: %s), %s is not exported to the unnamed module",
+            current_class_name, new_class_name, module_to_name, package_name);
+        }
+
+      } else {
+        ModuleEntry* module_from = InstanceKlass::cast(current_class)->module();
+        if (module_from != NULL) {
+          char * module_from_name = module_from->name()->as_C_string();
+          len = len + 2 * strlen(module_from_name);
+
+          if (result == MODULE_NOT_READABLE) {
+            len = len + strlen(module_to_name);
+            msg = NEW_RESOURCE_ARRAY(char, len);
+            jio_snprintf(msg, len - 1,
+              "class %s (in module: %s) cannot access class %s (in module: %s), %s cannot read %s",
+              current_class_name, module_from_name, new_class_name,
+              module_to_name, module_from_name, module_to_name);
+
+          } else if (result == TYPE_NOT_EXPORTED) {
+            if (InstanceKlass::cast(new_class)->package() != NULL) {
+              const char * package_name =
+                InstanceKlass::cast(new_class)->package()->name()->as_klass_external_name();
+              len = len + strlen(package_name);
+              msg = NEW_RESOURCE_ARRAY(char, len);
+              jio_snprintf(msg, len - 1,
+                "class %s (in module: %s) cannot access class %s (in module: %s), %s is not exported to %s",
+                current_class_name, module_from_name, new_class_name,
+                module_to_name, package_name, module_from_name);
+            }
+
+          } else {
+            ShouldNotReachHere();
+          }
+        }  // module_from != NULL
+      }
+    }  // module_to != NULL
+  }  // result != OTHER_PROBLEM...
+  return msg;
 }
 
 static bool under_host_klass(InstanceKlass* ik, Klass* host_klass) {
--- a/src/share/vm/runtime/reflection.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/reflection.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -63,6 +63,15 @@
     MAX_DIM           = 255
   };
 
+  // Results returned by verify_class_access()
+  enum VerifyClassAccessResults {
+    ACCESS_OK = 0,
+    MODULE_NOT_READABLE = 1,
+    TYPE_NOT_EXPORTED = 2,
+    TYPE_NOT_UNQ_EXPORTED = 3,
+    OTHER_PROBLEM = 4
+  };
+
   // Boxing. Returns boxed value of appropriate type. Throws IllegalArgumentException.
   static oop box(jvalue* v, BasicType type, TRAPS);
   // Unboxing. Returns type code and sets value.
@@ -83,7 +92,15 @@
   static arrayOop reflect_new_multi_array(oop element_mirror, typeArrayOop dimensions, TRAPS);
 
   // Verification
-  static bool     verify_class_access(Klass* current_class, Klass* new_class, bool classloader_only);
+  static VerifyClassAccessResults verify_class_access(Klass* current_class,
+                                                      Klass* new_class,
+                                                      bool classloader_only);
+
+  // Return an error message specific to the specified Klass*'s and result.
+  // This function must be called from within a block containing a ResourceMark.
+  static char*    verify_class_access_msg(Klass* current_class,
+                                          Klass* new_class,
+                                          VerifyClassAccessResults result);
 
   static bool     verify_field_access(Klass* current_class,
                                       Klass* resolved_class,
--- a/src/share/vm/runtime/sharedRuntime.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/sharedRuntime.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -37,6 +37,8 @@
 #include "interpreter/interpreterRuntime.hpp"
 #include "memory/gcLocker.inline.hpp"
 #include "memory/universe.inline.hpp"
+#include "oops/klass.hpp"
+#include "oops/objArrayKlass.hpp"
 #include "oops/oop.inline.hpp"
 #include "prims/forte.hpp"
 #include "prims/jvmtiExport.hpp"
@@ -1760,28 +1762,57 @@
 }
 JRT_END
 
+// The caller of generate_class_cast_message() (or one of its callers)
+// must use a ResourceMark in order to correctly free the result.
 char* SharedRuntime::generate_class_cast_message(
-    JavaThread* thread, const char* objName) {
+    JavaThread* thread, Klass* caster_klass) {
 
   // Get target class name from the checkcast instruction
   vframeStream vfst(thread, true);
   assert(!vfst.at_end(), "Java frame must exist");
   Bytecode_checkcast cc(vfst.method(), vfst.method()->bcp_from(vfst.bci()));
-  Klass* targetKlass = vfst.method()->constants()->klass_at(
+  Klass* target_klass = vfst.method()->constants()->klass_at(
     cc.index(), thread);
-  return generate_class_cast_message(objName, targetKlass->external_name());
+  return generate_class_cast_message(caster_klass, target_klass);
 }
 
 char* SharedRuntime::generate_class_cast_message(
-    const char* objName, const char* targetKlassName, const char* desc) {
-  size_t msglen = strlen(objName) + strlen(desc) + strlen(targetKlassName) + 1;
+    Klass* caster_klass, Klass* target_klass) {
+
+  const char* caster_klass_name = caster_klass->external_name();
+  Klass* c_klass = caster_klass->oop_is_objArray() ?
+    ObjArrayKlass::cast(caster_klass)->bottom_klass() : caster_klass;
+  ModuleEntry* caster_module;
+  if (c_klass->oop_is_instance()) {
+    caster_module = InstanceKlass::cast(c_klass)->module();
+  } else {
+    caster_module = NULL;
+  }
+  const char* caster_module_name = caster_module == NULL ? "unnamed" :
+    caster_module->name()->as_C_string();
+
+  const char* target_klass_name = target_klass->external_name();
+  Klass* t_klass = target_klass->oop_is_objArray() ?
+    ObjArrayKlass::cast(target_klass)->bottom_klass() : target_klass;
+  ModuleEntry* target_module;
+  if (t_klass->oop_is_instance()) {
+    target_module = InstanceKlass::cast(t_klass)->module();
+  } else {
+    target_module = NULL;
+  }
+  const char* target_module_name = target_module == NULL ? "unnamed" :
+    target_module->name()->as_C_string();
+
+  size_t msglen = strlen(caster_klass_name) + strlen(caster_module_name) +
+     strlen(target_klass_name) + strlen(target_module_name) + 50;
 
   char* message = NEW_RESOURCE_ARRAY(char, msglen);
   if (NULL == message) {
     // Shouldn't happen, but don't cause even more problems if it does
-    message = const_cast<char*>(objName);
+    message = const_cast<char*>(caster_klass_name);
   } else {
-    jio_snprintf(message, msglen, "%s%s%s", objName, desc, targetKlassName);
+    jio_snprintf(message, msglen, "%s (in module: %s) cannot be cast to %s (in module: %s)",
+      caster_klass_name, caster_module_name, target_klass_name, target_module_name);
   }
   return message;
 }
--- a/src/share/vm/runtime/sharedRuntime.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/sharedRuntime.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -274,22 +274,21 @@
   // Fill in the "X cannot be cast to a Y" message for ClassCastException
   //
   // @param thr the current thread
-  // @param name the name of the class of the object attempted to be cast
+  // @param caster_klass the class of the object we are casting
   // @return the dynamically allocated exception message (must be freed
   // by the caller using a resource mark)
   //
   // BCP must refer to the current 'checkcast' opcode for the frame
   // on top of the stack.
-  // The caller (or one of it's callers) must use a ResourceMark
+  // The caller (or one of its callers) must use a ResourceMark
   // in order to correctly free the result.
   //
-  static char* generate_class_cast_message(JavaThread* thr, const char* name);
+  static char* generate_class_cast_message(JavaThread* thr, Klass* caster_klass);
 
   // Fill in the "X cannot be cast to a Y" message for ClassCastException
   //
-  // @param name the name of the class of the object attempted to be cast
-  // @param klass the name of the target klass attempt
-  // @param gripe the specific kind of problem being reported
+  // @param caster_klass the class of the object we are casting
+  // @param target_klass the target klass attempt
   // @return the dynamically allocated exception message (must be freed
   // by the caller using a resource mark)
   //
@@ -298,8 +297,7 @@
   // The caller (or one of it's callers) must use a ResourceMark
   // in order to correctly free the result.
   //
-  static char* generate_class_cast_message(const char* name, const char* klass,
-                                           const char* gripe = " cannot be cast to ");
+  static char* generate_class_cast_message(Klass* caster_klass, Klass* target_klass);
 
   // Resolves a call site- may patch in the destination of the call into the
   // compiled code.
--- a/src/share/vm/runtime/statSampler.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/statSampler.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2015, 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
@@ -237,7 +237,6 @@
 
 // unstable interface, unsupported counters
 static const char* property_counters_uu[] = {
-  "sun.boot.class.path",
   "sun.boot.library.path",
   NULL
 };
--- a/src/share/vm/runtime/thread.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/thread.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -25,6 +25,7 @@
 #include "precompiled.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/javaClasses.hpp"
+#include "classfile/moduleEntry.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
 #include "code/codeCache.hpp"
@@ -106,6 +107,9 @@
 #include "runtime/rtmLocking.hpp"
 #endif
 
+// Initialization after module runtime initialization
+void universe_post_module_init();  // must happen after call_initPhase2
+
 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
 
 #ifdef DTRACE_ENABLED
@@ -982,15 +986,6 @@
   return thread_oop();
 }
 
-static void call_initializeSystemClass(TRAPS) {
-  Klass* k =  SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
-  instanceKlassHandle klass (THREAD, k);
-
-  JavaValue result(T_VOID);
-  JavaCalls::call_static(&result, klass, vmSymbols::initializeSystemClass_name(),
-                         vmSymbols::void_method_signature(), CHECK);
-}
-
 char java_runtime_name[128] = "";
 char java_runtime_version[128] = "";
 
@@ -3218,6 +3213,34 @@
   // If CompilerThreads ever become non-JavaThreads, add them here
 }
 
+static void call_initPhase1(TRAPS) {
+  Klass* k =  SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
+  instanceKlassHandle klass (THREAD, k);
+
+  JavaValue result(T_VOID);
+  JavaCalls::call_static(&result, klass, vmSymbols::initPhase1_name(),
+                                         vmSymbols::void_method_signature(), CHECK);
+}
+
+static void call_initPhase2(TRAPS) {
+  Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
+  instanceKlassHandle klass (THREAD, k);
+
+  JavaValue result(T_VOID);
+  JavaCalls::call_static(&result, klass, vmSymbols::initPhase2_name(),
+                                         vmSymbols::void_method_signature(), CHECK);
+  universe_post_module_init();
+}
+
+static void call_initPhase3(TRAPS) {
+  Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
+  instanceKlassHandle klass (THREAD, k);
+
+  JavaValue result(T_VOID);
+  JavaCalls::call_static(&result, klass, vmSymbols::initPhase3_name(),
+                                         vmSymbols::void_method_signature(), CHECK);
+}
+
 void Threads::initialize_java_lang_classes(JavaThread* main_thread, TRAPS) {
   TraceTime timer("Initialize java.lang classes", TraceStartupTime);
 
@@ -3243,10 +3266,13 @@
   // The VM creates & returns objects of this class. Make sure it's initialized.
   initialize_class(vmSymbols::java_lang_Class(), CHECK);
 
+  // The VM creates objects of this class.
+  initialize_class(vmSymbols::java_lang_reflect_Module(), CHECK);
+
   // The VM preresolves methods to these classes. Make sure that they get initialized
   initialize_class(vmSymbols::java_lang_reflect_Method(), CHECK);
   initialize_class(vmSymbols::java_lang_ref_Finalizer(), CHECK);
-  call_initializeSystemClass(CHECK);
+  call_initPhase1(CHECK);
 
   // get the Java runtime name after java.lang.System is initialized
   JDK_Version::set_runtime_name(get_java_runtime_name(THREAD));
@@ -3443,6 +3469,10 @@
 
   initialize_java_lang_classes(main_thread, CHECK_JNI_ERR);
 
+  // Create and patch the java.lang.reflect.Module entry for module java.base
+  // into existing classes.
+  ModuleEntryTable::patch_javabase_entries(CHECK_JNI_ERR);
+
   // We need this for ClassDataSharing - the initial vm.info property is set
   // with the default value of CDS "sharing" which may be reset through
   // command line options.
@@ -3468,12 +3498,9 @@
   Management::record_vm_init_completed();
 #endif // INCLUDE_MANAGEMENT
 
-  // Compute system loader. Note that this has to occur after set_init_completed, since
-  // valid exceptions may be thrown in the process.
   // Note that we do not use CHECK_0 here since we are inside an EXCEPTION_MARK and
   // 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(CHECK_JNI_ERR);
 
 #if INCLUDE_ALL_GCS
   // Support for ConcurrentMarkSweep. This should be cleaned up
@@ -3510,13 +3537,6 @@
     create_vm_init_libraries();
   }
 
-  // Notify JVMTI agents that VM initialization is complete - nop if no agents.
-  JvmtiExport::post_vm_initialized();
-
-  if (TRACE_START() != JNI_OK) {
-    vm_exit_during_initialization("Failed to start tracing backend.");
-  }
-
   if (CleanChunkPoolAsync) {
     Chunk::start_chunk_pool_cleaner_task();
   }
@@ -3532,6 +3552,53 @@
   // (see SystemDictionary::find_method_handle_intrinsic).
   initialize_jsr292_core_classes(CHECK_JNI_ERR);
 
+  // The system initialization in the library has three phases
+  // Phase 1: java.lang.System class initialization
+  //     java.lang.System is a primordial class loaded and initialized
+  //     by the VM early during startup.  java.lang.System.<clinit>
+  //     only does registerNatives and keep the rest of the class
+  //     initialization work later until thread initialization completes.
+  //
+  //     System.initPhase1 initializes the system properties, the static
+  //     fields in, out, and err. Setup java signal handlers, OS-specific
+  //     system settings, and set thread group of the main thread.
+  //
+  //     see initialize_java_lang_classes
+  //
+  // Phase 2. Module system initialization
+  //     This will initialize the module system.  Only java.base classes
+  //     can be loaded until phase 2 completes.
+  //
+  //     Call System.initPhase2 after the compiler initialization and jsr292
+  //     classes get initialized because module initialization runs a lot of java
+  //     code, that for performance reasons, should be compiled.  Also, this will
+  //     enable the startup code to use lambda and other language features in this
+  //     phase and onward.
+  //
+  //     After phase 2, The VM will begin search classes from -Xbootclasspath/a.
+  //
+  // Phase 3. final setup - set security manager, system class loader and TCCL
+  //
+  //     This will instantiate and set the security manager, set the system class
+  //     loader as well as the thread context class loader.  The security manager
+  //     and system class loader may be a custom class loaded from -Xbootclasspath/a,
+  //     other modules or the application's classpath.
+
+  call_initPhase2(CHECK_JNI_ERR);
+
+  // Final system initialization including security manager and system class loader.
+  call_initPhase3(CHECK_JNI_ERR);
+
+  // cache the system class loader
+  SystemDictionary::compute_java_system_loader(CHECK_JNI_ERR);
+
+  if (TRACE_START() != JNI_OK) {
+    vm_exit_during_initialization("Failed to start tracing backend.");
+  }
+
+  // Notify JVMTI agents that VM initialization is complete - nop if no agents.
+  JvmtiExport::post_vm_initialized();
+
 #if INCLUDE_MANAGEMENT
   Management::initialize(THREAD);
 
--- a/src/share/vm/runtime/vmStructs.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/runtime/vmStructs.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -1276,6 +1276,7 @@
   static_field(java_lang_Class,                _array_klass_offset,                           int)                                   \
   static_field(java_lang_Class,                _oop_size_offset,                              int)                                   \
   static_field(java_lang_Class,                _static_oop_field_count_offset,                int)                                   \
+  static_field(java_lang_Class,                _module_offset,                                int)                                   \
                                                                                                                                      \
   /************************/                                                                                                         \
   /* Miscellaneous fields */                                                                                                         \
--- a/src/share/vm/trace/traceDataTypes.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/trace/traceDataTypes.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -58,12 +58,11 @@
 
 typedef enum ReservedEvent ReservedEvent;
 
-typedef u8 classid;
-typedef u8 stacktraceid;
-typedef u8 methodid;
-typedef u8 fieldid;
+typedef u8 traceid;
 
+class ModuleEntry;
+class PackageEntry;
 class TraceUnicodeString;
+class Symbol;
 
 #endif // SHARE_VM_TRACE_TRACEDATATYPES_HPP
-
--- a/src/share/vm/trace/traceMacros.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/trace/traceMacros.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -28,16 +28,18 @@
 #define EVENT_THREAD_EXIT(thread)
 #define EVENT_THREAD_DESTRUCT(thread)
 
-#define TRACE_INIT_ID(k)
+#define TRACE_INIT_KLASS_ID(k)
+#define TRACE_INIT_MODULE_ID(m)
+#define TRACE_INIT_PACKAGE_ID(p)
 #define TRACE_DATA TraceThreadData
 
 #define TRACE_START() JNI_OK
 #define TRACE_INITIALIZE() JNI_OK
 
-#define TRACE_DEFINE_KLASS_METHODS typedef int ___IGNORED_hs_trace_type1
-#define TRACE_DEFINE_KLASS_TRACE_ID typedef int ___IGNORED_hs_trace_type2
-#define TRACE_DEFINE_OFFSET typedef int ___IGNORED_hs_trace_type3
-#define TRACE_ID_OFFSET in_ByteSize(0); ShouldNotReachHere()
+#define TRACE_DEFINE_TRACE_ID_METHODS typedef int ___IGNORED_hs_trace_type1
+#define TRACE_DEFINE_TRACE_ID_FIELD typedef int ___IGNORED_hs_trace_type2
+#define TRACE_DEFINE_KLASS_TRACE_ID_OFFSET typedef int ___IGNORED_hs_trace_type3
+#define TRACE_KLASS_TRACE_ID_OFFSET in_ByteSize(0); ShouldNotReachHere()
 #define TRACE_TEMPLATES(template)
 #define TRACE_INTRINSICS(do_intrinsic, do_class, do_name, do_signature, do_alias)
 
--- a/src/share/vm/trace/traceTypes.xsl	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/trace/traceTypes.xsl	Thu Apr 16 21:23:06 2015 -0700
@@ -32,7 +32,6 @@
 #ifndef TRACEFILES_TRACETYPES_HPP
 #define TRACEFILES_TRACETYPES_HPP
 
-#include "oops/symbol.hpp"
 #include "trace/traceDataTypes.hpp"
 #include "utilities/globalDefinitions.hpp"
 #include "utilities/ticks.hpp"
--- a/src/share/vm/trace/tracetypes.xml	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/trace/tracetypes.xml	Thu Apr 16 21:23:06 2015 -0700
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
- Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2012, 2015, 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
@@ -89,6 +89,7 @@
                   type="U8" builtin_type="CLASS">
       <value type="CLASS" field="loaderClass" label="ClassLoader"/>
       <value type="SYMBOL" field="name" label="Name"/>
+      <value type="PACKAGE" field="package" label="Package"/>
       <value type="SHORT" field="modifiers" label="Access modifiers"/>
     </content_type>
 
@@ -176,6 +177,20 @@
       <value type="UTF8" field="type" label="type" />
     </content_type>
 
+    <content_type id="Module" hr_name="Module"
+              type="U8" jvm_type="MODULE">
+      <value type="SYMBOL" field="name" label="Name"/>
+      <value type="SYMBOL" field="version" label="Version"/>
+      <value type="SYMBOL" field="location" label="Location"/>
+      <value type="CLASS" field="classLoader" label="ClassLoader"/>
+    </content_type>
+
+    <content_type id="Package" hr_name="Package"
+              type="U8" jvm_type="PACKAGE">
+      <value type="SYMBOL" field="name" label="Name"/>
+      <value type="MODULE" field="module" label="Module"/>
+      <value type="BOOLEAN" field="exported" label="Exported"/>
+    </content_type>
   </content_types>
 
 
@@ -292,6 +307,12 @@
     <primary_type symbol="CLASS" datatype="U8" contenttype="CLASS"
                   type="Klass *" sizeop="sizeof(u8)"/>
 
+    <primary_type symbol="MODULE" datatype="U8" contenttype="MODULE"
+                  type="const ModuleEntry *" sizeop="sizeof(u8)"/>
+
+    <primary_type symbol="PACKAGE" datatype="U8" contenttype="PACKAGE"
+              type="const PackageEntry *" sizeop="sizeof(u8)"/>
+
     <!-- A Method *. The method is marked as "used" and will eventually be
          written into the recording constant pool. -->
     <primary_type symbol="METHOD" datatype="U8" contenttype="METHOD"
--- a/src/share/vm/utilities/dtrace_disabled.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/utilities/dtrace_disabled.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -1084,6 +1084,12 @@
 #define HOTSPOT_JNI_UNREGISTERNATIVES_RETURN(arg0)
 #define HOTSPOT_JNI_UNREGISTERNATIVES_RETURN_ENABLED()  0
 
+/* Modules */
+#define HOTSPOT_JNI_GETMODULE_ENTRY(arg0, arg1)
+#define HOTSPOT_JNI_GETMODULE_ENTRY_ENABLED()  0
+#define HOTSPOT_JNI_GETMODULE_RETURN(arg0)
+#define HOTSPOT_JNI_GETMODULE_RETURN_ENABLED()
+
 #else /* !defined(DTRACE_ENABLED) */
 #error This file should only be included when dtrace is not enabled
 #endif /* !defined(DTRACE_ENABLED) */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/utilities/endian.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "utilities/endian.hpp"
+#include "utilities/bytes.hpp"
+
+#ifndef bswap_16
+extern "C" inline u2 bswap_16(u2 x) {
+  return ((x & 0xFF) << 8) |
+         ((x >> 8) & 0xFF);
+}
+#endif
+
+#ifndef bswap_32
+extern "C" inline u4 bswap_32(u4 x) {
+  return ((x & 0xFF) << 24) |
+       ((x & 0xFF00) << 8) |
+       ((x >> 8) & 0xFF00) |
+       ((x >> 24) & 0xFF);
+}
+#endif
+
+#ifndef bswap_64
+extern "C" inline u8 bswap_64(u8 x) {
+  return (u8)bswap_32((u4)x) << 32 |
+         (u8)bswap_32((u4)(x >> 32));
+}
+#endif
+
+u2 NativeEndian::get(u2 x) { return x; }
+u4 NativeEndian::get(u4 x) { return x; }
+u8 NativeEndian::get(u8 x) { return x; }
+s2 NativeEndian::get(s2 x) { return x; }
+s4 NativeEndian::get(s4 x) { return x; }
+s8 NativeEndian::get(s8 x) { return x; }
+
+void NativeEndian::set(u2& x, u2 y) { x = y; }
+void NativeEndian::set(u4& x, u4 y) { x = y; }
+void NativeEndian::set(u8& x, u8 y) { x = y; }
+void NativeEndian::set(s2& x, s2 y) { x = y; }
+void NativeEndian::set(s4& x, s4 y) { x = y; }
+void NativeEndian::set(s8& x, s8 y) { x = y; }
+
+NativeEndian NativeEndian::native;
+
+u2 SwappingEndian::get(u2 x) { return bswap_16(x); }
+u4 SwappingEndian::get(u4 x) { return bswap_32(x); }
+u8 SwappingEndian::get(u8 x) { return bswap_64(x); }
+s2 SwappingEndian::get(s2 x) { return bswap_16(x); }
+s4 SwappingEndian::get(s4 x) { return bswap_32(x); }
+s8 SwappingEndian::get(s8 x) { return bswap_64(x); }
+
+void SwappingEndian::set(u2& x, u2 y) { x = bswap_16(y); }
+void SwappingEndian::set(u4& x, u4 y) { x = bswap_32(y); }
+void SwappingEndian::set(u8& x, u8 y) { x = bswap_64(y); }
+void SwappingEndian::set(s2& x, s2 y) { x = bswap_16(y); }
+void SwappingEndian::set(s4& x, s4 y) { x = bswap_32(y); }
+void SwappingEndian::set(s8& x, s8 y) { x = bswap_64(y); }
+
+SwappingEndian SwappingEndian::swapping;
+
+Endian* Endian::get_handler(bool big_endian) {
+  // If requesting little endian on a little endian machine or
+  // big endian on a big endian machine use native handler
+  if (big_endian == is_big_endian()) {
+    return &NativeEndian::native;
+  } else {
+    // Use swapping handler.
+    return &SwappingEndian:: swapping;
+  }
+}
+
+Endian* Endian::get_native_handler() {
+  return &NativeEndian::native;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/utilities/endian.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ */
+
+#ifndef SHARE_VM_UTILITIES_ENDIAN_HPP
+#define SHARE_VM_UTILITIES_ENDIAN_HPP
+
+#include "utilities/globalDefinitions.hpp"
+
+// Selectable endian handling. Endian handlers are used when accessing values
+// that are of unknown (until runtime) endian.  The only requirement of the values
+// accessed are that they are aligned to proper size boundaries (no misalignment.)
+// To select an endian handler, one should call Endian::get_handler(big_endian);
+// Where big_endian is true if big endian is required and false otherwise.  The
+// native endian handler can be fetched with Endian::get_native_handler();
+// To retrieve a value using the approprate endian, use one of the overloaded
+// calls to get. To set a value, then use one of the overloaded set calls.
+// Ex.
+//      s4 value; // Imported value;
+//      ...
+//      Endian* endian = Endian::get_handler(true);  // Use big endian
+//      s4 corrected = endian->get(value);
+//      endian->set(value, 1);
+//
+struct Endian {
+  virtual u2 get(u2 x) = 0;
+  virtual u4 get(u4 x) = 0;
+  virtual u8 get(u8 x) = 0;
+  virtual s2 get(s2 x) = 0;
+  virtual s4 get(s4 x) = 0;
+  virtual s8 get(s8 x) = 0;
+
+  virtual void set(u2& x, u2 y) = 0;
+  virtual void set(u4& x, u4 y) = 0;
+  virtual void set(u8& x, u8 y) = 0;
+  virtual void set(s2& x, s2 y) = 0;
+  virtual void set(s4& x, s4 y) = 0;
+  virtual void set(s8& x, s8 y) = 0;
+
+  // Quick little endian test.
+  static bool is_little_endian() {  u4 x = 1; return *(u1 *)&x != 0; }
+
+  // Quick big endian test.
+  static bool is_big_endian() { return !is_little_endian(); }
+
+  // Select an appropriate endian handler.
+  static Endian* get_handler(bool big_endian);
+
+  // Return the native endian handler.
+  static Endian* get_native_handler();
+};
+
+// Normal endian handling.
+struct NativeEndian : public Endian {
+  u2 get(u2 x);
+  u4 get(u4 x);
+  u8 get(u8 x);
+  s2 get(s2 x);
+  s4 get(s4 x);
+  s8 get(s8 x);
+
+  void set(u2& x, u2 y);
+  void set(u4& x, u4 y);
+  void set(u8& x, u8 y);
+  void set(s2& x, s2 y);
+  void set(s4& x, s4 y);
+  void set(s8& x, s8 y);
+
+  static NativeEndian native;
+};
+
+// Swapping endian handling.
+struct SwappingEndian : public Endian {
+  u2 get(u2 x);
+  u4 get(u4 x);
+  u8 get(u8 x);
+  s2 get(s2 x);
+  s4 get(s4 x);
+  s8 get(s8 x);
+
+  void set(u2& x, u2 y);
+  void set(u4& x, u4 y);
+  void set(u8& x, u8 y);
+  void set(s2& x, s2 y);
+  void set(s4& x, s4 y);
+  void set(s8& x, s8 y);
+
+  static SwappingEndian swapping;
+};
+#endif // SHARE_VM_UTILITIES_ENDIAN_HPP
--- a/src/share/vm/utilities/hashtable.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/utilities/hashtable.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -151,7 +151,7 @@
   void copy_table(char** top, char* end);
 
   // Bucket handling
-  int hash_to_index(unsigned int full_hash) {
+  int hash_to_index(unsigned int full_hash) const {
     int h = full_hash % _table_size;
     assert(h >= 0 && h < _table_size, "Illegal hash value");
     return h;
--- a/src/share/vm/utilities/utf8.cpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/utilities/utf8.cpp	Thu Apr 16 21:23:06 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -306,6 +306,68 @@
                  + ((str[4] & 0x0f) << 6)  + (str[5] & 0x3f);
 }
 
+bool UTF8::is_legal_utf8(const unsigned char* buffer, int length,
+                         bool version_leq_47) {
+  int i = 0;
+  int count = length >> 2;
+  for (int k=0; k<count; k++) {
+    unsigned char b0 = buffer[i];
+    unsigned char b1 = buffer[i+1];
+    unsigned char b2 = buffer[i+2];
+    unsigned char b3 = buffer[i+3];
+    // For an unsigned char v,
+    // (v | v - 1) is < 128 (highest bit 0) for 0 < v < 128;
+    // (v | v - 1) is >= 128 (highest bit 1) for v == 0 or v >= 128.
+    unsigned char res = b0 | b0 - 1 |
+                        b1 | b1 - 1 |
+                        b2 | b2 - 1 |
+                        b3 | b3 - 1;
+    if (res >= 128) break;
+    i += 4;
+  }
+  for(; i < length; i++) {
+    unsigned short c;
+    // no embedded zeros
+    if (buffer[i] == 0) return false;
+    if(buffer[i] < 128) {
+      continue;
+    }
+    if ((i + 5) < length) { // see if it's legal supplementary character
+      if (UTF8::is_supplementary_character(&buffer[i])) {
+        c = UTF8::get_supplementary_character(&buffer[i]);
+        i += 5;
+        continue;
+      }
+    }
+    switch (buffer[i] >> 4) {
+      default: break;
+      case 0x8: case 0x9: case 0xA: case 0xB: case 0xF:
+        return false;
+      case 0xC: case 0xD:  // 110xxxxx  10xxxxxx
+        c = (buffer[i] & 0x1F) << 6;
+        i++;
+        if ((i < length) && ((buffer[i] & 0xC0) == 0x80)) {
+          c += buffer[i] & 0x3F;
+          if (version_leq_47 || c == 0 || c >= 0x80) {
+            break;
+          }
+        }
+        return false;
+      case 0xE:  // 1110xxxx 10xxxxxx 10xxxxxx
+        c = (buffer[i] & 0xF) << 12;
+        i += 2;
+        if ((i < length) && ((buffer[i-1] & 0xC0) == 0x80) && ((buffer[i] & 0xC0) == 0x80)) {
+          c += ((buffer[i-1] & 0x3F) << 6) + (buffer[i] & 0x3F);
+          if (version_leq_47 || c >= 0x800) {
+            break;
+          }
+        }
+        return false;
+    }  // end of switch
+  } // end of for
+  return true;
+}
+
 
 //-------------------------------------------------------------------------------------
 
--- a/src/share/vm/utilities/utf8.hpp	Thu Apr 09 17:38:28 2015 -0700
+++ b/src/share/vm/utilities/utf8.hpp	Thu Apr 16 21:23:06 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -65,6 +65,9 @@
   static bool   equal(const jbyte* base1, int length1, const jbyte* base2,int length2);
   static bool   is_supplementary_character(const unsigned char* str);
   static jint   get_supplementary_character(const unsigned char* str);
+
+  static bool   is_legal_utf8(const unsigned char* buffer, int length,
+                              bool version_leq_47);
 };
 
 
--- a/test/compiler/c2/5057225/Test5057225.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/c2/5057225/Test5057225.java	Thu Apr 16 21:23:06 2015 -0700
@@ -25,7 +25,7 @@
  * @test
  * @bug 5057225
  * @summary Remove useless I2L conversions
- *
+ * @ignore 8072369
  * @run main/othervm -Xcomp -XX:CompileOnly=Test5057225.doload Test5057225
  */
 
--- a/test/compiler/c2/6603011/Test.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/c2/6603011/Test.java	Thu Apr 16 21:23:06 2015 -0700
@@ -25,7 +25,7 @@
  * @test
  * @bug 6603011
  * @summary long/int division by constant
- *
+ * @ignore 8072369
  * @run main/othervm -Xcomp -Xbatch -XX:-Inline Test
  */
 
--- a/test/compiler/c2/6800154/Test6800154.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/c2/6800154/Test6800154.java	Thu Apr 16 21:23:06 2015 -0700
@@ -25,7 +25,7 @@
  * @test
  * @bug 6800154
  * @summary Add comments to long_by_long_mulhi() for better understandability
- *
+ * @ignore 8072369
  * @run main/othervm -Xcomp -XX:CompileOnly=Test6800154.divcomp Test6800154
  */
 
--- a/test/compiler/c2/6805724/Test6805724.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/c2/6805724/Test6805724.java	Thu Apr 16 21:23:06 2015 -0700
@@ -25,7 +25,7 @@
  * @test
  * @bug 6805724
  * @summary ModLNode::Ideal() generates functionally incorrect graph when divisor is any (2^k-1) constant.
- *
+ * @ignore 8072369
  * @run main/othervm -Xcomp -XX:CompileOnly=Test6805724.fcomp Test6805724
  */
 
--- a/test/compiler/codegen/6823354/Test6823354.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/codegen/6823354/Test6823354.java	Thu Apr 16 21:23:06 2015 -0700
@@ -25,7 +25,7 @@
  * @test
  * @bug 6823354
  * @summary These methods can be instrinsified by using bit scan, bit test, and population count instructions.
- *
+ * @ignore 8072369
  * @run main/othervm -Xcomp -XX:CompileOnly=Test6823354.lzcomp,Test6823354.tzcomp,.dolzcomp,.dotzcomp Test6823354
  */
 
--- a/test/compiler/dependencies/MonomorphicObjectCall/TestMonomorphicObjectCall.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/dependencies/MonomorphicObjectCall/TestMonomorphicObjectCall.java	Thu Apr 16 21:23:06 2015 -0700
@@ -22,6 +22,8 @@
  */
 
 import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Collections;
 
@@ -38,7 +40,6 @@
  * @run main TestMonomorphicObjectCall
  */
 public class TestMonomorphicObjectCall {
-    final static String testClasses = System.getProperty("test.classes") + File.separator;
 
     private static void callFinalize(Object object) throws Throwable {
         // Call modified version of java.lang.Object::finalize() that is
@@ -49,6 +50,9 @@
 
     public static void main(String[] args) throws Throwable {
         if (args.length == 0) {
+            byte[] bytecode = Files.readAllBytes(Paths.get(System.getProperty("test.classes") + File.separator +
+                "java" + File.separator + "lang" + File.separator + "Object.class"));
+            ClassFileInstaller.writeClassToDisk("java.lang.Object", bytecode, "mods/java.base");
             // Execute new instance with modified java.lang.Object
             executeTestJvm();
         } else {
@@ -61,7 +65,7 @@
         // Execute test with modified version of java.lang.Object
         // in -Xbootclasspath.
         String[] vmOpts = new String[] {
-                "-Xbootclasspath/p:" + testClasses,
+                "-Xoverride:mods",
                 "-Xcomp",
                 "-XX:+IgnoreUnrecognizedVMOptions",
                 "-XX:-VerifyDependencies",
--- a/test/compiler/jsr292/CreatesInterfaceDotEqualsCallInfo.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/jsr292/CreatesInterfaceDotEqualsCallInfo.java	Thu Apr 16 21:23:06 2015 -0700
@@ -24,6 +24,7 @@
 
 /**
  * @test
+ * @ignore 8072479
  * @bug 8026124
  * @summary Javascript file provoked assertion failure in linkResolver.cpp
  * @modules jdk.scripting.nashorn/jdk.nashorn.tools
--- a/test/compiler/stable/TestStableBoolean.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/stable/TestStableBoolean.java	Thu Apr 16 21:23:06 2015 -0700
@@ -27,6 +27,7 @@
  * @test TestStableBoolean
  * @summary tests on stable fields and arrays
  * @library /testlibrary /../../test/lib
+ * @ignore 8077176
  * @build TestStableBoolean StableConfiguration sun.hotspot.WhiteBox
  * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  * @run main ClassFileInstaller
--- a/test/compiler/stable/TestStableByte.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/stable/TestStableByte.java	Thu Apr 16 21:23:06 2015 -0700
@@ -27,6 +27,7 @@
  * @test TestStableByte
  * @summary tests on stable fields and arrays
  * @library /testlibrary /../../test/lib
+ * @ignore 8077176
  * @build TestStableByte StableConfiguration sun.hotspot.WhiteBox
  * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  * @run main ClassFileInstaller
--- a/test/compiler/stable/TestStableChar.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/stable/TestStableChar.java	Thu Apr 16 21:23:06 2015 -0700
@@ -27,6 +27,7 @@
  * @test TestStableChar
  * @summary tests on stable fields and arrays
  * @library /testlibrary /../../test/lib
+ * @ignore 8077176
  * @build TestStableChar StableConfiguration sun.hotspot.WhiteBox
  * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  * @run main ClassFileInstaller
--- a/test/compiler/stable/TestStableDouble.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/stable/TestStableDouble.java	Thu Apr 16 21:23:06 2015 -0700
@@ -27,6 +27,7 @@
  * @test TestStableDouble
  * @summary tests on stable fields and arrays
  * @library /testlibrary /../../test/lib
+ * @ignore 8077176
  * @build TestStableDouble StableConfiguration sun.hotspot.WhiteBox
  * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  * @run main ClassFileInstaller
--- a/test/compiler/stable/TestStableFloat.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/stable/TestStableFloat.java	Thu Apr 16 21:23:06 2015 -0700
@@ -27,6 +27,7 @@
  * @test TestStableFloat
  * @summary tests on stable fields and arrays
  * @library /testlibrary /../../test/lib
+ * @ignore 8077176
  * @build TestStableFloat StableConfiguration sun.hotspot.WhiteBox
  * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  * @run main ClassFileInstaller
--- a/test/compiler/stable/TestStableInt.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/stable/TestStableInt.java	Thu Apr 16 21:23:06 2015 -0700
@@ -27,6 +27,7 @@
  * @test TestStableInt
  * @summary tests on stable fields and arrays
  * @library /testlibrary /../../test/lib
+ * @ignore 8077176
  * @build TestStableInt StableConfiguration sun.hotspot.WhiteBox
  * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  * @run main ClassFileInstaller
--- a/test/compiler/stable/TestStableLong.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/stable/TestStableLong.java	Thu Apr 16 21:23:06 2015 -0700
@@ -27,6 +27,7 @@
  * @test TestStableLong
  * @summary tests on stable fields and arrays
  * @library /testlibrary /../../test/lib
+ * @ignore 8077176
  * @build TestStableLong StableConfiguration sun.hotspot.WhiteBox
  * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  * @run main ClassFileInstaller
--- a/test/compiler/stable/TestStableObject.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/stable/TestStableObject.java	Thu Apr 16 21:23:06 2015 -0700
@@ -27,6 +27,7 @@
  * @test TestStableObject
  * @summary tests on stable fields and arrays
  * @library /testlibrary /../../test/lib
+ * @ignore 8077176
  * @build TestStableObject StableConfiguration sun.hotspot.WhiteBox
  * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  * @run main ClassFileInstaller
--- a/test/compiler/stable/TestStableShort.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/stable/TestStableShort.java	Thu Apr 16 21:23:06 2015 -0700
@@ -27,6 +27,7 @@
  * @test TestStableShort
  * @summary tests on stable fields and arrays
  * @library /testlibrary /../../test/lib
+ * @ignore 8077176
  * @build TestStableShort StableConfiguration sun.hotspot.WhiteBox
  * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  * @run main ClassFileInstaller
--- a/test/compiler/uncommontrap/TestUnstableIfTrap.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/compiler/uncommontrap/TestUnstableIfTrap.java	Thu Apr 16 21:23:06 2015 -0700
@@ -53,7 +53,7 @@
  *                   -XX:+WhiteBoxAPI -XX:+LogCompilation
  *                   -XX:CompileCommand=compileonly,UnstableIfExecutable.test
  *                   -XX:LogFile=always_taken_not_fired.xml
- *                   TestUnstableIfTrap ALWAYS_TAKEN false
+  *                   TestUnstableIfTrap ALWAYS_TAKEN false
  * @run main/othervm -Xbatch -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  *                   -XX:+WhiteBoxAPI -XX:+LogCompilation
  *                   -XX:CompileCommand=compileonly,UnstableIfExecutable.test
--- a/test/gc/TestSmallHeap.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/gc/TestSmallHeap.java	Thu Apr 16 21:23:06 2015 -0700
@@ -30,6 +30,7 @@
  * @summary Verify that starting the VM with a small heap works
  * @library /testlibrary /../../test/lib
  * @modules java.management/sun.management
+ * @ignore 8076621
  * @build TestSmallHeap
  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx2m -XX:+UseParallelGC TestSmallHeap
--- a/test/gc/g1/TestShrinkDefragmentedHeap.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/gc/g1/TestShrinkDefragmentedHeap.java	Thu Apr 16 21:23:06 2015 -0700
@@ -63,6 +63,7 @@
                 "-XX:G1HeapRegionSize=" + REGION_SIZE,
                 "-XX:-ExplicitGCInvokesConcurrent",
                 "-verbose:gc",
+                "-XX:AddModuleExports=java.management/sun.management",
                 GCTest.class.getName()
         );
 
--- a/test/gc/g1/TestStringDeduplicationTools.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/gc/g1/TestStringDeduplicationTools.java	Thu Apr 16 21:23:06 2015 -0700
@@ -189,7 +189,8 @@
             "-Xmx" + Xmx + "m",
             "-XX:+UseG1GC",
             "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:+VerifyAfterGC" // Always verify after GC
+            "-XX:+VerifyAfterGC", // Always verify after GC
+            "-XX:AddModuleExports=java.base/sun.misc"
         };
 
         ArrayList<String> args = new ArrayList<String>();
--- a/test/gc/g1/TestSummarizeRSetStats.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/gc/g1/TestSummarizeRSetStats.java	Thu Apr 16 21:23:06 2015 -0700
@@ -29,7 +29,7 @@
  *          java.management/sun.management
  * @build TestSummarizeRSetStatsTools TestSummarizeRSetStats
  * @summary Verify output of -XX:+G1SummarizeRSetStats
- * @run main TestSummarizeRSetStats
+ * @run main/othervm TestSummarizeRSetStats
  *
  * Test the output of G1SummarizeRSetStats in conjunction with G1SummarizeRSetStatsPeriod.
  */
--- a/test/gc/g1/TestSummarizeRSetStatsPerRegion.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/gc/g1/TestSummarizeRSetStatsPerRegion.java	Thu Apr 16 21:23:06 2015 -0700
@@ -29,7 +29,7 @@
  *          java.management/sun.management
  * @build TestSummarizeRSetStatsTools TestSummarizeRSetStatsPerRegion
  * @summary Verify output of -XX:+G1SummarizeRSetStats in regards to per-region type output
- * @run main TestSummarizeRSetStatsPerRegion
+ * @run main/othervm TestSummarizeRSetStatsPerRegion
  */
 
 import com.oracle.java.testlibrary.*;
--- a/test/gc/parallelScavenge/TestDynShrinkHeap.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/gc/parallelScavenge/TestDynShrinkHeap.java	Thu Apr 16 21:23:06 2015 -0700
@@ -26,6 +26,7 @@
  * @bug 8016479
  * @requires vm.gc=="Parallel" | vm.gc=="null"
  * @summary Verify that the heap shrinks after full GC according to the current values of the Min/MaxHeapFreeRatio flags
+ * @modules java.management/sun.management
  * @library /testlibrary
  * @run main/othervm -XX:+UseAdaptiveSizePolicyWithSystemGC -XX:+UseParallelGC -XX:MinHeapFreeRatio=0 -XX:MaxHeapFreeRatio=100 -Xmx1g -verbose:gc TestDynShrinkHeap
  */
--- a/test/runtime/BadObjectClass/BootstrapRedefine.java	Thu Apr 09 17:38:28 2015 -0700
+++ b/test/runtime/BadObjectClass/BootstrapRedefine.java	Thu Apr 16 21:23:06 2015 -0700
@@ -28,7 +28,6 @@
  * @library /testlibrary
  * @modules java.base/sun.misc
  *          java.management
- * @compile Object.java
  * @run main BootstrapRedefine
  */
 
@@ -37,8 +36,18 @@
 public class BootstrapRedefine {
 
     public static void main(String[] args) throws Exception {
-        String testClasses = System.getProperty("test.classes", ".");
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xbootclasspath/p:" + testClasses, "-version");
+        String source = "package java.lang;" +
+                        "public class Object {" +
+                        "    void dummy1() { return; }" +
+                        "    void dummy2() { return; }" +
+                        "    void dummy3() { return; }" +
+                        "}";
+
+        ClassFileInstaller.writeClassToDisk("java/lang/Object",
+                                        InMemoryJavaCompiler.compile("java.lang.Object", source),
+                                        "mods/java.base");
+
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xoverride:mods", "-version");
         new OutputAnalyzer(pb.start())
             .shouldContain("Incompatible definition of java.lang.Object")
             .shouldHaveExitValue(1);
--- a/test/runtime/BadObjectClass/Object.java	Thu Apr 09 17:38:28 2015 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2015, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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 java.lang;
-
-/**
- * This is a fake java.lang.Object class.
- */
-public class Object {
-
-    // Add some methods
-    void dummy1() { return; }
-    void dummy2() { return; }
-    void dummy3() { return; }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/runtime/BootClassAppendProp/BootClassPathAppendProp.java	Thu Apr 16 21:23:06 2015 -0700
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights