changeset 6699:87cbcaecf4e4

8205714: Initial class initialization Reviewed-by: acorn, coleenp, kvn, vlivanov
author dholmes
date Thu, 07 Feb 2019 05:19:56 +0000
parents 69f46e2dbd83
children e14a43e8767f
files src/share/vm/oops/cpCacheOop.cpp src/share/vm/runtime/sharedRuntime.cpp
diffstat 2 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/oops/cpCacheOop.cpp	Mon Oct 22 05:27:45 2018 +0100
+++ b/src/share/vm/oops/cpCacheOop.cpp	Thu Feb 07 05:19:56 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, 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
@@ -220,7 +220,17 @@
   if (byte_no == 1) {
     assert(invoke_code != Bytecodes::_invokevirtual &&
            invoke_code != Bytecodes::_invokeinterface, "");
-    set_bytecode_1(invoke_code);
+    bool do_resolve = true;
+    // Don't mark invokestatic to method as resolved if the holder class has not yet completed
+    // initialization. An invokestatic must only proceed if the class is initialized, but if
+    // we resolve it before then that class initialization check is skipped.
+    if (invoke_code == Bytecodes::_invokestatic &&
+        !instanceKlass::cast(method->method_holder())->is_initialized()) {
+      do_resolve = false;
+    }
+    if (do_resolve) {
+      set_bytecode_1(invoke_code);
+    }
   } else if (byte_no == 2)  {
     if (change_to_virtual) {
       assert(invoke_code == Bytecodes::_invokeinterface, "");
--- a/src/share/vm/runtime/sharedRuntime.cpp	Mon Oct 22 05:27:45 2018 +0100
+++ b/src/share/vm/runtime/sharedRuntime.cpp	Thu Feb 07 05:19:56 2019 +0000
@@ -1207,6 +1207,14 @@
   }
 #endif
 
+  // Do not patch call site for static call when the class is not
+  // fully initialized.
+  if (invoke_code == Bytecodes::_invokestatic &&
+      !instanceKlass::cast(callee_method->method_holder())->is_initialized()) {
+    assert(callee_method->method_holder()->is_linked(), "must be");
+    return callee_method;
+  }
+
   // JSR 292 key invariant:
   // If the resolved method is a MethodHandle invoke target the call
   // site must be a MethodHandle call site, because the lambda form might tail-call