src/hotspot/share/jvmci/jvmciRuntime.cpp
author stefank
Tue, 26 Nov 2019 10:47:46 +0100
changeset 59290 97d13893ec3c
parent 59260 b0a649295f25
permissions -rw-r--r--
8234748: Clean up atomic and orderAccess includes Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     1
/*
53582
881c5fbeb849 8218041: Assorted wrong/missing includes
rehn
parents: 52033
diff changeset
     2
 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     4
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     8
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    13
 * accompanied this code).
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    14
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    18
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    21
 * questions.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    22
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    23
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    24
#include "precompiled.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54732
diff changeset
    25
#include "classfile/symbolTable.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    26
#include "compiler/compileBroker.hpp"
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
    27
#include "jvmci/jniAccessMark.inline.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    28
#include "jvmci/jvmciCompilerToVM.hpp"
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
    29
#include "jvmci/jvmciRuntime.hpp"
35216
71c463a17b3b 8141211: Convert TraceExceptions to Unified Logging
rprotacio
parents: 35071
diff changeset
    30
#include "logging/log.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    31
#include "memory/oopFactory.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54732
diff changeset
    32
#include "memory/universe.hpp"
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
    33
#include "oops/constantPool.inline.hpp"
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
    34
#include "oops/method.inline.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54732
diff changeset
    35
#include "oops/objArrayKlass.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    36
#include "oops/oop.inline.hpp"
59290
97d13893ec3c 8234748: Clean up atomic and orderAccess includes
stefank
parents: 59260
diff changeset
    37
#include "runtime/atomic.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    38
#include "runtime/biasedLocking.hpp"
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
    39
#include "runtime/deoptimization.hpp"
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
    40
#include "runtime/fieldDescriptor.inline.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49449
diff changeset
    41
#include "runtime/frame.inline.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    42
#include "runtime/sharedRuntime.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49837
diff changeset
    43
#if INCLUDE_G1GC
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49480
diff changeset
    44
#include "gc/g1/g1ThreadLocalData.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49837
diff changeset
    45
#endif // INCLUDE_G1GC
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    46
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    47
// Simple helper to see if the caller of a runtime stub which
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    48
// entered the VM has been deoptimized
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    49
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    50
static bool caller_is_deopted() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    51
  JavaThread* thread = JavaThread::current();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    52
  RegisterMap reg_map(thread, false);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    53
  frame runtime_frame = thread->last_frame();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    54
  frame caller_frame = runtime_frame.sender(&reg_map);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    55
  assert(caller_frame.is_compiled_frame(), "must be compiled");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    56
  return caller_frame.is_deoptimized_frame();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    57
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    58
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    59
// Stress deoptimization
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    60
static void deopt_caller() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    61
  if ( !caller_is_deopted()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    62
    JavaThread* thread = JavaThread::current();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    63
    RegisterMap reg_map(thread, false);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    64
    frame runtime_frame = thread->last_frame();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    65
    frame caller_frame = runtime_frame.sender(&reg_map);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    66
    Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    67
    assert(caller_is_deopted(), "Must be deoptimized");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    68
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    69
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    70
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    71
// Manages a scope for a JVMCI runtime call that attempts a heap allocation.
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    72
// If there is a pending exception upon closing the scope and the runtime
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    73
// call is of the variety where allocation failure returns NULL without an
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    74
// exception, the following action is taken:
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    75
//   1. The pending exception is cleared
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    76
//   2. NULL is written to JavaThread::_vm_result
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    77
//   3. Checks that an OutOfMemoryError is Universe::out_of_memory_error_retry().
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    78
class RetryableAllocationMark: public StackObj {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    79
 private:
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    80
  JavaThread* _thread;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    81
 public:
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    82
  RetryableAllocationMark(JavaThread* thread, bool activate) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    83
    if (activate) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    84
      assert(!thread->in_retryable_allocation(), "retryable allocation scope is non-reentrant");
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    85
      _thread = thread;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    86
      _thread->set_in_retryable_allocation(true);
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    87
    } else {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    88
      _thread = NULL;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    89
    }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    90
  }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    91
  ~RetryableAllocationMark() {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    92
    if (_thread != NULL) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    93
      _thread->set_in_retryable_allocation(false);
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    94
      JavaThread* THREAD = _thread;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    95
      if (HAS_PENDING_EXCEPTION) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    96
        oop ex = PENDING_EXCEPTION;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    97
        CLEAR_PENDING_EXCEPTION;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    98
        oop retry_oome = Universe::out_of_memory_error_retry();
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    99
        if (ex->is_a(retry_oome->klass()) && retry_oome != ex) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   100
          ResourceMark rm;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   101
          fatal("Unexpected exception in scope of retryable allocation: " INTPTR_FORMAT " of type %s", p2i(ex), ex->klass()->external_name());
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   102
        }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   103
        _thread->set_vm_result(NULL);
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   104
      }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   105
    }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   106
  }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   107
};
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   108
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   109
JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_instance_common(JavaThread* thread, Klass* klass, bool null_on_fail))
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   110
  JRT_BLOCK;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   111
  assert(klass->is_klass(), "not a class");
36603
0bc3ad031d60 8141420: Compiler runtime entries don't hold Klass* from being GCed
vlivanov
parents: 36594
diff changeset
   112
  Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   113
  InstanceKlass* h = InstanceKlass::cast(klass);
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   114
  {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   115
    RetryableAllocationMark ram(thread, null_on_fail);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   116
    h->check_valid_for_instantiation(true, CHECK);
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   117
    oop obj;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   118
    if (null_on_fail) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   119
      if (!h->is_initialized()) {
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   120
        // Cannot re-execute class initialization without side effects
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   121
        // so return without attempting the initialization
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   122
        return;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   123
      }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   124
    } else {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   125
      // make sure klass is initialized
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   126
      h->initialize(CHECK);
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   127
    }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   128
    // allocate instance and return via TLS
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   129
    obj = h->allocate_instance(CHECK);
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   130
    thread->set_vm_result(obj);
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   131
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   132
  JRT_BLOCK_END;
48961
120b61d50f85 8195103: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48105
diff changeset
   133
  SharedRuntime::on_slowpath_allocation_exit(thread);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   134
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   135
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   136
JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_array_common(JavaThread* thread, Klass* array_klass, jint length, bool null_on_fail))
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   137
  JRT_BLOCK;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   138
  // Note: no handle for klass needed since they are not used
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   139
  //       anymore after new_objArray() and no GC can happen before.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   140
  //       (This may have to change if this code changes!)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   141
  assert(array_klass->is_klass(), "not a class");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   142
  oop obj;
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33198
diff changeset
   143
  if (array_klass->is_typeArray_klass()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   144
    BasicType elt_type = TypeArrayKlass::cast(array_klass)->element_type();
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   145
    RetryableAllocationMark ram(thread, null_on_fail);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   146
    obj = oopFactory::new_typeArray(elt_type, length, CHECK);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   147
  } else {
36603
0bc3ad031d60 8141420: Compiler runtime entries don't hold Klass* from being GCed
vlivanov
parents: 36594
diff changeset
   148
    Handle holder(THREAD, array_klass->klass_holder()); // keep the klass alive
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   149
    Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass();
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   150
    RetryableAllocationMark ram(thread, null_on_fail);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   151
    obj = oopFactory::new_objArray(elem_klass, length, CHECK);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   152
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   153
  thread->set_vm_result(obj);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   154
  // This is pretty rare but this runtime patch is stressful to deoptimization
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   155
  // if we deoptimize here so force a deopt to stress the path.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   156
  if (DeoptimizeALot) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   157
    static int deopts = 0;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   158
    // Alternate between deoptimizing and raising an error (which will also cause a deopt)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   159
    if (deopts++ % 2 == 0) {
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   160
      if (null_on_fail) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   161
        return;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   162
      } else {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   163
        ResourceMark rm(THREAD);
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   164
        THROW(vmSymbols::java_lang_OutOfMemoryError());
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   165
      }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   166
    } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   167
      deopt_caller();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   168
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   169
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   170
  JRT_BLOCK_END;
48961
120b61d50f85 8195103: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48105
diff changeset
   171
  SharedRuntime::on_slowpath_allocation_exit(thread);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   172
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   173
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   174
JRT_ENTRY(void, JVMCIRuntime::new_multi_array_common(JavaThread* thread, Klass* klass, int rank, jint* dims, bool null_on_fail))
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   175
  assert(klass->is_klass(), "not a class");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   176
  assert(rank >= 1, "rank must be nonzero");
36603
0bc3ad031d60 8141420: Compiler runtime entries don't hold Klass* from being GCed
vlivanov
parents: 36594
diff changeset
   177
  Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   178
  RetryableAllocationMark ram(thread, null_on_fail);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   179
  oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   180
  thread->set_vm_result(obj);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   181
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   182
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   183
JRT_ENTRY(void, JVMCIRuntime::dynamic_new_array_common(JavaThread* thread, oopDesc* element_mirror, jint length, bool null_on_fail))
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   184
  RetryableAllocationMark ram(thread, null_on_fail);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   185
  oop obj = Reflection::reflect_new_array(element_mirror, length, CHECK);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   186
  thread->set_vm_result(obj);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   187
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   188
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   189
JRT_ENTRY(void, JVMCIRuntime::dynamic_new_instance_common(JavaThread* thread, oopDesc* type_mirror, bool null_on_fail))
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46271
diff changeset
   190
  InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(type_mirror));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   191
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   192
  if (klass == NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   193
    ResourceMark rm(THREAD);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   194
    THROW(vmSymbols::java_lang_InstantiationException());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   195
  }
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   196
  RetryableAllocationMark ram(thread, null_on_fail);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   197
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   198
  // Create new instance (the receiver)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   199
  klass->check_valid_for_instantiation(false, CHECK);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   200
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   201
  if (null_on_fail) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   202
    if (!klass->is_initialized()) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   203
      // Cannot re-execute class initialization without side effects
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   204
      // so return without attempting the initialization
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   205
      return;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   206
    }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   207
  } else {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   208
    // Make sure klass gets initialized
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   209
    klass->initialize(CHECK);
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   210
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   211
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   212
  oop obj = klass->allocate_instance(CHECK);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   213
  thread->set_vm_result(obj);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   214
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   215
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   216
extern void vm_exit(int code);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   217
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   218
// Enter this method from compiled code handler below. This is where we transition
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   219
// to VM mode. This is done as a helper routine so that the method called directly
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   220
// from compiled code does not have to transition to VM. This allows the entry
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   221
// method to see if the nmethod that we have just looked up a handler for has
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   222
// been deoptimized while we were in the vm. This simplifies the assembly code
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   223
// cpu directories.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   224
//
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   225
// We are entering here from exception stub (via the entry method below)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   226
// If there is a compiled exception handler in this method, we will continue there;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   227
// otherwise we will unwind the stack and continue at the caller of top frame method
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   228
// Note: we enter in Java using a special JRT wrapper. This wrapper allows us to
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   229
// control the area where we can allow a safepoint. After we exit the safepoint area we can
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   230
// check to see if the handler we are going to return is now in a nmethod that has
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   231
// been deoptimized. If that is the case we return the deopt blob
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   232
// unpack_with_exception entry instead. This makes life for the exception blob easier
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   233
// because making that same check and diverting is painful from assembly language.
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   234
JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* thread, oopDesc* ex, address pc, CompiledMethod*& cm))
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   235
  // Reset method handle flag.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   236
  thread->set_is_method_handle_return(false);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   237
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   238
  Handle exception(thread, ex);
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   239
  cm = CodeCache::find_compiled(pc);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   240
  assert(cm != NULL, "this is not a compiled method");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   241
  // Adjust the pc as needed/
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   242
  if (cm->is_deopt_pc(pc)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   243
    RegisterMap map(thread, false);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   244
    frame exception_frame = thread->last_frame().sender(&map);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   245
    // if the frame isn't deopted then pc must not correspond to the caller of last_frame
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   246
    assert(exception_frame.is_deoptimized_frame(), "must be deopted");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   247
    pc = exception_frame.pc();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   248
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   249
#ifdef ASSERT
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   250
  assert(exception.not_null(), "NULL exceptions should be handled by throw_exception");
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   251
  assert(oopDesc::is_oop(exception()), "just checking");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   252
  // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   253
  if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   254
    if (ExitVMOnVerifyError) vm_exit(-1);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   255
    ShouldNotReachHere();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   256
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   257
#endif
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   258
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   259
  // Check the stack guard pages and reenable them if necessary and there is
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   260
  // enough space on the stack to do so.  Use fast exceptions only if the guard
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   261
  // pages are enabled.
35071
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34192
diff changeset
   262
  bool guard_pages_enabled = thread->stack_guards_enabled();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   263
  if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   264
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   265
  if (JvmtiExport::can_post_on_exceptions()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   266
    // To ensure correct notification of exception catches and throws
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   267
    // we have to deoptimize here.  If we attempted to notify the
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   268
    // catches and throws during this exception lookup it's possible
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   269
    // we could deoptimize on the way out of the VM and end back in
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   270
    // the interpreter at the throw site.  This would result in double
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   271
    // notifications since the interpreter would also notify about
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   272
    // these same catches and throws as it unwound the frame.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   273
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   274
    RegisterMap reg_map(thread);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   275
    frame stub_frame = thread->last_frame();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   276
    frame caller_frame = stub_frame.sender(&reg_map);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   277
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   278
    // We don't really want to deoptimize the nmethod itself since we
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   279
    // can actually continue in the exception handler ourselves but I
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   280
    // don't see an easy way to have the desired effect.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   281
    Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   282
    assert(caller_is_deopted(), "Must be deoptimized");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   283
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   284
    return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   285
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   286
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   287
  // ExceptionCache is used only for exceptions at call sites and not for implicit exceptions
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   288
  if (guard_pages_enabled) {
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   289
    address fast_continuation = cm->handler_for_exception_and_pc(exception, pc);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   290
    if (fast_continuation != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   291
      // Set flag if return address is a method handle call site.
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   292
      thread->set_is_method_handle_return(cm->is_method_handle_return(pc));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   293
      return fast_continuation;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   294
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   295
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   296
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   297
  // If the stack guard pages are enabled, check whether there is a handler in
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   298
  // the current method.  Otherwise (guard pages disabled), force an unwind and
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   299
  // skip the exception cache update (i.e., just leave continuation==NULL).
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   300
  address continuation = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   301
  if (guard_pages_enabled) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   302
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   303
    // New exception handling mechanism can support inlined methods
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   304
    // with exception handlers since the mappings are from PC to PC
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   305
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   306
    // debugging support
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   307
    // tracing
35216
71c463a17b3b 8141211: Convert TraceExceptions to Unified Logging
rprotacio
parents: 35071
diff changeset
   308
    if (log_is_enabled(Info, exceptions)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   309
      ResourceMark rm;
36333
dcca1e98a2ab 8150738: [JVMCI] runtime/CommandLine/TraceExceptionsTest.java fails with: java.lang.RuntimeException: '<a 'java/lang/ClassNotFoundException': NoClassFound>' missing
twisti
parents: 35835
diff changeset
   310
      stringStream tempst;
51314
82adcc8ad853 8208604: Metadata::print_value_string() compares 'this' to NULL
hseigel
parents: 51180
diff changeset
   311
      assert(cm->method() != NULL, "Unexpected null method()");
36333
dcca1e98a2ab 8150738: [JVMCI] runtime/CommandLine/TraceExceptionsTest.java fails with: java.lang.RuntimeException: '<a 'java/lang/ClassNotFoundException': NoClassFound>' missing
twisti
parents: 35835
diff changeset
   312
      tempst.print("compiled method <%s>\n"
dcca1e98a2ab 8150738: [JVMCI] runtime/CommandLine/TraceExceptionsTest.java fails with: java.lang.RuntimeException: '<a 'java/lang/ClassNotFoundException': NoClassFound>' missing
twisti
parents: 35835
diff changeset
   313
                   " at PC" INTPTR_FORMAT " for thread " INTPTR_FORMAT,
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   314
                   cm->method()->print_value_string(), p2i(pc), p2i(thread));
54973
0927d8c7296f 8224487: outputStream should not be copyable
stuefe
parents: 54847
diff changeset
   315
      Exceptions::log_exception(exception, tempst.as_string());
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   316
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   317
    // for AbortVMOnException flag
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   318
    NOT_PRODUCT(Exceptions::debug_check_abort(exception));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   319
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   320
    // Clear out the exception oop and pc since looking up an
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   321
    // exception handler can cause class loading, which might throw an
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   322
    // exception and those fields are expected to be clear during
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   323
    // normal bytecode execution.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   324
    thread->clear_exception_oop_and_pc();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   325
41057
f77b9d9e0e4c 8164480: Crash with assert(handler_address == SharedRuntime::compute_compiled_exc_handler(..) failed: Must be the same
thartmann
parents: 40093
diff changeset
   326
    bool recursive_exception = false;
f77b9d9e0e4c 8164480: Crash with assert(handler_address == SharedRuntime::compute_compiled_exc_handler(..) failed: Must be the same
thartmann
parents: 40093
diff changeset
   327
    continuation = SharedRuntime::compute_compiled_exc_handler(cm, pc, exception, false, false, recursive_exception);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   328
    // If an exception was thrown during exception dispatch, the exception oop may have changed
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   329
    thread->set_exception_oop(exception());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   330
    thread->set_exception_pc(pc);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   331
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   332
    // The exception cache is used only for non-implicit exceptions
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   333
    // Update the exception cache only when another exception did
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   334
    // occur during the computation of the compiled exception handler
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   335
    // (e.g., when loading the class of the catch type).
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   336
    // Checking for exception oop equality is not
41057
f77b9d9e0e4c 8164480: Crash with assert(handler_address == SharedRuntime::compute_compiled_exc_handler(..) failed: Must be the same
thartmann
parents: 40093
diff changeset
   337
    // sufficient because some exceptions are pre-allocated and reused.
f77b9d9e0e4c 8164480: Crash with assert(handler_address == SharedRuntime::compute_compiled_exc_handler(..) failed: Must be the same
thartmann
parents: 40093
diff changeset
   338
    if (continuation != NULL && !recursive_exception && !SharedRuntime::deopt_blob()->contains(continuation)) {
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   339
      cm->add_handler_for_exception_and_pc(exception, pc, continuation);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   340
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   341
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   342
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   343
  // Set flag if return address is a method handle call site.
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   344
  thread->set_is_method_handle_return(cm->is_method_handle_return(pc));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   345
35216
71c463a17b3b 8141211: Convert TraceExceptions to Unified Logging
rprotacio
parents: 35071
diff changeset
   346
  if (log_is_enabled(Info, exceptions)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   347
    ResourceMark rm;
35216
71c463a17b3b 8141211: Convert TraceExceptions to Unified Logging
rprotacio
parents: 35071
diff changeset
   348
    log_info(exceptions)("Thread " PTR_FORMAT " continuing at PC " PTR_FORMAT
71c463a17b3b 8141211: Convert TraceExceptions to Unified Logging
rprotacio
parents: 35071
diff changeset
   349
                         " for exception thrown at PC " PTR_FORMAT,
71c463a17b3b 8141211: Convert TraceExceptions to Unified Logging
rprotacio
parents: 35071
diff changeset
   350
                         p2i(thread), p2i(continuation), p2i(pc));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   351
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   352
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   353
  return continuation;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   354
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   355
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   356
// Enter this method from compiled code only if there is a Java exception handler
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   357
// in the method handling the exception.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   358
// We are entering here from exception stub. We don't do a normal VM transition here.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   359
// We do it in a helper. This is so we can check to see if the nmethod we have just
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   360
// searched for an exception handler has been deoptimized in the meantime.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   361
address JVMCIRuntime::exception_handler_for_pc(JavaThread* thread) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   362
  oop exception = thread->exception_oop();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   363
  address pc = thread->exception_pc();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   364
  // Still in Java mode
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   365
  DEBUG_ONLY(ResetNoHandleMark rnhm);
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   366
  CompiledMethod* cm = NULL;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   367
  address continuation = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   368
  {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   369
    // Enter VM mode by calling the helper
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   370
    ResetNoHandleMark rnhm;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   371
    continuation = exception_handler_for_pc_helper(thread, exception, pc, cm);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   372
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   373
  // Back in JAVA, use no oops DON'T safepoint
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   374
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   375
  // Now check to see if the compiled method we were called from is now deoptimized.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   376
  // If so we must return to the deopt blob and deoptimize the nmethod
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   377
  if (cm != NULL && caller_is_deopted()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   378
    continuation = SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   379
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   380
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   381
  assert(continuation != NULL, "no handler found");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   382
  return continuation;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   383
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   384
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   385
JRT_ENTRY_NO_ASYNC(void, JVMCIRuntime::monitorenter(JavaThread* thread, oopDesc* obj, BasicLock* lock))
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   386
  IF_TRACE_jvmci_3 {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   387
    char type[O_BUFLEN];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   388
    obj->klass()->name()->as_C_string(type, O_BUFLEN);
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 55635
diff changeset
   389
    markWord mark = obj->mark();
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 55635
diff changeset
   390
    TRACE_jvmci_3("%s: entered locking slow case with obj=" INTPTR_FORMAT ", type=%s, mark=" INTPTR_FORMAT ", lock=" INTPTR_FORMAT, thread->name(), p2i(obj), type, mark.value(), p2i(lock));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   391
    tty->flush();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   392
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   393
  if (PrintBiasedLockingStatistics) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   394
    Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   395
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   396
  Handle h_obj(thread, obj);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   397
  assert(oopDesc::is_oop(h_obj()), "must be NULL or an object");
57893
49fea19f0726 8229844: Remove attempt_rebias parameter from revoke_and_rebias()
pchilanomate
parents: 57777
diff changeset
   398
  ObjectSynchronizer::enter(h_obj, lock, THREAD);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   399
  TRACE_jvmci_3("%s: exiting locking slow with obj=" INTPTR_FORMAT, thread->name(), p2i(obj));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   400
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   401
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   402
JRT_LEAF(void, JVMCIRuntime::monitorexit(JavaThread* thread, oopDesc* obj, BasicLock* lock))
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   403
  assert(thread == JavaThread::current(), "threads must correspond");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   404
  assert(thread->last_Java_sp(), "last_Java_sp must be set");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   405
  // monitorexit is non-blocking (leaf routine) => no exceptions can be thrown
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   406
  EXCEPTION_MARK;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   407
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   408
#ifdef ASSERT
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 46727
diff changeset
   409
  if (!oopDesc::is_oop(obj)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   410
    ResetNoHandleMark rhm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   411
    nmethod* method = thread->last_frame().cb()->as_nmethod_or_null();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   412
    if (method != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   413
      tty->print_cr("ERROR in monitorexit in method %s wrong obj " INTPTR_FORMAT, method->name(), p2i(obj));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   414
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   415
    thread->print_stack_on(tty);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   416
    assert(false, "invalid lock object pointer dected");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   417
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   418
#endif
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   419
57893
49fea19f0726 8229844: Remove attempt_rebias parameter from revoke_and_rebias()
pchilanomate
parents: 57777
diff changeset
   420
  ObjectSynchronizer::exit(obj, lock, THREAD);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   421
  IF_TRACE_jvmci_3 {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   422
    char type[O_BUFLEN];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   423
    obj->klass()->name()->as_C_string(type, O_BUFLEN);
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 55635
diff changeset
   424
    TRACE_jvmci_3("%s: exited locking slow case with obj=" INTPTR_FORMAT ", type=%s, mark=" INTPTR_FORMAT ", lock=" INTPTR_FORMAT, thread->name(), p2i(obj), type, obj->mark().value(), p2i(lock));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   425
    tty->flush();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   426
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   427
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   428
49837
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   429
// Object.notify() fast path, caller does slow path
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   430
JRT_LEAF(jboolean, JVMCIRuntime::object_notify(JavaThread *thread, oopDesc* obj))
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   431
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   432
  // Very few notify/notifyAll operations find any threads on the waitset, so
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   433
  // the dominant fast-path is to simply return.
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   434
  // Relatedly, it's critical that notify/notifyAll be fast in order to
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   435
  // reduce lock hold times.
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   436
  if (!SafepointSynchronize::is_synchronizing()) {
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   437
    if (ObjectSynchronizer::quick_notify(obj, thread, false)) {
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   438
      return true;
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   439
    }
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   440
  }
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   441
  return false; // caller must perform slow path
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   442
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   443
JRT_END
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   444
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   445
// Object.notifyAll() fast path, caller does slow path
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   446
JRT_LEAF(jboolean, JVMCIRuntime::object_notifyAll(JavaThread *thread, oopDesc* obj))
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   447
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   448
  if (!SafepointSynchronize::is_synchronizing() ) {
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   449
    if (ObjectSynchronizer::quick_notify(obj, thread, true)) {
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   450
      return true;
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   451
    }
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   452
  }
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   453
  return false; // caller must perform slow path
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   454
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   455
JRT_END
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   456
38229
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   457
JRT_ENTRY(void, JVMCIRuntime::throw_and_post_jvmti_exception(JavaThread* thread, const char* exception, const char* message))
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   458
  TempNewSymbol symbol = SymbolTable::new_symbol(exception);
38229
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   459
  SharedRuntime::throw_and_post_jvmti_exception(thread, symbol, message);
36842
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   460
JRT_END
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   461
38229
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   462
JRT_ENTRY(void, JVMCIRuntime::throw_klass_external_name_exception(JavaThread* thread, const char* exception, Klass* klass))
36842
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   463
  ResourceMark rm(thread);
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   464
  TempNewSymbol symbol = SymbolTable::new_symbol(exception);
38229
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   465
  SharedRuntime::throw_and_post_jvmti_exception(thread, symbol, klass->external_name());
36842
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   466
JRT_END
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   467
38229
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   468
JRT_ENTRY(void, JVMCIRuntime::throw_class_cast_exception(JavaThread* thread, const char* exception, Klass* caster_klass, Klass* target_klass))
36842
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   469
  ResourceMark rm(thread);
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   470
  const char* message = SharedRuntime::generate_class_cast_message(caster_klass, target_klass);
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   471
  TempNewSymbol symbol = SymbolTable::new_symbol(exception);
38229
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   472
  SharedRuntime::throw_and_post_jvmti_exception(thread, symbol, message);
36842
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   473
JRT_END
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   474
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   475
JRT_LEAF(void, JVMCIRuntime::log_object(JavaThread* thread, oopDesc* obj, bool as_string, bool newline))
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   476
  ttyLocker ttyl;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   477
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   478
  if (obj == NULL) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   479
    tty->print("NULL");
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 46727
diff changeset
   480
  } else if (oopDesc::is_oop_or_null(obj, true) && (!as_string || !java_lang_String::is_instance(obj))) {
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 46727
diff changeset
   481
    if (oopDesc::is_oop_or_null(obj, true)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   482
      char buf[O_BUFLEN];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   483
      tty->print("%s@" INTPTR_FORMAT, obj->klass()->name()->as_C_string(buf, O_BUFLEN), p2i(obj));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   484
    } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   485
      tty->print(INTPTR_FORMAT, p2i(obj));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   486
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   487
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   488
    ResourceMark rm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   489
    assert(obj != NULL && java_lang_String::is_instance(obj), "must be");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   490
    char *buf = java_lang_String::as_utf8_string(obj);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   491
    tty->print_raw(buf);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   492
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   493
  if (newline) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   494
    tty->cr();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   495
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   496
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   497
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49837
diff changeset
   498
#if INCLUDE_G1GC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49837
diff changeset
   499
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   500
JRT_LEAF(void, JVMCIRuntime::write_barrier_pre(JavaThread* thread, oopDesc* obj))
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49480
diff changeset
   501
  G1ThreadLocalData::satb_mark_queue(thread).enqueue(obj);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   502
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   503
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   504
JRT_LEAF(void, JVMCIRuntime::write_barrier_post(JavaThread* thread, void* card_addr))
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49480
diff changeset
   505
  G1ThreadLocalData::dirty_card_queue(thread).enqueue(card_addr);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   506
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   507
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49837
diff changeset
   508
#endif // INCLUDE_G1GC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49837
diff changeset
   509
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   510
JRT_LEAF(jboolean, JVMCIRuntime::validate_object(JavaThread* thread, oopDesc* parent, oopDesc* child))
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   511
  bool ret = true;
54375
a5ce9300462f 8221648: Remove CollectedHeap::is_in_closed_subset()
pliden
parents: 53582
diff changeset
   512
  if(!Universe::heap()->is_in(parent)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   513
    tty->print_cr("Parent Object " INTPTR_FORMAT " not in heap", p2i(parent));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   514
    parent->print();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   515
    ret=false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   516
  }
54375
a5ce9300462f 8221648: Remove CollectedHeap::is_in_closed_subset()
pliden
parents: 53582
diff changeset
   517
  if(!Universe::heap()->is_in(child)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   518
    tty->print_cr("Child Object " INTPTR_FORMAT " not in heap", p2i(child));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   519
    child->print();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   520
    ret=false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   521
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   522
  return (jint)ret;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   523
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   524
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   525
JRT_ENTRY(void, JVMCIRuntime::vm_error(JavaThread* thread, jlong where, jlong format, jlong value))
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   526
  ResourceMark rm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   527
  const char *error_msg = where == 0L ? "<internal JVMCI error>" : (char*) (address) where;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   528
  char *detail_msg = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   529
  if (format != 0L) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   530
    const char* buf = (char*) (address) format;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   531
    size_t detail_msg_length = strlen(buf) * 2;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   532
    detail_msg = (char *) NEW_RESOURCE_ARRAY(u_char, detail_msg_length);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   533
    jio_snprintf(detail_msg, detail_msg_length, buf, value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   534
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   535
  report_vm_error(__FILE__, __LINE__, error_msg, "%s", detail_msg);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   536
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   537
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   538
JRT_LEAF(oopDesc*, JVMCIRuntime::load_and_clear_exception(JavaThread* thread))
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   539
  oop exception = thread->exception_oop();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   540
  assert(exception != NULL, "npe");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   541
  thread->set_exception_oop(NULL);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   542
  thread->set_exception_pc(0);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   543
  return exception;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   544
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   545
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   546
PRAGMA_DIAG_PUSH
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   547
PRAGMA_FORMAT_NONLITERAL_IGNORED
50858
2d3e99a72541 8205824: Update Graal
never
parents: 49982
diff changeset
   548
JRT_LEAF(void, JVMCIRuntime::log_printf(JavaThread* thread, const char* format, jlong v1, jlong v2, jlong v3))
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   549
  ResourceMark rm;
50858
2d3e99a72541 8205824: Update Graal
never
parents: 49982
diff changeset
   550
  tty->print(format, v1, v2, v3);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   551
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   552
PRAGMA_DIAG_POP
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   553
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   554
static void decipher(jlong v, bool ignoreZero) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   555
  if (v != 0 || !ignoreZero) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   556
    void* p = (void *)(address) v;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   557
    CodeBlob* cb = CodeCache::find_blob(p);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   558
    if (cb) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   559
      if (cb->is_nmethod()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   560
        char buf[O_BUFLEN];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   561
        tty->print("%s [" INTPTR_FORMAT "+" JLONG_FORMAT "]", cb->as_nmethod_or_null()->method()->name_and_sig_as_C_string(buf, O_BUFLEN), p2i(cb->code_begin()), (jlong)((address)v - cb->code_begin()));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   562
        return;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   563
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   564
      cb->print_value_on(tty);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   565
      return;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   566
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   567
    if (Universe::heap()->is_in(p)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   568
      oop obj = oop(p);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   569
      obj->print_value_on(tty);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   570
      return;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   571
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   572
    tty->print(INTPTR_FORMAT " [long: " JLONG_FORMAT ", double %lf, char %c]",p2i((void *)v), (jlong)v, (jdouble)v, (char)v);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   573
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   574
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   575
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   576
PRAGMA_DIAG_PUSH
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   577
PRAGMA_FORMAT_NONLITERAL_IGNORED
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   578
JRT_LEAF(void, JVMCIRuntime::vm_message(jboolean vmError, jlong format, jlong v1, jlong v2, jlong v3))
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   579
  ResourceMark rm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   580
  const char *buf = (const char*) (address) format;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   581
  if (vmError) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   582
    if (buf != NULL) {
33198
dlong
parents: 33178
diff changeset
   583
      fatal(buf, v1, v2, v3);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   584
    } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   585
      fatal("<anonymous error>");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   586
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   587
  } else if (buf != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   588
    tty->print(buf, v1, v2, v3);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   589
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   590
    assert(v2 == 0, "v2 != 0");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   591
    assert(v3 == 0, "v3 != 0");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   592
    decipher(v1, false);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   593
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   594
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   595
PRAGMA_DIAG_POP
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   596
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   597
JRT_LEAF(void, JVMCIRuntime::log_primitive(JavaThread* thread, jchar typeChar, jlong value, jboolean newline))
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   598
  union {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   599
      jlong l;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   600
      jdouble d;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   601
      jfloat f;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   602
  } uu;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   603
  uu.l = value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   604
  switch (typeChar) {
38695
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   605
    case 'Z': tty->print(value == 0 ? "false" : "true"); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   606
    case 'B': tty->print("%d", (jbyte) value); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   607
    case 'C': tty->print("%c", (jchar) value); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   608
    case 'S': tty->print("%d", (jshort) value); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   609
    case 'I': tty->print("%d", (jint) value); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   610
    case 'F': tty->print("%f", uu.f); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   611
    case 'J': tty->print(JLONG_FORMAT, value); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   612
    case 'D': tty->print("%lf", uu.d); break;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   613
    default: assert(false, "unknown typeChar"); break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   614
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   615
  if (newline) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   616
    tty->cr();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   617
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   618
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   619
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   620
JRT_ENTRY(jint, JVMCIRuntime::identity_hash_code(JavaThread* thread, oopDesc* obj))
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   621
  return (jint) obj->identity_hash();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   622
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   623
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   624
JRT_ENTRY(jint, JVMCIRuntime::test_deoptimize_call_int(JavaThread* thread, int value))
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   625
  deopt_caller();
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   626
  return (jint) value;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   627
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   628
40034
4a288aaf8511 8160121: [JVMCI] JvmciNotifyBootstrapFinishedEventTest.java failed NoClassDefFoundError: jdk/vm/ci/runtime/JVMCI
never
parents: 38695
diff changeset
   629
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   630
// private static JVMCIRuntime JVMCI.initializeRuntime()
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   631
JVM_ENTRY_NO_ENV(jobject, JVM_GetJVMCIRuntime(JNIEnv *env, jclass c))
54732
2d012a75d35c 8223332: Update JVMCI
kvn
parents: 54669
diff changeset
   632
  JNI_JVMCIENV(thread, env);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   633
  if (!EnableJVMCI) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   634
    JVMCI_THROW_MSG_NULL(InternalError, "JVMCI is not enabled");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   635
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   636
  JVMCIENV->runtime()->initialize_HotSpotJVMCIRuntime(JVMCI_CHECK_NULL);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   637
  JVMCIObject runtime = JVMCIENV->runtime()->get_HotSpotJVMCIRuntime(JVMCI_CHECK_NULL);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   638
  return JVMCIENV->get_jobject(runtime);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   639
JVM_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   640
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   641
void JVMCIRuntime::call_getCompiler(TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   642
  THREAD_JVMCIENV(JavaThread::current());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   643
  JVMCIObject jvmciRuntime = JVMCIRuntime::get_HotSpotJVMCIRuntime(JVMCI_CHECK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   644
  initialize(JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   645
  JVMCIENV->call_HotSpotJVMCIRuntime_getCompiler(jvmciRuntime, JVMCI_CHECK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   646
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   647
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   648
void JVMCINMethodData::initialize(
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   649
  int nmethod_mirror_index,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   650
  const char* name,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   651
  FailedSpeculation** failed_speculations)
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   652
{
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   653
  _failed_speculations = failed_speculations;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   654
  _nmethod_mirror_index = nmethod_mirror_index;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   655
  if (name != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   656
    _has_name = true;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   657
    char* dest = (char*) this->name();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   658
    strcpy(dest, name);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   659
  } else {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   660
    _has_name = false;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   661
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   662
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   663
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   664
void JVMCINMethodData::add_failed_speculation(nmethod* nm, jlong speculation) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   665
  uint index = (speculation >> 32) & 0xFFFFFFFF;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   666
  int length = (int) speculation;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   667
  if (index + length > (uint) nm->speculations_size()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   668
    fatal(INTPTR_FORMAT "[index: %d, length: %d] out of bounds wrt encoded speculations of length %u", speculation, index, length, nm->speculations_size());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   669
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   670
  address data = nm->speculations_begin() + index;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   671
  FailedSpeculation::add_failed_speculation(nm, _failed_speculations, data, length);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   672
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   673
55454
8892555795cd 8223794: applications/kitchensink/Kitchensink.java crash bad oop with Graal
kvn
parents: 55317
diff changeset
   674
oop JVMCINMethodData::get_nmethod_mirror(nmethod* nm, bool phantom_ref) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   675
  if (_nmethod_mirror_index == -1) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   676
    return NULL;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   677
  }
55454
8892555795cd 8223794: applications/kitchensink/Kitchensink.java crash bad oop with Graal
kvn
parents: 55317
diff changeset
   678
  if (phantom_ref) {
8892555795cd 8223794: applications/kitchensink/Kitchensink.java crash bad oop with Graal
kvn
parents: 55317
diff changeset
   679
    return nm->oop_at_phantom(_nmethod_mirror_index);
8892555795cd 8223794: applications/kitchensink/Kitchensink.java crash bad oop with Graal
kvn
parents: 55317
diff changeset
   680
  } else {
8892555795cd 8223794: applications/kitchensink/Kitchensink.java crash bad oop with Graal
kvn
parents: 55317
diff changeset
   681
    return nm->oop_at(_nmethod_mirror_index);
8892555795cd 8223794: applications/kitchensink/Kitchensink.java crash bad oop with Graal
kvn
parents: 55317
diff changeset
   682
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   683
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   684
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   685
void JVMCINMethodData::set_nmethod_mirror(nmethod* nm, oop new_mirror) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   686
  assert(_nmethod_mirror_index != -1, "cannot set JVMCI mirror for nmethod");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   687
  oop* addr = nm->oop_addr_at(_nmethod_mirror_index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   688
  assert(new_mirror != NULL, "use clear_nmethod_mirror to clear the mirror");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   689
  assert(*addr == NULL, "cannot overwrite non-null mirror");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   690
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   691
  *addr = new_mirror;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   692
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   693
  // Since we've patched some oops in the nmethod,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   694
  // (re)register it with the heap.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   695
  Universe::heap()->register_nmethod(nm);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   696
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   697
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   698
void JVMCINMethodData::clear_nmethod_mirror(nmethod* nm) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   699
  if (_nmethod_mirror_index != -1) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   700
    oop* addr = nm->oop_addr_at(_nmethod_mirror_index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   701
    *addr = NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   702
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   703
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   704
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   705
void JVMCINMethodData::invalidate_nmethod_mirror(nmethod* nm) {
59260
b0a649295f25 8234359: [JVMCI] invalidate_nmethod_mirror shouldn't use a phantom reference
never
parents: 59252
diff changeset
   706
  oop nmethod_mirror = get_nmethod_mirror(nm, /* phantom_ref */ false);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   707
  if (nmethod_mirror == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   708
    return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   709
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   710
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   711
  // Update the values in the mirror if it still refers to nm.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   712
  // We cannot use JVMCIObject to wrap the mirror as this is called
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   713
  // during GC, forbidding the creation of JNIHandles.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   714
  JVMCIEnv* jvmciEnv = NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   715
  nmethod* current = (nmethod*) HotSpotJVMCI::InstalledCode::address(jvmciEnv, nmethod_mirror);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   716
  if (nm == current) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   717
    if (!nm->is_alive()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   718
      // Break the link from the mirror to nm such that
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   719
      // future invocations via the mirror will result in
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   720
      // an InvalidInstalledCodeException.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   721
      HotSpotJVMCI::InstalledCode::set_address(jvmciEnv, nmethod_mirror, 0);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   722
      HotSpotJVMCI::InstalledCode::set_entryPoint(jvmciEnv, nmethod_mirror, 0);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   723
    } else if (nm->is_not_entrant()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   724
      // Zero the entry point so any new invocation will fail but keep
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   725
      // the address link around that so that existing activations can
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   726
      // be deoptimized via the mirror (i.e. JVMCIEnv::invalidate_installed_code).
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   727
      HotSpotJVMCI::InstalledCode::set_entryPoint(jvmciEnv, nmethod_mirror, 0);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   728
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   729
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   730
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   731
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   732
void JVMCIRuntime::initialize_HotSpotJVMCIRuntime(JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   733
  if (is_HotSpotJVMCIRuntime_initialized()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   734
    if (JVMCIENV->is_hotspot() && UseJVMCINativeLibrary) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   735
      JVMCI_THROW_MSG(InternalError, "JVMCI has already been enabled in the JVMCI shared library");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   736
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   737
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   738
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   739
  initialize(JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   740
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   741
  // This should only be called in the context of the JVMCI class being initialized
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   742
  JVMCIObject result = JVMCIENV->call_HotSpotJVMCIRuntime_runtime(JVMCI_CHECK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   743
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   744
  _HotSpotJVMCIRuntime_instance = JVMCIENV->make_global(result);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   745
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   746
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   747
void JVMCIRuntime::initialize(JVMCIEnv* JVMCIENV) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   748
  assert(this != NULL, "sanity");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   749
  // Check first without JVMCI_lock
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   750
  if (_initialized) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   751
    return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   752
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   753
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   754
  MutexLocker locker(JVMCI_lock);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   755
  // Check again under JVMCI_lock
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   756
  if (_initialized) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   757
    return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   758
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   759
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   760
  while (_being_initialized) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   761
    JVMCI_lock->wait();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   762
    if (_initialized) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   763
      return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   764
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   765
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   766
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   767
  _being_initialized = true;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   768
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   769
  {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   770
    MutexUnlocker unlock(JVMCI_lock);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   771
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   772
    HandleMark hm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   773
    ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   774
    JavaThread* THREAD = JavaThread::current();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   775
    if (JVMCIENV->is_hotspot()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   776
      HotSpotJVMCI::compute_offsets(CHECK_EXIT);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   777
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   778
      JNIAccessMark jni(JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   779
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   780
      JNIJVMCI::initialize_ids(jni.env());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   781
      if (jni()->ExceptionCheck()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   782
        jni()->ExceptionDescribe();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   783
        fatal("JNI exception during init");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   784
      }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   785
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   786
    create_jvmci_primitive_type(T_BOOLEAN, JVMCI_CHECK_EXIT_((void)0));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   787
    create_jvmci_primitive_type(T_BYTE, JVMCI_CHECK_EXIT_((void)0));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   788
    create_jvmci_primitive_type(T_CHAR, JVMCI_CHECK_EXIT_((void)0));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   789
    create_jvmci_primitive_type(T_SHORT, JVMCI_CHECK_EXIT_((void)0));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   790
    create_jvmci_primitive_type(T_INT, JVMCI_CHECK_EXIT_((void)0));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   791
    create_jvmci_primitive_type(T_LONG, JVMCI_CHECK_EXIT_((void)0));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   792
    create_jvmci_primitive_type(T_FLOAT, JVMCI_CHECK_EXIT_((void)0));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   793
    create_jvmci_primitive_type(T_DOUBLE, JVMCI_CHECK_EXIT_((void)0));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   794
    create_jvmci_primitive_type(T_VOID, JVMCI_CHECK_EXIT_((void)0));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   795
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   796
    if (!JVMCIENV->is_hotspot()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   797
      JVMCIENV->copy_saved_properties();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   798
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   799
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   800
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   801
  _initialized = true;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   802
  _being_initialized = false;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   803
  JVMCI_lock->notify_all();
49192
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 48961
diff changeset
   804
}
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 48961
diff changeset
   805
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   806
JVMCIObject JVMCIRuntime::create_jvmci_primitive_type(BasicType type, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   807
  Thread* THREAD = Thread::current();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   808
  // These primitive types are long lived and are created before the runtime is fully set up
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   809
  // so skip registering them for scanning.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   810
  JVMCIObject mirror = JVMCIENV->get_object_constant(java_lang_Class::primitive_mirror(type), false, true);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   811
  if (JVMCIENV->is_hotspot()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   812
    JavaValue result(T_OBJECT);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   813
    JavaCallArguments args;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   814
    args.push_oop(Handle(THREAD, HotSpotJVMCI::resolve(mirror)));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   815
    args.push_int(type2char(type));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   816
    JavaCalls::call_static(&result, HotSpotJVMCI::HotSpotResolvedPrimitiveType::klass(), vmSymbols::fromMetaspace_name(), vmSymbols::primitive_fromMetaspace_signature(), &args, CHECK_(JVMCIObject()));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   817
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   818
    return JVMCIENV->wrap(JNIHandles::make_local((oop)result.get_jobject()));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   819
  } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   820
    JNIAccessMark jni(JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   821
    jobject result = jni()->CallStaticObjectMethod(JNIJVMCI::HotSpotResolvedPrimitiveType::clazz(),
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   822
                                           JNIJVMCI::HotSpotResolvedPrimitiveType_fromMetaspace_method(),
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   823
                                           mirror.as_jobject(), type2char(type));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   824
    if (jni()->ExceptionCheck()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   825
      return JVMCIObject();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   826
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   827
    return JVMCIENV->wrap(result);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   828
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   829
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   830
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   831
void JVMCIRuntime::initialize_JVMCI(JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   832
  if (!is_HotSpotJVMCIRuntime_initialized()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   833
    initialize(JVMCI_CHECK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   834
    JVMCIENV->call_JVMCI_getRuntime(JVMCI_CHECK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   835
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   836
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   837
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   838
JVMCIObject JVMCIRuntime::get_HotSpotJVMCIRuntime(JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   839
  initialize(JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   840
  initialize_JVMCI(JVMCI_CHECK_(JVMCIObject()));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   841
  return _HotSpotJVMCIRuntime_instance;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   842
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   843
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   844
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   845
// private void CompilerToVM.registerNatives()
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   846
JVM_ENTRY_NO_ENV(void, JVM_RegisterJVMCINatives(JNIEnv *env, jclass c2vmClass))
54732
2d012a75d35c 8223332: Update JVMCI
kvn
parents: 54669
diff changeset
   847
  JNI_JVMCIENV(thread, env);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   848
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   849
  if (!EnableJVMCI) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   850
    JVMCI_THROW_MSG(InternalError, "JVMCI is not enabled");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   851
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   852
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   853
  JVMCIENV->runtime()->initialize(JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   854
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   855
  {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   856
    ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   857
    HandleMark hm(thread);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   858
    ThreadToNativeFromVM trans(thread);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   859
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   860
    // Ensure _non_oop_bits is initialized
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   861
    Universe::non_oop_word();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   862
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   863
    if (JNI_OK != env->RegisterNatives(c2vmClass, CompilerToVM::methods, CompilerToVM::methods_count())) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   864
      if (!env->ExceptionCheck()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   865
        for (int i = 0; i < CompilerToVM::methods_count(); i++) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   866
          if (JNI_OK != env->RegisterNatives(c2vmClass, CompilerToVM::methods + i, 1)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   867
            guarantee(false, "Error registering JNI method %s%s", CompilerToVM::methods[i].name, CompilerToVM::methods[i].signature);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   868
            break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   869
          }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   870
        }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   871
      } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   872
        env->ExceptionDescribe();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   873
      }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   874
      guarantee(false, "Failed registering CompilerToVM native methods");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   875
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   876
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   877
JVM_END
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   878
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   879
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   880
void JVMCIRuntime::shutdown() {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   881
  if (is_HotSpotJVMCIRuntime_initialized()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   882
    _shutdown_called = true;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   883
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   884
    THREAD_JVMCIENV(JavaThread::current());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   885
    JVMCIENV->call_HotSpotJVMCIRuntime_shutdown(_HotSpotJVMCIRuntime_instance);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   886
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   887
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   888
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   889
void JVMCIRuntime::bootstrap_finished(TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   890
  if (is_HotSpotJVMCIRuntime_initialized()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   891
    THREAD_JVMCIENV(JavaThread::current());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   892
    JVMCIENV->call_HotSpotJVMCIRuntime_bootstrapFinished(_HotSpotJVMCIRuntime_instance, JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   893
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   894
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   895
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   896
void JVMCIRuntime::describe_pending_hotspot_exception(JavaThread* THREAD, bool clear) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   897
  if (HAS_PENDING_EXCEPTION) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   898
    Handle exception(THREAD, PENDING_EXCEPTION);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   899
    const char* exception_file = THREAD->exception_file();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   900
    int exception_line = THREAD->exception_line();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   901
    CLEAR_PENDING_EXCEPTION;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   902
    if (exception->is_a(SystemDictionary::ThreadDeath_klass())) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   903
      // Don't print anything if we are being killed.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   904
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   905
      java_lang_Throwable::print_stack_trace(exception, tty);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   906
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   907
      // Clear and ignore any exceptions raised during printing
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   908
      CLEAR_PENDING_EXCEPTION;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   909
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   910
    if (!clear) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   911
      THREAD->set_pending_exception(exception(), exception_file, exception_line);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   912
    }
40074
135bb8aa1e18 8161274: [JVMCI] compiler/jvmci/events/JvmciNotifyInstallEventTest.java fails with NoClassDefFound
dnsimon
parents: 40034
diff changeset
   913
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   914
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   915
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   916
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   917
void JVMCIRuntime::exit_on_pending_exception(JVMCIEnv* JVMCIENV, const char* message) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   918
  JavaThread* THREAD = JavaThread::current();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   919
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   920
  static volatile int report_error = 0;
59252
623722a6aeb9 8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents: 59056
diff changeset
   921
  if (!report_error && Atomic::cmpxchg(&report_error, 0, 1) == 0) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   922
    // Only report an error once
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   923
    tty->print_raw_cr(message);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   924
    if (JVMCIENV != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   925
      JVMCIENV->describe_pending_exception(true);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   926
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   927
      describe_pending_hotspot_exception(THREAD, true);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   928
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   929
  } else {
58041
d8902e9c307c 8230422: Convert uninterruptible os::sleep calls to os::naked_short_sleep
dholmes
parents: 58015
diff changeset
   930
    // Allow error reporting thread to print the stack trace.
58095
adc72cd1d1f2 8230423: Move os::sleep to JavaThread::sleep
dholmes
parents: 58041
diff changeset
   931
    THREAD->sleep(200);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   932
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   933
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   934
  before_exit(THREAD);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   935
  vm_exit(-1);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   936
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   937
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   938
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   939
// Note: the logic of this method should mirror the logic of
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   940
// constantPoolOopDesc::verify_constant_pool_resolve.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   941
bool JVMCIRuntime::check_klass_accessibility(Klass* accessing_klass, Klass* resolved_klass) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   942
  if (accessing_klass->is_objArray_klass()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   943
    accessing_klass = ObjArrayKlass::cast(accessing_klass)->bottom_klass();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   944
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   945
  if (!accessing_klass->is_instance_klass()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   946
    return true;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   947
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   948
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   949
  if (resolved_klass->is_objArray_klass()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   950
    // Find the element klass, if this is an array.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   951
    resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   952
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   953
  if (resolved_klass->is_instance_klass()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   954
    Reflection::VerifyClassAccessResults result =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   955
      Reflection::verify_class_access(accessing_klass, InstanceKlass::cast(resolved_klass), true);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   956
    return result == Reflection::ACCESS_OK;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   957
  }
40074
135bb8aa1e18 8161274: [JVMCI] compiler/jvmci/events/JvmciNotifyInstallEventTest.java fails with NoClassDefFound
dnsimon
parents: 40034
diff changeset
   958
  return true;
135bb8aa1e18 8161274: [JVMCI] compiler/jvmci/events/JvmciNotifyInstallEventTest.java fails with NoClassDefFound
dnsimon
parents: 40034
diff changeset
   959
}
135bb8aa1e18 8161274: [JVMCI] compiler/jvmci/events/JvmciNotifyInstallEventTest.java fails with NoClassDefFound
dnsimon
parents: 40034
diff changeset
   960
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   961
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   962
Klass* JVMCIRuntime::get_klass_by_name_impl(Klass*& accessing_klass,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   963
                                          const constantPoolHandle& cpool,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   964
                                          Symbol* sym,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   965
                                          bool require_local) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   966
  JVMCI_EXCEPTION_CONTEXT;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   967
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   968
  // Now we need to check the SystemDictionary
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58226
diff changeset
   969
  if (sym->char_at(0) == JVM_SIGNATURE_CLASS &&
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58226
diff changeset
   970
      sym->char_at(sym->utf8_length()-1) == JVM_SIGNATURE_ENDCLASS) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   971
    // This is a name from a signature.  Strip off the trimmings.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   972
    // Call recursive to keep scope of strippedsym.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   973
    TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1,
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   974
                                                        sym->utf8_length()-2);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   975
    return get_klass_by_name_impl(accessing_klass, cpool, strippedsym, require_local);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   976
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   977
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   978
  Handle loader(THREAD, (oop)NULL);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   979
  Handle domain(THREAD, (oop)NULL);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   980
  if (accessing_klass != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   981
    loader = Handle(THREAD, accessing_klass->class_loader());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   982
    domain = Handle(THREAD, accessing_klass->protection_domain());
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   983
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   984
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   985
  Klass* found_klass;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   986
  {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   987
    ttyUnlocker ttyul;  // release tty lock to avoid ordering problems
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   988
    MutexLocker ml(Compile_lock);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   989
    if (!require_local) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   990
      found_klass = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, CHECK_NULL);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   991
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   992
      found_klass = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, CHECK_NULL);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   993
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   994
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   995
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   996
  // If we fail to find an array klass, look again for its element type.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   997
  // The element type may be available either locally or via constraints.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   998
  // In either case, if we can find the element type in the system dictionary,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   999
  // we must build an array type around it.  The CI requires array klasses
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1000
  // to be loaded if their element klasses are loaded, except when memory
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1001
  // is exhausted.
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58226
diff changeset
  1002
  if (sym->char_at(0) == JVM_SIGNATURE_ARRAY &&
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58226
diff changeset
  1003
      (sym->char_at(1) == JVM_SIGNATURE_ARRAY || sym->char_at(1) == JVM_SIGNATURE_CLASS)) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1004
    // We have an unloaded array.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1005
    // Build it on the fly if the element class exists.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1006
    TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1,
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
  1007
                                                     sym->utf8_length()-1);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1008
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1009
    // Get element Klass recursively.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1010
    Klass* elem_klass =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1011
      get_klass_by_name_impl(accessing_klass,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1012
                             cpool,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1013
                             elem_sym,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1014
                             require_local);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1015
    if (elem_klass != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1016
      // Now make an array for it
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1017
      return elem_klass->array_klass(THREAD);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1018
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1019
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1020
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1021
  if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1022
    // Look inside the constant pool for pre-resolved class entries.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1023
    for (int i = cpool->length() - 1; i >= 1; i--) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1024
      if (cpool->tag_at(i).is_klass()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1025
        Klass*  kls = cpool->resolved_klass_at(i);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1026
        if (kls->name() == sym) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1027
          return kls;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1028
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1029
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1030
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1031
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1032
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1033
  return found_klass;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1034
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1035
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1036
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1037
Klass* JVMCIRuntime::get_klass_by_name(Klass* accessing_klass,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1038
                                  Symbol* klass_name,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1039
                                  bool require_local) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1040
  ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1041
  constantPoolHandle cpool;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1042
  return get_klass_by_name_impl(accessing_klass,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1043
                                                 cpool,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1044
                                                 klass_name,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1045
                                                 require_local);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1046
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1047
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1048
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1049
// Implementation of get_klass_by_index.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1050
Klass* JVMCIRuntime::get_klass_by_index_impl(const constantPoolHandle& cpool,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1051
                                        int index,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1052
                                        bool& is_accessible,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1053
                                        Klass* accessor) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1054
  JVMCI_EXCEPTION_CONTEXT;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1055
  Klass* klass = ConstantPool::klass_at_if_loaded(cpool, index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1056
  Symbol* klass_name = NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1057
  if (klass == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1058
    klass_name = cpool->klass_name_at(index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1059
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1060
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1061
  if (klass == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1062
    // Not found in constant pool.  Use the name to do the lookup.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1063
    Klass* k = get_klass_by_name_impl(accessor,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1064
                                        cpool,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1065
                                        klass_name,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1066
                                        false);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1067
    // Calculate accessibility the hard way.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1068
    if (k == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1069
      is_accessible = false;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1070
    } else if (k->class_loader() != accessor->class_loader() &&
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1071
               get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1072
      // Loaded only remotely.  Not linked yet.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1073
      is_accessible = false;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1074
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1075
      // Linked locally, and we must also check public/private, etc.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1076
      is_accessible = check_klass_accessibility(accessor, k);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1077
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1078
    if (!is_accessible) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1079
      return NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1080
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1081
    return k;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1082
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1083
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1084
  // It is known to be accessible, since it was found in the constant pool.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1085
  is_accessible = true;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1086
  return klass;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1087
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1088
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1089
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1090
// Get a klass from the constant pool.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1091
Klass* JVMCIRuntime::get_klass_by_index(const constantPoolHandle& cpool,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1092
                                   int index,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1093
                                   bool& is_accessible,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1094
                                   Klass* accessor) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1095
  ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1096
  Klass* result = get_klass_by_index_impl(cpool, index, is_accessible, accessor);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1097
  return result;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1098
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1099
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1100
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1101
// Implementation of get_field_by_index.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1102
//
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1103
// Implementation note: the results of field lookups are cached
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1104
// in the accessor klass.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1105
void JVMCIRuntime::get_field_by_index_impl(InstanceKlass* klass, fieldDescriptor& field_desc,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1106
                                        int index) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1107
  JVMCI_EXCEPTION_CONTEXT;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1108
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1109
  assert(klass->is_linked(), "must be linked before using its constant-pool");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1110
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1111
  constantPoolHandle cpool(thread, klass->constants());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1112
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1113
  // Get the field's name, signature, and type.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1114
  Symbol* name  = cpool->name_ref_at(index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1115
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1116
  int nt_index = cpool->name_and_type_ref_index_at(index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1117
  int sig_index = cpool->signature_ref_index_at(nt_index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1118
  Symbol* signature = cpool->symbol_at(sig_index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1119
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1120
  // Get the field's declared holder.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1121
  int holder_index = cpool->klass_ref_index_at(index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1122
  bool holder_is_accessible;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1123
  Klass* declared_holder = get_klass_by_index(cpool, holder_index,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1124
                                               holder_is_accessible,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1125
                                               klass);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1126
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1127
  // The declared holder of this field may not have been loaded.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1128
  // Bail out with partial field information.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1129
  if (!holder_is_accessible) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1130
    return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1131
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1132
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1133
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1134
  // Perform the field lookup.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1135
  Klass*  canonical_holder =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1136
    InstanceKlass::cast(declared_holder)->find_field(name, signature, &field_desc);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1137
  if (canonical_holder == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1138
    return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1139
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1140
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1141
  assert(canonical_holder == field_desc.field_holder(), "just checking");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1142
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1143
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1144
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1145
// Get a field by index from a klass's constant pool.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1146
void JVMCIRuntime::get_field_by_index(InstanceKlass* accessor, fieldDescriptor& fd, int index) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1147
  ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1148
  return get_field_by_index_impl(accessor, fd, index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1149
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1150
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1151
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1152
// Perform an appropriate method lookup based on accessor, holder,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1153
// name, signature, and bytecode.
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1154
Method* JVMCIRuntime::lookup_method(InstanceKlass* accessor,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1155
                                    Klass*        holder,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1156
                                    Symbol*       name,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1157
                                    Symbol*       sig,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1158
                                    Bytecodes::Code bc,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1159
                                    constantTag   tag) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1160
  // Accessibility checks are performed in JVMCIEnv::get_method_by_index_impl().
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1161
  assert(check_klass_accessibility(accessor, holder), "holder not accessible");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1162
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1163
  Method* dest_method;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1164
  LinkInfo link_info(holder, name, sig, accessor, LinkInfo::needs_access_check, tag);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1165
  switch (bc) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1166
  case Bytecodes::_invokestatic:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1167
    dest_method =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1168
      LinkResolver::resolve_static_call_or_null(link_info);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1169
    break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1170
  case Bytecodes::_invokespecial:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1171
    dest_method =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1172
      LinkResolver::resolve_special_call_or_null(link_info);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1173
    break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1174
  case Bytecodes::_invokeinterface:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1175
    dest_method =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1176
      LinkResolver::linktime_resolve_interface_method_or_null(link_info);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1177
    break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1178
  case Bytecodes::_invokevirtual:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1179
    dest_method =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1180
      LinkResolver::linktime_resolve_virtual_method_or_null(link_info);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1181
    break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1182
  default: ShouldNotReachHere();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1183
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1184
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1185
  return dest_method;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1186
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1187
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1188
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1189
// ------------------------------------------------------------------
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1190
Method* JVMCIRuntime::get_method_by_index_impl(const constantPoolHandle& cpool,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1191
                                               int index, Bytecodes::Code bc,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1192
                                               InstanceKlass* accessor) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1193
  if (bc == Bytecodes::_invokedynamic) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1194
    ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1195
    bool is_resolved = !cpce->is_f1_null();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1196
    if (is_resolved) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1197
      // Get the invoker Method* from the constant pool.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1198
      // (The appendix argument, if any, will be noted in the method's signature.)
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1199
      Method* adapter = cpce->f1_as_method();
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1200
      return adapter;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1201
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1202
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1203
    return NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1204
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1205
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1206
  int holder_index = cpool->klass_ref_index_at(index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1207
  bool holder_is_accessible;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1208
  Klass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1209
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1210
  // Get the method's name and signature.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1211
  Symbol* name_sym = cpool->name_ref_at(index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1212
  Symbol* sig_sym  = cpool->signature_ref_at(index);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1213
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1214
  if (cpool->has_preresolution()
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1215
      || ((holder == SystemDictionary::MethodHandle_klass() || holder == SystemDictionary::VarHandle_klass()) &&
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1216
          MethodHandles::is_signature_polymorphic_name(holder, name_sym))) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1217
    // Short-circuit lookups for JSR 292-related call sites.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1218
    // That is, do not rely only on name-based lookups, because they may fail
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1219
    // if the names are not resolvable in the boot class loader (7056328).
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1220
    switch (bc) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1221
    case Bytecodes::_invokevirtual:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1222
    case Bytecodes::_invokeinterface:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1223
    case Bytecodes::_invokespecial:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1224
    case Bytecodes::_invokestatic:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1225
      {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1226
        Method* m = ConstantPool::method_at_if_loaded(cpool, index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1227
        if (m != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1228
          return m;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1229
        }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1230
      }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1231
      break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1232
    default:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1233
      break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1234
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1235
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1236
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1237
  if (holder_is_accessible) { // Our declared holder is loaded.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1238
    constantTag tag = cpool->tag_ref_at(index);
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1239
    Method* m = lookup_method(accessor, holder, name_sym, sig_sym, bc, tag);
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1240
    if (m != NULL) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1241
      // We found the method.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1242
      return m;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1243
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1244
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1245
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1246
  // Either the declared holder was not loaded, or the method could
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1247
  // not be found.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1248
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1249
  return NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1250
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1251
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1252
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1253
InstanceKlass* JVMCIRuntime::get_instance_klass_for_declared_method_holder(Klass* method_holder) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1254
  // For the case of <array>.clone(), the method holder can be an ArrayKlass*
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1255
  // instead of an InstanceKlass*.  For that case simply pretend that the
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1256
  // declared holder is Object.clone since that's where the call will bottom out.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1257
  if (method_holder->is_instance_klass()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1258
    return InstanceKlass::cast(method_holder);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1259
  } else if (method_holder->is_array_klass()) {
58760
1f7f707c1aa9 8232881: Remove unnecessary InstanceKlass::casts
redestad
parents: 58722
diff changeset
  1260
    return SystemDictionary::Object_klass();
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1261
  } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1262
    ShouldNotReachHere();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1263
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1264
  return NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1265
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1266
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1267
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1268
// ------------------------------------------------------------------
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58901
diff changeset
  1269
Method* JVMCIRuntime::get_method_by_index(const constantPoolHandle& cpool,
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1270
                                     int index, Bytecodes::Code bc,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1271
                                     InstanceKlass* accessor) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1272
  ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1273
  return get_method_by_index_impl(cpool, index, bc, accessor);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1274
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1275
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1276
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1277
// Check for changes to the system dictionary during compilation
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1278
// class loads, evolution, breakpoints
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1279
JVMCI::CodeInstallResult JVMCIRuntime::validate_compile_task_dependencies(Dependencies* dependencies, JVMCICompileState* compile_state, char** failure_detail) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1280
  // If JVMTI capabilities were enabled during compile, the compilation is invalidated.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1281
  if (compile_state != NULL && compile_state->jvmti_state_changed()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1282
    *failure_detail = (char*) "Jvmti state change during compilation invalidated dependencies";
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1283
    return JVMCI::dependencies_failed;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1284
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1285
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1286
  CompileTask* task = compile_state == NULL ? NULL : compile_state->task();
55635
0fb70c9118ce 8222446: assert(C->env()->system_dictionary_modification_counter_changed()) failed: Must invalidate if TypeFuncs differ
coleenp
parents: 55454
diff changeset
  1287
  Dependencies::DepType result = dependencies->validate_dependencies(task, failure_detail);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1288
  if (result == Dependencies::end_marker) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1289
    return JVMCI::ok;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1290
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1291
57957
4364524f8cac 8229797: [JVMCI] Clean up no longer used JVMCI::dependencies_invalid value
pli
parents: 57893
diff changeset
  1292
  return JVMCI::dependencies_failed;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1293
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1294
55317
b76aee290002 8225492: Update JVMCI
dnsimon
parents: 55293
diff changeset
  1295
// Reports a pending exception and exits the VM.
b76aee290002 8225492: Update JVMCI
dnsimon
parents: 55293
diff changeset
  1296
static void fatal_exception_in_compile(JVMCIEnv* JVMCIENV, JavaThread* thread, const char* msg) {
b76aee290002 8225492: Update JVMCI
dnsimon
parents: 55293
diff changeset
  1297
  // Only report a fatal JVMCI compilation exception once
b76aee290002 8225492: Update JVMCI
dnsimon
parents: 55293
diff changeset
  1298
  static volatile int report_init_failure = 0;
59252
623722a6aeb9 8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents: 59056
diff changeset
  1299
  if (!report_init_failure && Atomic::cmpxchg(&report_init_failure, 0, 1) == 0) {
55317
b76aee290002 8225492: Update JVMCI
dnsimon
parents: 55293
diff changeset
  1300
      tty->print_cr("%s:", msg);
b76aee290002 8225492: Update JVMCI
dnsimon
parents: 55293
diff changeset
  1301
      JVMCIENV->describe_pending_exception(true);
b76aee290002 8225492: Update JVMCI
dnsimon
parents: 55293
diff changeset
  1302
  }
b76aee290002 8225492: Update JVMCI
dnsimon
parents: 55293
diff changeset
  1303
  JVMCIENV->clear_pending_exception();
b76aee290002 8225492: Update JVMCI
dnsimon
parents: 55293
diff changeset
  1304
  before_exit(thread);
b76aee290002 8225492: Update JVMCI
dnsimon
parents: 55293
diff changeset
  1305
  vm_exit(-1);
b76aee290002 8225492: Update JVMCI
dnsimon
parents: 55293
diff changeset
  1306
}
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1307
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1308
void JVMCIRuntime::compile_method(JVMCIEnv* JVMCIENV, JVMCICompiler* compiler, const methodHandle& method, int entry_bci) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1309
  JVMCI_EXCEPTION_CONTEXT
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1310
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1311
  JVMCICompileState* compile_state = JVMCIENV->compile_state();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1312
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1313
  bool is_osr = entry_bci != InvocationEntryBci;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1314
  if (compiler->is_bootstrapping() && is_osr) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1315
    // no OSR compilations during bootstrap - the compiler is just too slow at this point,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1316
    // and we know that there are no endless loops
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1317
    compile_state->set_failure(true, "No OSR during boostrap");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1318
    return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1319
  }
54732
2d012a75d35c 8223332: Update JVMCI
kvn
parents: 54669
diff changeset
  1320
  if (JVMCI::shutdown_called()) {
2d012a75d35c 8223332: Update JVMCI
kvn
parents: 54669
diff changeset
  1321
    compile_state->set_failure(false, "Avoiding compilation during shutdown");
2d012a75d35c 8223332: Update JVMCI
kvn
parents: 54669
diff changeset
  1322
    return;
2d012a75d35c 8223332: Update JVMCI
kvn
parents: 54669
diff changeset
  1323
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1324
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1325
  HandleMark hm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1326
  JVMCIObject receiver = get_HotSpotJVMCIRuntime(JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1327
  if (JVMCIENV->has_pending_exception()) {
55317
b76aee290002 8225492: Update JVMCI
dnsimon
parents: 55293
diff changeset
  1328
    fatal_exception_in_compile(JVMCIENV, thread, "Exception during HotSpotJVMCIRuntime initialization");
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1329
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1330
  JVMCIObject jvmci_method = JVMCIENV->get_jvmci_method(method, JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1331
  if (JVMCIENV->has_pending_exception()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1332
    JVMCIENV->describe_pending_exception(true);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1333
    compile_state->set_failure(false, "exception getting JVMCI wrapper method");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1334
    return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1335
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1336
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1337
  JVMCIObject result_object = JVMCIENV->call_HotSpotJVMCIRuntime_compileMethod(receiver, jvmci_method, entry_bci,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1338
                                                                     (jlong) compile_state, compile_state->task()->compile_id());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1339
  if (!JVMCIENV->has_pending_exception()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1340
    if (result_object.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1341
      JVMCIObject failure_message = JVMCIENV->get_HotSpotCompilationRequestResult_failureMessage(result_object);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1342
      if (failure_message.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1343
        // Copy failure reason into resource memory first ...
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1344
        const char* failure_reason = JVMCIENV->as_utf8_string(failure_message);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1345
        // ... and then into the C heap.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1346
        failure_reason = os::strdup(failure_reason, mtJVMCI);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1347
        bool retryable = JVMCIENV->get_HotSpotCompilationRequestResult_retry(result_object) != 0;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1348
        compile_state->set_failure(retryable, failure_reason, true);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1349
      } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1350
        if (compile_state->task()->code() == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1351
          compile_state->set_failure(true, "no nmethod produced");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1352
        } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1353
          compile_state->task()->set_num_inlined_bytecodes(JVMCIENV->get_HotSpotCompilationRequestResult_inlinedBytecodes(result_object));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1354
          compiler->inc_methods_compiled();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1355
        }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1356
      }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1357
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1358
      assert(false, "JVMCICompiler.compileMethod should always return non-null");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1359
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1360
  } else {
55206
2fe2063fe567 8225019: Update JVMCI
kvn
parents: 54973
diff changeset
  1361
    // An uncaught exception here implies failure during compiler initialization.
2fe2063fe567 8225019: Update JVMCI
kvn
parents: 54973
diff changeset
  1362
    // The only sensible thing to do here is to exit the VM.
55317
b76aee290002 8225492: Update JVMCI
dnsimon
parents: 55293
diff changeset
  1363
    fatal_exception_in_compile(JVMCIENV, thread, "Exception during JVMCI compiler initialization");
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1364
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1365
  if (compiler->is_bootstrapping()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1366
    compiler->set_bootstrap_compilation_request_handled();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1367
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1368
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1369
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1370
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1371
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1372
JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1373
                                const methodHandle& method,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1374
                                nmethod*& nm,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1375
                                int entry_bci,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1376
                                CodeOffsets* offsets,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1377
                                int orig_pc_offset,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1378
                                CodeBuffer* code_buffer,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1379
                                int frame_words,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1380
                                OopMapSet* oop_map_set,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1381
                                ExceptionHandlerTable* handler_table,
55293
d19dc5b10fbb 8209626: [JVMCI] Use implicit exception table for dispatch and printing
never
parents: 55273
diff changeset
  1382
                                ImplicitExceptionTable* implicit_exception_table,
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1383
                                AbstractCompiler* compiler,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1384
                                DebugInformationRecorder* debug_info,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1385
                                Dependencies* dependencies,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1386
                                int compile_id,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1387
                                bool has_unsafe_access,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1388
                                bool has_wide_vector,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1389
                                JVMCIObject compiled_code,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1390
                                JVMCIObject nmethod_mirror,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1391
                                FailedSpeculation** failed_speculations,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1392
                                char* speculations,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1393
                                int speculations_len) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1394
  JVMCI_EXCEPTION_CONTEXT;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1395
  nm = NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1396
  int comp_level = CompLevel_full_optimization;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1397
  char* failure_detail = NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1398
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1399
  bool install_default = JVMCIENV->get_HotSpotNmethod_isDefault(nmethod_mirror) != 0;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1400
  assert(JVMCIENV->isa_HotSpotNmethod(nmethod_mirror), "must be");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1401
  JVMCIObject name = JVMCIENV->get_InstalledCode_name(nmethod_mirror);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1402
  const char* nmethod_mirror_name = name.is_null() ? NULL : JVMCIENV->as_utf8_string(name);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1403
  int nmethod_mirror_index;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1404
  if (!install_default) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1405
    // Reserve or initialize mirror slot in the oops table.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1406
    OopRecorder* oop_recorder = debug_info->oop_recorder();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1407
    nmethod_mirror_index = oop_recorder->allocate_oop_index(nmethod_mirror.is_hotspot() ? nmethod_mirror.as_jobject() : NULL);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1408
  } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1409
    // A default HotSpotNmethod mirror is never tracked by the nmethod
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1410
    nmethod_mirror_index = -1;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1411
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1412
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1413
  JVMCI::CodeInstallResult result;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1414
  {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1415
    // To prevent compile queue updates.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1416
    MutexLocker locker(MethodCompileQueue_lock, THREAD);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1417
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1418
    // Prevent SystemDictionary::add_to_hierarchy from running
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1419
    // and invalidating our dependencies until we install this method.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1420
    MutexLocker ml(Compile_lock);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1421
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1422
    // Encode the dependencies now, so we can check them right away.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1423
    dependencies->encode_content_bytes();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1424
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1425
    // Record the dependencies for the current compile in the log
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1426
    if (LogCompilation) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1427
      for (Dependencies::DepStream deps(dependencies); deps.next(); ) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1428
        deps.log_dependency();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1429
      }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1430
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1431
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1432
    // Check for {class loads, evolution, breakpoints} during compilation
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1433
    result = validate_compile_task_dependencies(dependencies, JVMCIENV->compile_state(), &failure_detail);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1434
    if (result != JVMCI::ok) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1435
      // While not a true deoptimization, it is a preemptive decompile.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1436
      MethodData* mdp = method()->method_data();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1437
      if (mdp != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1438
        mdp->inc_decompile_count();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1439
#ifdef ASSERT
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1440
        if (mdp->decompile_count() > (uint)PerMethodRecompilationCutoff) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1441
          ResourceMark m;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1442
          tty->print_cr("WARN: endless recompilation of %s. Method was set to not compilable.", method()->name_and_sig_as_C_string());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1443
        }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1444
#endif
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1445
      }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1446
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1447
      // All buffers in the CodeBuffer are allocated in the CodeCache.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1448
      // If the code buffer is created on each compile attempt
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1449
      // as in C2, then it must be freed.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1450
      //code_buffer->free_blob();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1451
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1452
      nm =  nmethod::new_nmethod(method,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1453
                                 compile_id,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1454
                                 entry_bci,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1455
                                 offsets,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1456
                                 orig_pc_offset,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1457
                                 debug_info, dependencies, code_buffer,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1458
                                 frame_words, oop_map_set,
55293
d19dc5b10fbb 8209626: [JVMCI] Use implicit exception table for dispatch and printing
never
parents: 55273
diff changeset
  1459
                                 handler_table, implicit_exception_table,
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1460
                                 compiler, comp_level,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1461
                                 speculations, speculations_len,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1462
                                 nmethod_mirror_index, nmethod_mirror_name, failed_speculations);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1463
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1464
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1465
      // Free codeBlobs
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1466
      if (nm == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1467
        // The CodeCache is full.  Print out warning and disable compilation.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1468
        {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1469
          MutexUnlocker ml(Compile_lock);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1470
          MutexUnlocker locker(MethodCompileQueue_lock);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1471
          CompileBroker::handle_full_code_cache(CodeCache::get_code_blob_type(comp_level));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1472
        }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1473
      } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1474
        nm->set_has_unsafe_access(has_unsafe_access);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1475
        nm->set_has_wide_vectors(has_wide_vector);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1476
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1477
        // Record successful registration.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1478
        // (Put nm into the task handle *before* publishing to the Java heap.)
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1479
        if (JVMCIENV->compile_state() != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1480
          JVMCIENV->compile_state()->task()->set_code(nm);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1481
        }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1482
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1483
        JVMCINMethodData* data = nm->jvmci_nmethod_data();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1484
        assert(data != NULL, "must be");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1485
        if (install_default) {
55454
8892555795cd 8223794: applications/kitchensink/Kitchensink.java crash bad oop with Graal
kvn
parents: 55317
diff changeset
  1486
          assert(!nmethod_mirror.is_hotspot() || data->get_nmethod_mirror(nm, /* phantom_ref */ false) == NULL, "must be");
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1487
          if (entry_bci == InvocationEntryBci) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1488
            if (TieredCompilation) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1489
              // If there is an old version we're done with it
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1490
              CompiledMethod* old = method->code();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1491
              if (TraceMethodReplacement && old != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1492
                ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1493
                char *method_name = method->name_and_sig_as_C_string();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1494
                tty->print_cr("Replacing method %s", method_name);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1495
              }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1496
              if (old != NULL ) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1497
                old->make_not_entrant();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1498
              }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1499
            }
55273
64b76867851b 8222371: Use UL for TraceNMethodInstalls code
kvn
parents: 55206
diff changeset
  1500
64b76867851b 8222371: Use UL for TraceNMethodInstalls code
kvn
parents: 55206
diff changeset
  1501
            LogTarget(Info, nmethod, install) lt;
64b76867851b 8222371: Use UL for TraceNMethodInstalls code
kvn
parents: 55206
diff changeset
  1502
            if (lt.is_enabled()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1503
              ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1504
              char *method_name = method->name_and_sig_as_C_string();
55273
64b76867851b 8222371: Use UL for TraceNMethodInstalls code
kvn
parents: 55206
diff changeset
  1505
              lt.print("Installing method (%d) %s [entry point: %p]",
64b76867851b 8222371: Use UL for TraceNMethodInstalls code
kvn
parents: 55206
diff changeset
  1506
                        comp_level, method_name, nm->entry_point());
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1507
            }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1508
            // Allow the code to be executed
58226
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 58196
diff changeset
  1509
            MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 58196
diff changeset
  1510
            if (nm->make_in_use()) {
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 58196
diff changeset
  1511
              method->set_code(method, nm);
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 58196
diff changeset
  1512
            }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1513
          } else {
55273
64b76867851b 8222371: Use UL for TraceNMethodInstalls code
kvn
parents: 55206
diff changeset
  1514
            LogTarget(Info, nmethod, install) lt;
64b76867851b 8222371: Use UL for TraceNMethodInstalls code
kvn
parents: 55206
diff changeset
  1515
            if (lt.is_enabled()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1516
              ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1517
              char *method_name = method->name_and_sig_as_C_string();
55273
64b76867851b 8222371: Use UL for TraceNMethodInstalls code
kvn
parents: 55206
diff changeset
  1518
              lt.print("Installing osr method (%d) %s @ %d",
64b76867851b 8222371: Use UL for TraceNMethodInstalls code
kvn
parents: 55206
diff changeset
  1519
                        comp_level, method_name, entry_bci);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1520
            }
58226
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 58196
diff changeset
  1521
            MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 58196
diff changeset
  1522
            if (nm->make_in_use()) {
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 58196
diff changeset
  1523
              InstanceKlass::cast(method->method_holder())->add_osr_nmethod(nm);
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 58196
diff changeset
  1524
            }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1525
          }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1526
        } else {
55454
8892555795cd 8223794: applications/kitchensink/Kitchensink.java crash bad oop with Graal
kvn
parents: 55317
diff changeset
  1527
          assert(!nmethod_mirror.is_hotspot() || data->get_nmethod_mirror(nm, /* phantom_ref */ false) == HotSpotJVMCI::resolve(nmethod_mirror), "must be");
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1528
        }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1529
      }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1530
      result = nm != NULL ? JVMCI::ok :JVMCI::cache_full;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1531
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1532
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1533
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1534
  // String creation must be done outside lock
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1535
  if (failure_detail != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1536
    // A failure to allocate the string is silently ignored.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1537
    JVMCIObject message = JVMCIENV->create_string(failure_detail, JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1538
    JVMCIENV->set_HotSpotCompiledNmethod_installationFailureMessage(compiled_code, message);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1539
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1540
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1541
  // JVMTI -- compiled method notification (must be done outside lock)
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1542
  if (nm != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1543
    nm->post_compiled_method_load_event();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1544
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1545
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1546
  return result;
38674
eacc567feae8 8156034: [JVMCI] Notify the jvmci compiler on completion of a bootstrap
never
parents: 38666
diff changeset
  1547
}