8164091: VM fails during startup with "assert(resolved_method->method_holder()->is_linked()) failed: must be linked"
authorthartmann
Wed, 17 Aug 2016 08:19:06 +0200
changeset 40646 c5dfe23b92b1
parent 40642 7f337136f657
child 40647 cd5e1372ad44
8164091: VM fails during startup with "assert(resolved_method->method_holder()->is_linked()) failed: must be linked" Summary: Don't throw java_lang_VirtualMachineError during VM initialization. Reviewed-by: zmajo, dlong, dholmes
hotspot/src/share/vm/oops/method.cpp
hotspot/test/compiler/startup/StartupOutput.java
--- a/hotspot/src/share/vm/oops/method.cpp	Mon Aug 15 14:08:01 2016 -0700
+++ b/hotspot/src/share/vm/oops/method.cpp	Wed Aug 17 08:19:06 2016 +0200
@@ -54,6 +54,7 @@
 #include "runtime/compilationPolicy.hpp"
 #include "runtime/frame.inline.hpp"
 #include "runtime/handles.inline.hpp"
+#include "runtime/init.hpp"
 #include "runtime/orderAccess.inline.hpp"
 #include "runtime/relocator.hpp"
 #include "runtime/sharedRuntime.hpp"
@@ -1015,7 +1016,14 @@
   // so making them eagerly shouldn't be too expensive.
   AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
   if (adapter == NULL ) {
-    THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters");
+    if (!is_init_completed()) {
+      // Don't throw exceptions during VM initialization because java.lang.* classes
+      // might not have been initialized, causing problems when constructing the
+      // Java exception object.
+      vm_exit_during_initialization("Out of space in CodeCache for adapters");
+    } else {
+      THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters");
+    }
   }
 
   if (mh->is_shared()) {
--- a/hotspot/test/compiler/startup/StartupOutput.java	Mon Aug 15 14:08:01 2016 -0700
+++ b/hotspot/test/compiler/startup/StartupOutput.java	Wed Aug 17 08:19:06 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, 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,7 +23,7 @@
 
 /*
  * @test
- * @bug 8026949
+ * @bug 8026949 8164091
  * @summary Test ensures correct VM output during startup
  * @library /testlibrary
  * @modules java.base/jdk.internal.misc
@@ -45,7 +45,14 @@
         pb = ProcessTools.createJavaProcessBuilder("-Xint", "-XX:+DisplayVMOutputToStdout", "-version");
         out = new OutputAnalyzer(pb.start());
         out.shouldNotContain("no space to run compilers");
+        out.shouldHaveExitValue(0);
 
-        out.shouldHaveExitValue(0);
+        pb = ProcessTools.createJavaProcessBuilder("-Xint", "-XX:ReservedCodeCacheSize=1770K", "-XX:InitialCodeCacheSize=4K", "-version");
+        out = new OutputAnalyzer(pb.start());
+        // The VM should not crash but may return an error message because we don't have enough space for adapters
+        int exitCode = out.getExitValue();
+        if (exitCode != 1 && exitCode != 0) {
+            throw new Exception("VM crashed with exit code " + exitCode);
+        }
     }
 }