src/hotspot/share/jvmci/jvmciRuntime.cpp
author kvn
Wed, 01 May 2019 12:31:29 -0700
changeset 54669 ad45b3802d4e
parent 54647 c0d9bc9b4e1f
child 54732 2d012a75d35c
permissions -rw-r--r--
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library Reviewed-by: dnsimon, never, stefank, rehn, neliasso, dholmes, kbarrett, coleenp
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"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    25
#include "compiler/compileBroker.hpp"
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
    26
#include "jvmci/jniAccessMark.inline.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    27
#include "jvmci/jvmciCompilerToVM.hpp"
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
    28
#include "jvmci/jvmciRuntime.hpp"
35216
71c463a17b3b 8141211: Convert TraceExceptions to Unified Logging
rprotacio
parents: 35071
diff changeset
    29
#include "logging/log.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    30
#include "memory/oopFactory.hpp"
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
    31
#include "oops/constantPool.inline.hpp"
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
    32
#include "oops/method.inline.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    33
#include "oops/oop.inline.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    34
#include "runtime/biasedLocking.hpp"
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
    35
#include "runtime/deoptimization.hpp"
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
    36
#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
    37
#include "runtime/frame.inline.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    38
#include "runtime/sharedRuntime.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49837
diff changeset
    39
#if INCLUDE_G1GC
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49480
diff changeset
    40
#include "gc/g1/g1ThreadLocalData.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49837
diff changeset
    41
#endif // INCLUDE_G1GC
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    42
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    43
// 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
    44
// entered the VM has been deoptimized
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    45
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    46
static bool caller_is_deopted() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    47
  JavaThread* thread = JavaThread::current();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    48
  RegisterMap reg_map(thread, false);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    49
  frame runtime_frame = thread->last_frame();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    50
  frame caller_frame = runtime_frame.sender(&reg_map);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    51
  assert(caller_frame.is_compiled_frame(), "must be compiled");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    52
  return caller_frame.is_deoptimized_frame();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    53
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    54
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    55
// Stress deoptimization
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    56
static void deopt_caller() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    57
  if ( !caller_is_deopted()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    58
    JavaThread* thread = JavaThread::current();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    59
    RegisterMap reg_map(thread, false);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    60
    frame runtime_frame = thread->last_frame();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    61
    frame caller_frame = runtime_frame.sender(&reg_map);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    62
    Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    63
    assert(caller_is_deopted(), "Must be deoptimized");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    64
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    65
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    66
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    67
// 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
    68
// 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
    69
// 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
    70
// exception, the following action is taken:
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    71
//   1. The pending exception is cleared
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    72
//   2. NULL is written to JavaThread::_vm_result
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    73
//   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
    74
class RetryableAllocationMark: public StackObj {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    75
 private:
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    76
  JavaThread* _thread;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    77
 public:
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    78
  RetryableAllocationMark(JavaThread* thread, bool activate) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    79
    if (activate) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    80
      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
    81
      _thread = thread;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    82
      _thread->set_in_retryable_allocation(true);
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    83
    } else {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    84
      _thread = NULL;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    85
    }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    86
  }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    87
  ~RetryableAllocationMark() {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    88
    if (_thread != NULL) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    89
      _thread->set_in_retryable_allocation(false);
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    90
      JavaThread* THREAD = _thread;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    91
      if (HAS_PENDING_EXCEPTION) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    92
        oop ex = PENDING_EXCEPTION;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    93
        CLEAR_PENDING_EXCEPTION;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    94
        oop retry_oome = Universe::out_of_memory_error_retry();
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    95
        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
    96
          ResourceMark rm;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    97
          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
    98
        }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
    99
        _thread->set_vm_result(NULL);
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   100
      }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   101
    }
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
};
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
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
   106
  JRT_BLOCK;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   107
  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
   108
  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
   109
  InstanceKlass* h = InstanceKlass::cast(klass);
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   110
  {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   111
    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
   112
    h->check_valid_for_instantiation(true, CHECK);
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   113
    oop obj;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   114
    if (null_on_fail) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   115
      if (!h->is_initialized()) {
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   116
        // Cannot re-execute class initialization without side effects
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   117
        // so return without attempting the initialization
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   118
        return;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   119
      }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   120
    } else {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   121
      // 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
   122
      h->initialize(CHECK);
52033
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
    // 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
   125
    obj = h->allocate_instance(CHECK);
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   126
    thread->set_vm_result(obj);
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   127
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   128
  JRT_BLOCK_END;
48961
120b61d50f85 8195103: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48105
diff changeset
   129
  SharedRuntime::on_slowpath_allocation_exit(thread);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   130
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   131
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   132
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
   133
  JRT_BLOCK;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   134
  // Note: no handle for klass needed since they are not used
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   135
  //       anymore after new_objArray() and no GC can happen before.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   136
  //       (This may have to change if this code changes!)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   137
  assert(array_klass->is_klass(), "not a class");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   138
  oop obj;
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33198
diff changeset
   139
  if (array_klass->is_typeArray_klass()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   140
    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
   141
    RetryableAllocationMark ram(thread, null_on_fail);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   142
    obj = oopFactory::new_typeArray(elt_type, length, CHECK);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   143
  } else {
36603
0bc3ad031d60 8141420: Compiler runtime entries don't hold Klass* from being GCed
vlivanov
parents: 36594
diff changeset
   144
    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
   145
    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
   146
    RetryableAllocationMark ram(thread, null_on_fail);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   147
    obj = oopFactory::new_objArray(elem_klass, length, CHECK);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   148
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   149
  thread->set_vm_result(obj);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   150
  // 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
   151
  // 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
   152
  if (DeoptimizeALot) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   153
    static int deopts = 0;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   154
    // 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
   155
    if (deopts++ % 2 == 0) {
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   156
      if (null_on_fail) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   157
        return;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   158
      } else {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   159
        ResourceMark rm(THREAD);
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   160
        THROW(vmSymbols::java_lang_OutOfMemoryError());
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   161
      }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   162
    } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   163
      deopt_caller();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   164
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   165
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   166
  JRT_BLOCK_END;
48961
120b61d50f85 8195103: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48105
diff changeset
   167
  SharedRuntime::on_slowpath_allocation_exit(thread);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   168
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   169
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   170
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
   171
  assert(klass->is_klass(), "not a class");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   172
  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
   173
  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
   174
  RetryableAllocationMark ram(thread, null_on_fail);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   175
  oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   176
  thread->set_vm_result(obj);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   177
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   178
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   179
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
   180
  RetryableAllocationMark ram(thread, null_on_fail);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   181
  oop obj = Reflection::reflect_new_array(element_mirror, length, CHECK);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   182
  thread->set_vm_result(obj);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   183
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   184
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   185
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
   186
  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
   187
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   188
  if (klass == NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   189
    ResourceMark rm(THREAD);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   190
    THROW(vmSymbols::java_lang_InstantiationException());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   191
  }
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   192
  RetryableAllocationMark ram(thread, null_on_fail);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   193
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   194
  // Create new instance (the receiver)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   195
  klass->check_valid_for_instantiation(false, CHECK);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   196
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   197
  if (null_on_fail) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   198
    if (!klass->is_initialized()) {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   199
      // Cannot re-execute class initialization without side effects
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   200
      // so return without attempting the initialization
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   201
      return;
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   202
    }
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   203
  } else {
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   204
    // Make sure klass gets initialized
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   205
    klass->initialize(CHECK);
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51314
diff changeset
   206
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   207
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   208
  oop obj = klass->allocate_instance(CHECK);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   209
  thread->set_vm_result(obj);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   210
JRT_END
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
extern void vm_exit(int code);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   213
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   214
// 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
   215
// 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
   216
// 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
   217
// 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
   218
// 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
   219
// cpu directories.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   220
//
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   221
// 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
   222
// 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
   223
// 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
   224
// 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
   225
// 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
   226
// 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
   227
// 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
   228
// 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
   229
// 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
   230
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
   231
  // Reset method handle flag.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   232
  thread->set_is_method_handle_return(false);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   233
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   234
  Handle exception(thread, ex);
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   235
  cm = CodeCache::find_compiled(pc);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   236
  assert(cm != NULL, "this is not a compiled method");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   237
  // Adjust the pc as needed/
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   238
  if (cm->is_deopt_pc(pc)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   239
    RegisterMap map(thread, false);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   240
    frame exception_frame = thread->last_frame().sender(&map);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   241
    // 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
   242
    assert(exception_frame.is_deoptimized_frame(), "must be deopted");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   243
    pc = exception_frame.pc();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   244
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   245
#ifdef ASSERT
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   246
  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
   247
  assert(oopDesc::is_oop(exception()), "just checking");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   248
  // 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
   249
  if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   250
    if (ExitVMOnVerifyError) vm_exit(-1);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   251
    ShouldNotReachHere();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   252
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   253
#endif
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   254
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   255
  // 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
   256
  // 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
   257
  // pages are enabled.
35071
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34192
diff changeset
   258
  bool guard_pages_enabled = thread->stack_guards_enabled();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   259
  if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   260
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   261
  if (JvmtiExport::can_post_on_exceptions()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   262
    // To ensure correct notification of exception catches and throws
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   263
    // we have to deoptimize here.  If we attempted to notify the
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   264
    // catches and throws during this exception lookup it's possible
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   265
    // 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
   266
    // the interpreter at the throw site.  This would result in double
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   267
    // notifications since the interpreter would also notify about
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   268
    // these same catches and throws as it unwound the frame.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   269
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   270
    RegisterMap reg_map(thread);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   271
    frame stub_frame = thread->last_frame();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   272
    frame caller_frame = stub_frame.sender(&reg_map);
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
    // 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
   275
    // can actually continue in the exception handler ourselves but I
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   276
    // don't see an easy way to have the desired effect.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   277
    Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   278
    assert(caller_is_deopted(), "Must be deoptimized");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   279
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   280
    return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   281
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   282
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   283
  // 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
   284
  if (guard_pages_enabled) {
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   285
    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
   286
    if (fast_continuation != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   287
      // 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
   288
      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
   289
      return fast_continuation;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   290
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   291
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   292
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   293
  // 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
   294
  // the current method.  Otherwise (guard pages disabled), force an unwind and
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   295
  // skip the exception cache update (i.e., just leave continuation==NULL).
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   296
  address continuation = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   297
  if (guard_pages_enabled) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   298
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   299
    // New exception handling mechanism can support inlined methods
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   300
    // with exception handlers since the mappings are from PC to PC
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   301
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   302
    // debugging support
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   303
    // tracing
35216
71c463a17b3b 8141211: Convert TraceExceptions to Unified Logging
rprotacio
parents: 35071
diff changeset
   304
    if (log_is_enabled(Info, exceptions)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   305
      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
   306
      stringStream tempst;
51314
82adcc8ad853 8208604: Metadata::print_value_string() compares 'this' to NULL
hseigel
parents: 51180
diff changeset
   307
      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
   308
      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
   309
                   " at PC" INTPTR_FORMAT " for thread " INTPTR_FORMAT,
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   310
                   cm->method()->print_value_string(), p2i(pc), p2i(thread));
36333
dcca1e98a2ab 8150738: [JVMCI] runtime/CommandLine/TraceExceptionsTest.java fails with: java.lang.RuntimeException: '<a 'java/lang/ClassNotFoundException': NoClassFound>' missing
twisti
parents: 35835
diff changeset
   311
      Exceptions::log_exception(exception, tempst);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   312
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   313
    // for AbortVMOnException flag
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   314
    NOT_PRODUCT(Exceptions::debug_check_abort(exception));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   315
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   316
    // Clear out the exception oop and pc since looking up an
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   317
    // exception handler can cause class loading, which might throw an
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   318
    // exception and those fields are expected to be clear during
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   319
    // normal bytecode execution.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   320
    thread->clear_exception_oop_and_pc();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   321
41057
f77b9d9e0e4c 8164480: Crash with assert(handler_address == SharedRuntime::compute_compiled_exc_handler(..) failed: Must be the same
thartmann
parents: 40093
diff changeset
   322
    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
   323
    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
   324
    // 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
   325
    thread->set_exception_oop(exception());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   326
    thread->set_exception_pc(pc);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   327
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   328
    // 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
   329
    // 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
   330
    // 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
   331
    // (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
   332
    // 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
   333
    // 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
   334
    if (continuation != NULL && !recursive_exception && !SharedRuntime::deopt_blob()->contains(continuation)) {
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   335
      cm->add_handler_for_exception_and_pc(exception, pc, continuation);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   336
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   337
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   338
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   339
  // 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
   340
  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
   341
35216
71c463a17b3b 8141211: Convert TraceExceptions to Unified Logging
rprotacio
parents: 35071
diff changeset
   342
  if (log_is_enabled(Info, exceptions)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   343
    ResourceMark rm;
35216
71c463a17b3b 8141211: Convert TraceExceptions to Unified Logging
rprotacio
parents: 35071
diff changeset
   344
    log_info(exceptions)("Thread " PTR_FORMAT " continuing at PC " PTR_FORMAT
71c463a17b3b 8141211: Convert TraceExceptions to Unified Logging
rprotacio
parents: 35071
diff changeset
   345
                         " for exception thrown at PC " PTR_FORMAT,
71c463a17b3b 8141211: Convert TraceExceptions to Unified Logging
rprotacio
parents: 35071
diff changeset
   346
                         p2i(thread), p2i(continuation), p2i(pc));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   347
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   348
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   349
  return continuation;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   350
JRT_END
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
// 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
   353
// in the method handling the exception.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   354
// 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
   355
// 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
   356
// searched for an exception handler has been deoptimized in the meantime.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   357
address JVMCIRuntime::exception_handler_for_pc(JavaThread* thread) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   358
  oop exception = thread->exception_oop();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   359
  address pc = thread->exception_pc();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   360
  // Still in Java mode
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   361
  DEBUG_ONLY(ResetNoHandleMark rnhm);
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   362
  CompiledMethod* cm = NULL;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   363
  address continuation = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   364
  {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   365
    // Enter VM mode by calling the helper
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   366
    ResetNoHandleMark rnhm;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37267
diff changeset
   367
    continuation = exception_handler_for_pc_helper(thread, exception, pc, cm);
33160
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
  // Back in JAVA, use no oops DON'T safepoint
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   370
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   371
  // 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
   372
  // 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
   373
  if (cm != NULL && caller_is_deopted()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   374
    continuation = SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   375
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   376
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   377
  assert(continuation != NULL, "no handler found");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   378
  return continuation;
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
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
   382
  IF_TRACE_jvmci_3 {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   383
    char type[O_BUFLEN];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   384
    obj->klass()->name()->as_C_string(type, O_BUFLEN);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   385
    markOop mark = obj->mark();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   386
    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, p2i(mark), p2i(lock));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   387
    tty->flush();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   388
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   389
  if (PrintBiasedLockingStatistics) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   390
    Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   391
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   392
  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
   393
  assert(oopDesc::is_oop(h_obj()), "must be NULL or an object");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   394
  if (UseBiasedLocking) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   395
    // Retry fast entry if bias is revoked to avoid unnecessary inflation
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   396
    ObjectSynchronizer::fast_enter(h_obj, lock, true, CHECK);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   397
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   398
    if (JVMCIUseFastLocking) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   399
      // When using fast locking, the compiled code has already tried the fast case
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   400
      ObjectSynchronizer::slow_enter(h_obj, lock, THREAD);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   401
    } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   402
      ObjectSynchronizer::fast_enter(h_obj, lock, false, THREAD);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   403
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   404
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   405
  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
   406
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   407
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   408
JRT_LEAF(void, JVMCIRuntime::monitorexit(JavaThread* thread, oopDesc* obj, BasicLock* lock))
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   409
  assert(thread == JavaThread::current(), "threads must correspond");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   410
  assert(thread->last_Java_sp(), "last_Java_sp must be set");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   411
  // monitorexit is non-blocking (leaf routine) => no exceptions can be thrown
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   412
  EXCEPTION_MARK;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   413
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   414
#ifdef ASSERT
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 46727
diff changeset
   415
  if (!oopDesc::is_oop(obj)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   416
    ResetNoHandleMark rhm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   417
    nmethod* method = thread->last_frame().cb()->as_nmethod_or_null();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   418
    if (method != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   419
      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
   420
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   421
    thread->print_stack_on(tty);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   422
    assert(false, "invalid lock object pointer dected");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   423
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   424
#endif
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   425
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   426
  if (JVMCIUseFastLocking) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   427
    // When using fast locking, the compiled code has already tried the fast case
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   428
    ObjectSynchronizer::slow_exit(obj, lock, THREAD);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   429
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   430
    ObjectSynchronizer::fast_exit(obj, lock, THREAD);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   431
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   432
  IF_TRACE_jvmci_3 {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   433
    char type[O_BUFLEN];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   434
    obj->klass()->name()->as_C_string(type, O_BUFLEN);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   435
    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, p2i(obj->mark()), p2i(lock));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   436
    tty->flush();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   437
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   438
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   439
49837
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   440
// Object.notify() fast path, caller does slow path
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   441
JRT_LEAF(jboolean, JVMCIRuntime::object_notify(JavaThread *thread, oopDesc* obj))
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
  // 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
   444
  // the dominant fast-path is to simply return.
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   445
  // 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
   446
  // reduce lock hold times.
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   447
  if (!SafepointSynchronize::is_synchronizing()) {
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   448
    if (ObjectSynchronizer::quick_notify(obj, thread, false)) {
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   449
      return true;
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   450
    }
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
  return false; // caller must perform slow path
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   453
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   454
JRT_END
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   455
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   456
// Object.notifyAll() fast path, caller does slow path
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   457
JRT_LEAF(jboolean, JVMCIRuntime::object_notifyAll(JavaThread *thread, oopDesc* obj))
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   458
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   459
  if (!SafepointSynchronize::is_synchronizing() ) {
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   460
    if (ObjectSynchronizer::quick_notify(obj, thread, true)) {
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   461
      return true;
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   462
    }
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   463
  }
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   464
  return false; // caller must perform slow path
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   465
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
diff changeset
   466
JRT_END
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 49752
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_and_post_jvmti_exception(JavaThread* thread, const char* exception, const char* message))
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   469
  TempNewSymbol symbol = SymbolTable::new_symbol(exception, CHECK);
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   470
  SharedRuntime::throw_and_post_jvmti_exception(thread, symbol, message);
36842
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   471
JRT_END
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   472
38229
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   473
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
   474
  ResourceMark rm(thread);
38229
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   475
  TempNewSymbol symbol = SymbolTable::new_symbol(exception, CHECK);
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   476
  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
   477
JRT_END
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   478
38229
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   479
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
   480
  ResourceMark rm(thread);
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   481
  const char* message = SharedRuntime::generate_class_cast_message(caster_klass, target_klass);
38229
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   482
  TempNewSymbol symbol = SymbolTable::new_symbol(exception, CHECK);
7d3bad8f8ec8 8155735: use strings instead of Symbol* in JVMCI exception stubs
rschatz
parents: 38133
diff changeset
   483
  SharedRuntime::throw_and_post_jvmti_exception(thread, symbol, message);
36842
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   484
JRT_END
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36805
diff changeset
   485
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   486
JRT_LEAF(void, JVMCIRuntime::log_object(JavaThread* thread, oopDesc* obj, bool as_string, bool newline))
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   487
  ttyLocker ttyl;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   488
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   489
  if (obj == NULL) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   490
    tty->print("NULL");
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 46727
diff changeset
   491
  } 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
   492
    if (oopDesc::is_oop_or_null(obj, true)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   493
      char buf[O_BUFLEN];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   494
      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
   495
    } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   496
      tty->print(INTPTR_FORMAT, p2i(obj));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   497
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   498
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   499
    ResourceMark rm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   500
    assert(obj != NULL && java_lang_String::is_instance(obj), "must be");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   501
    char *buf = java_lang_String::as_utf8_string(obj);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   502
    tty->print_raw(buf);
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
  if (newline) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   505
    tty->cr();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   506
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   507
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   508
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49837
diff changeset
   509
#if INCLUDE_G1GC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49837
diff changeset
   510
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   511
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
   512
  G1ThreadLocalData::satb_mark_queue(thread).enqueue(obj);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   513
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   514
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   515
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
   516
  G1ThreadLocalData::dirty_card_queue(thread).enqueue(card_addr);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   517
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   518
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49837
diff changeset
   519
#endif // INCLUDE_G1GC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49837
diff changeset
   520
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   521
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
   522
  bool ret = true;
54375
a5ce9300462f 8221648: Remove CollectedHeap::is_in_closed_subset()
pliden
parents: 53582
diff changeset
   523
  if(!Universe::heap()->is_in(parent)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   524
    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
   525
    parent->print();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   526
    ret=false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   527
  }
54375
a5ce9300462f 8221648: Remove CollectedHeap::is_in_closed_subset()
pliden
parents: 53582
diff changeset
   528
  if(!Universe::heap()->is_in(child)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   529
    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
   530
    child->print();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   531
    ret=false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   532
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   533
  return (jint)ret;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   534
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   535
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   536
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
   537
  ResourceMark rm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   538
  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
   539
  char *detail_msg = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   540
  if (format != 0L) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   541
    const char* buf = (char*) (address) format;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   542
    size_t detail_msg_length = strlen(buf) * 2;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   543
    detail_msg = (char *) NEW_RESOURCE_ARRAY(u_char, detail_msg_length);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   544
    jio_snprintf(detail_msg, detail_msg_length, buf, value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   545
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   546
  report_vm_error(__FILE__, __LINE__, error_msg, "%s", detail_msg);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   547
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   548
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   549
JRT_LEAF(oopDesc*, JVMCIRuntime::load_and_clear_exception(JavaThread* thread))
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   550
  oop exception = thread->exception_oop();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   551
  assert(exception != NULL, "npe");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   552
  thread->set_exception_oop(NULL);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   553
  thread->set_exception_pc(0);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   554
  return exception;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   555
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   556
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   557
PRAGMA_DIAG_PUSH
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   558
PRAGMA_FORMAT_NONLITERAL_IGNORED
50858
2d3e99a72541 8205824: Update Graal
never
parents: 49982
diff changeset
   559
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
   560
  ResourceMark rm;
50858
2d3e99a72541 8205824: Update Graal
never
parents: 49982
diff changeset
   561
  tty->print(format, v1, v2, v3);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   562
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   563
PRAGMA_DIAG_POP
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   564
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   565
static void decipher(jlong v, bool ignoreZero) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   566
  if (v != 0 || !ignoreZero) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   567
    void* p = (void *)(address) v;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   568
    CodeBlob* cb = CodeCache::find_blob(p);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   569
    if (cb) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   570
      if (cb->is_nmethod()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   571
        char buf[O_BUFLEN];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   572
        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
   573
        return;
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
      cb->print_value_on(tty);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   576
      return;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   577
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   578
    if (Universe::heap()->is_in(p)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   579
      oop obj = oop(p);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   580
      obj->print_value_on(tty);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   581
      return;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   582
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   583
    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
   584
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   585
}
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
PRAGMA_DIAG_PUSH
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   588
PRAGMA_FORMAT_NONLITERAL_IGNORED
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   589
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
   590
  ResourceMark rm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   591
  const char *buf = (const char*) (address) format;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   592
  if (vmError) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   593
    if (buf != NULL) {
33198
dlong
parents: 33178
diff changeset
   594
      fatal(buf, v1, v2, v3);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   595
    } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   596
      fatal("<anonymous error>");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   597
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   598
  } else if (buf != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   599
    tty->print(buf, v1, v2, v3);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   600
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   601
    assert(v2 == 0, "v2 != 0");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   602
    assert(v3 == 0, "v3 != 0");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   603
    decipher(v1, false);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   604
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   605
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   606
PRAGMA_DIAG_POP
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   607
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   608
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
   609
  union {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   610
      jlong l;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   611
      jdouble d;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   612
      jfloat f;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   613
  } uu;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   614
  uu.l = value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   615
  switch (typeChar) {
38695
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   616
    case 'Z': tty->print(value == 0 ? "false" : "true"); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   617
    case 'B': tty->print("%d", (jbyte) value); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   618
    case 'C': tty->print("%c", (jchar) value); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   619
    case 'S': tty->print("%d", (jshort) value); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   620
    case 'I': tty->print("%d", (jint) value); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   621
    case 'F': tty->print("%f", uu.f); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   622
    case 'J': tty->print(JLONG_FORMAT, value); break;
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38674
diff changeset
   623
    case 'D': tty->print("%lf", uu.d); break;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   624
    default: assert(false, "unknown typeChar"); break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   625
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   626
  if (newline) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   627
    tty->cr();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   628
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   629
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   630
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   631
JRT_ENTRY(jint, JVMCIRuntime::identity_hash_code(JavaThread* thread, oopDesc* obj))
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   632
  return (jint) obj->identity_hash();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   633
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   634
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   635
JRT_ENTRY(jboolean, JVMCIRuntime::thread_is_interrupted(JavaThread* thread, oopDesc* receiver, jboolean clear_interrupted))
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   636
  Handle receiverHandle(thread, receiver);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47796
diff changeset
   637
  // A nested ThreadsListHandle may require the Threads_lock which
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47796
diff changeset
   638
  // requires thread_in_vm which is why this method cannot be JRT_LEAF.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47796
diff changeset
   639
  ThreadsListHandle tlh;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47796
diff changeset
   640
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   641
  JavaThread* receiverThread = java_lang_Thread::thread(receiverHandle());
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47796
diff changeset
   642
  if (receiverThread == NULL || (EnableThreadSMRExtraValidityChecks && !tlh.includes(receiverThread))) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   643
    // The other thread may exit during this process, which is ok so return false.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   644
    return JNI_FALSE;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   645
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   646
    return (jint) Thread::is_interrupted(receiverThread, clear_interrupted != 0);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   647
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   648
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   649
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   650
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
   651
  deopt_caller();
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   652
  return (jint) value;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   653
JRT_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   654
40034
4a288aaf8511 8160121: [JVMCI] JvmciNotifyBootstrapFinishedEventTest.java failed NoClassDefFoundError: jdk/vm/ci/runtime/JVMCI
never
parents: 38695
diff changeset
   655
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   656
// 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
   657
JVM_ENTRY_NO_ENV(jobject, JVM_GetJVMCIRuntime(JNIEnv *env, jclass c))
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   658
  JNI_JVMCIENV(env);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   659
  if (!EnableJVMCI) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   660
    JVMCI_THROW_MSG_NULL(InternalError, "JVMCI is not enabled");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   661
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   662
  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
   663
  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
   664
  return JVMCIENV->get_jobject(runtime);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   665
JVM_END
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   666
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   667
void JVMCIRuntime::call_getCompiler(TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   668
  THREAD_JVMCIENV(JavaThread::current());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   669
  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
   670
  initialize(JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   671
  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
   672
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   673
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   674
void JVMCINMethodData::initialize(
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   675
  int nmethod_mirror_index,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   676
  const char* name,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   677
  FailedSpeculation** failed_speculations)
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   678
{
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   679
  _failed_speculations = failed_speculations;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   680
  _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
   681
  if (name != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   682
    _has_name = true;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   683
    char* dest = (char*) this->name();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   684
    strcpy(dest, name);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   685
  } else {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   686
    _has_name = false;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   687
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   688
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   689
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   690
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
   691
  uint index = (speculation >> 32) & 0xFFFFFFFF;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   692
  int length = (int) speculation;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   693
  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
   694
    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
   695
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   696
  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
   697
  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
   698
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   699
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   700
oop JVMCINMethodData::get_nmethod_mirror(nmethod* nm) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   701
  if (_nmethod_mirror_index == -1) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   702
    return NULL;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   703
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   704
  return nm->oop_at(_nmethod_mirror_index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   705
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   706
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   707
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
   708
  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
   709
  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
   710
  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
   711
  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
   712
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   713
  *addr = new_mirror;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   714
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   715
  // 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
   716
  // (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
   717
  Universe::heap()->register_nmethod(nm);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   718
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   719
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   720
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
   721
  if (_nmethod_mirror_index != -1) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   722
    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
   723
    *addr = NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   724
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   725
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   726
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   727
void JVMCINMethodData::invalidate_nmethod_mirror(nmethod* nm) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   728
  oop nmethod_mirror = get_nmethod_mirror(nm);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   729
  if (nmethod_mirror == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   730
    return;
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
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   733
  // 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
   734
  // 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
   735
  // 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
   736
  JVMCIEnv* jvmciEnv = NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   737
  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
   738
  if (nm == current) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   739
    if (!nm->is_alive()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   740
      // 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
   741
      // 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
   742
      // an InvalidInstalledCodeException.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   743
      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
   744
      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
   745
    } 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
   746
      // 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
   747
      // 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
   748
      // 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
   749
      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
   750
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   751
  }
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
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
   755
  if (is_HotSpotJVMCIRuntime_initialized()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   756
    if (JVMCIENV->is_hotspot() && UseJVMCINativeLibrary) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   757
      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
   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
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   761
  initialize(JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   762
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   763
  // 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
   764
  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
   765
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   766
  _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
   767
}
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
void JVMCIRuntime::initialize(JVMCIEnv* JVMCIENV) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   770
  assert(this != NULL, "sanity");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   771
  // Check first without JVMCI_lock
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   772
  if (_initialized) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   773
    return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   774
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   775
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   776
  MutexLocker locker(JVMCI_lock);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   777
  // Check again under JVMCI_lock
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   778
  if (_initialized) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   779
    return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   780
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   781
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   782
  while (_being_initialized) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   783
    JVMCI_lock->wait();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   784
    if (_initialized) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   785
      return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   786
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   787
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   788
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   789
  _being_initialized = true;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   790
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   791
  {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   792
    MutexUnlocker unlock(JVMCI_lock);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   793
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   794
    HandleMark hm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   795
    ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   796
    JavaThread* THREAD = JavaThread::current();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   797
    if (JVMCIENV->is_hotspot()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   798
      HotSpotJVMCI::compute_offsets(CHECK_EXIT);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   799
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   800
      JNIAccessMark jni(JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   801
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   802
      JNIJVMCI::initialize_ids(jni.env());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   803
      if (jni()->ExceptionCheck()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   804
        jni()->ExceptionDescribe();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   805
        fatal("JNI exception during init");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   806
      }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   807
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   808
    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
   809
    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
   810
    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
   811
    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
   812
    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
   813
    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
   814
    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
   815
    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
   816
    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
   817
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   818
    if (!JVMCIENV->is_hotspot()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   819
      JVMCIENV->copy_saved_properties();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   820
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   821
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   822
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   823
  _initialized = true;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   824
  _being_initialized = false;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   825
  JVMCI_lock->notify_all();
49192
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 48961
diff changeset
   826
}
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 48961
diff changeset
   827
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   828
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
   829
  Thread* THREAD = Thread::current();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   830
  // 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
   831
  // 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
   832
  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
   833
  if (JVMCIENV->is_hotspot()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   834
    JavaValue result(T_OBJECT);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   835
    JavaCallArguments args;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   836
    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
   837
    args.push_int(type2char(type));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   838
    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
   839
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   840
    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
   841
  } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   842
    JNIAccessMark jni(JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   843
    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
   844
                                           JNIJVMCI::HotSpotResolvedPrimitiveType_fromMetaspace_method(),
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   845
                                           mirror.as_jobject(), type2char(type));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   846
    if (jni()->ExceptionCheck()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   847
      return JVMCIObject();
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
    return JVMCIENV->wrap(result);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   850
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   851
}
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
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
   854
  if (!is_HotSpotJVMCIRuntime_initialized()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   855
    initialize(JVMCI_CHECK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   856
    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
   857
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   858
}
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
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
   861
  initialize(JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   862
  initialize_JVMCI(JVMCI_CHECK_(JVMCIObject()));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   863
  return _HotSpotJVMCIRuntime_instance;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   864
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   865
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   866
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   867
// private void CompilerToVM.registerNatives()
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   868
JVM_ENTRY_NO_ENV(void, JVM_RegisterJVMCINatives(JNIEnv *env, jclass c2vmClass))
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
#ifdef _LP64
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   871
#ifndef TARGET_ARCH_sparc
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   872
  uintptr_t heap_end = (uintptr_t) Universe::heap()->reserved_region().end();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   873
  uintptr_t allocation_end = heap_end + ((uintptr_t)16) * 1024 * 1024 * 1024;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   874
  guarantee(heap_end < allocation_end, "heap end too close to end of address space (might lead to erroneous TLAB allocations)");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   875
#endif // TARGET_ARCH_sparc
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   876
#else
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   877
  fatal("check TLAB allocation code for address space conflicts");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   878
#endif
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
  JNI_JVMCIENV(env);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   881
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   882
  if (!EnableJVMCI) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   883
    JVMCI_THROW_MSG(InternalError, "JVMCI is not enabled");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   884
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   885
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   886
  JVMCIENV->runtime()->initialize(JVMCIENV);
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
    ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   890
    HandleMark hm(thread);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   891
    ThreadToNativeFromVM trans(thread);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   892
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   893
    // 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
   894
    Universe::non_oop_word();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   895
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   896
    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
   897
      if (!env->ExceptionCheck()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   898
        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
   899
          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
   900
            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
   901
            break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   902
          }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   903
        }
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
        env->ExceptionDescribe();
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
      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
   908
    }
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
JVM_END
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   911
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   912
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   913
void JVMCIRuntime::shutdown() {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   914
  if (is_HotSpotJVMCIRuntime_initialized()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   915
    _shutdown_called = true;
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
    THREAD_JVMCIENV(JavaThread::current());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   918
    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
   919
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   920
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   921
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   922
void JVMCIRuntime::bootstrap_finished(TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   923
  if (is_HotSpotJVMCIRuntime_initialized()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   924
    THREAD_JVMCIENV(JavaThread::current());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   925
    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
   926
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   927
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   928
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   929
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
   930
  if (HAS_PENDING_EXCEPTION) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   931
    Handle exception(THREAD, PENDING_EXCEPTION);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   932
    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
   933
    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
   934
    CLEAR_PENDING_EXCEPTION;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   935
    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
   936
      // 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
   937
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   938
      java_lang_Throwable::print(exception(), tty);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   939
      tty->cr();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   940
      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
   941
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   942
      // 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
   943
      CLEAR_PENDING_EXCEPTION;
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 (!clear) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   946
      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
   947
    }
40074
135bb8aa1e18 8161274: [JVMCI] compiler/jvmci/events/JvmciNotifyInstallEventTest.java fails with NoClassDefFound
dnsimon
parents: 40034
diff changeset
   948
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   949
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   950
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   951
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   952
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
   953
  JavaThread* THREAD = JavaThread::current();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   954
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   955
  static volatile int report_error = 0;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   956
  if (!report_error && Atomic::cmpxchg(1, &report_error, 0) == 0) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   957
    // Only report an error once
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   958
    tty->print_raw_cr(message);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   959
    if (JVMCIENV != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   960
      JVMCIENV->describe_pending_exception(true);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   961
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   962
      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
   963
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   964
  } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   965
    // Allow error reporting thread to print the stack trace.  Windows
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   966
    // doesn't allow uninterruptible wait for JavaThreads
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   967
    const bool interruptible = true;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   968
    os::sleep(THREAD, 200, interruptible);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   969
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   970
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   971
  before_exit(THREAD);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   972
  vm_exit(-1);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   973
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   974
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   975
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   976
// 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
   977
// constantPoolOopDesc::verify_constant_pool_resolve.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   978
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
   979
  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
   980
    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
   981
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   982
  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
   983
    return true;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   984
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   985
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   986
  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
   987
    // 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
   988
    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
   989
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   990
  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
   991
    Reflection::VerifyClassAccessResults result =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   992
      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
   993
    return result == Reflection::ACCESS_OK;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   994
  }
40074
135bb8aa1e18 8161274: [JVMCI] compiler/jvmci/events/JvmciNotifyInstallEventTest.java fails with NoClassDefFound
dnsimon
parents: 40034
diff changeset
   995
  return true;
135bb8aa1e18 8161274: [JVMCI] compiler/jvmci/events/JvmciNotifyInstallEventTest.java fails with NoClassDefFound
dnsimon
parents: 40034
diff changeset
   996
}
135bb8aa1e18 8161274: [JVMCI] compiler/jvmci/events/JvmciNotifyInstallEventTest.java fails with NoClassDefFound
dnsimon
parents: 40034
diff changeset
   997
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   998
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
   999
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
  1000
                                          const constantPoolHandle& cpool,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1001
                                          Symbol* sym,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1002
                                          bool require_local) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1003
  JVMCI_EXCEPTION_CONTEXT;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1004
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1005
  // Now we need to check the SystemDictionary
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1006
  if (sym->char_at(0) == 'L' &&
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1007
    sym->char_at(sym->utf8_length()-1) == ';') {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1008
    // 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
  1009
    // 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
  1010
    TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1011
                    sym->utf8_length()-2,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1012
                    CHECK_NULL);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1013
    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
  1014
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1015
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1016
  Handle loader(THREAD, (oop)NULL);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1017
  Handle domain(THREAD, (oop)NULL);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1018
  if (accessing_klass != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1019
    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
  1020
    domain = Handle(THREAD, accessing_klass->protection_domain());
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1021
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1022
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1023
  Klass* found_klass;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1024
  {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1025
    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
  1026
    MutexLocker ml(Compile_lock);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1027
    if (!require_local) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1028
      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
  1029
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1030
      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
  1031
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1032
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1033
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1034
  // 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
  1035
  // 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
  1036
  // 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
  1037
  // 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
  1038
  // 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
  1039
  // is exhausted.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1040
  if (sym->char_at(0) == '[' &&
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1041
      (sym->char_at(1) == '[' || sym->char_at(1) == 'L')) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1042
    // We have an unloaded array.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1043
    // 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
  1044
    TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1045
                                                 sym->utf8_length()-1,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1046
                                                 CHECK_NULL);
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
    // Get element Klass recursively.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1049
    Klass* elem_klass =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1050
      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
  1051
                             cpool,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1052
                             elem_sym,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1053
                             require_local);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1054
    if (elem_klass != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1055
      // 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
  1056
      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
  1057
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1058
  }
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
  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
  1061
    // 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
  1062
    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
  1063
      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
  1064
        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
  1065
        if (kls->name() == sym) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1066
          return kls;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1067
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1068
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1069
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1070
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1071
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1072
  return found_klass;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1073
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1074
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1075
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1076
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
  1077
                                  Symbol* klass_name,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1078
                                  bool require_local) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1079
  ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1080
  constantPoolHandle cpool;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1081
  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
  1082
                                                 cpool,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1083
                                                 klass_name,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1084
                                                 require_local);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1085
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1086
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
// 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
  1089
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
  1090
                                        int index,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1091
                                        bool& is_accessible,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1092
                                        Klass* accessor) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1093
  JVMCI_EXCEPTION_CONTEXT;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1094
  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
  1095
  Symbol* klass_name = NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1096
  if (klass == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1097
    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
  1098
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1099
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1100
  if (klass == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1101
    // 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
  1102
    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
  1103
                                        cpool,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1104
                                        klass_name,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1105
                                        false);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1106
    // Calculate accessibility the hard way.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1107
    if (k == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1108
      is_accessible = false;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1109
    } 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
  1110
               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
  1111
      // 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
  1112
      is_accessible = false;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1113
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1114
      // 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
  1115
      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
  1116
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1117
    if (!is_accessible) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1118
      return NULL;
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
    return k;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1121
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1122
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1123
  // 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
  1124
  is_accessible = true;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1125
  return 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
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1128
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1129
// 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
  1130
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
  1131
                                   int index,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1132
                                   bool& is_accessible,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1133
                                   Klass* accessor) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1134
  ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1135
  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
  1136
  return result;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1137
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1138
54669
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
// 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
  1141
//
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1142
// 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
  1143
// in the accessor klass.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1144
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
  1145
                                        int index) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1146
  JVMCI_EXCEPTION_CONTEXT;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1147
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1148
  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
  1149
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1150
  constantPoolHandle cpool(thread, klass->constants());
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
  // 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
  1153
  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
  1154
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1155
  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
  1156
  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
  1157
  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
  1158
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1159
  // 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
  1160
  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
  1161
  bool holder_is_accessible;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1162
  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
  1163
                                               holder_is_accessible,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1164
                                               klass);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1165
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1166
  // 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
  1167
  // 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
  1168
  if (!holder_is_accessible) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1169
    return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1170
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1171
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1172
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1173
  // Perform the field lookup.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1174
  Klass*  canonical_holder =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1175
    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
  1176
  if (canonical_holder == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1177
    return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1178
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1179
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1180
  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
  1181
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1182
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1183
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1184
// 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
  1185
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
  1186
  ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1187
  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
  1188
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1189
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1190
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1191
// 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
  1192
// name, signature, and bytecode.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1193
methodHandle JVMCIRuntime::lookup_method(InstanceKlass* accessor,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1194
                               Klass*        holder,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1195
                               Symbol*       name,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1196
                               Symbol*       sig,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1197
                               Bytecodes::Code bc,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1198
                               constantTag   tag) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1199
  // 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
  1200
  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
  1201
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1202
  methodHandle dest_method;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1203
  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
  1204
  switch (bc) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1205
  case Bytecodes::_invokestatic:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1206
    dest_method =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1207
      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
  1208
    break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1209
  case Bytecodes::_invokespecial:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1210
    dest_method =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1211
      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
  1212
    break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1213
  case Bytecodes::_invokeinterface:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1214
    dest_method =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1215
      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
  1216
    break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1217
  case Bytecodes::_invokevirtual:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1218
    dest_method =
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1219
      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
  1220
    break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1221
  default: ShouldNotReachHere();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1222
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1223
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1224
  return dest_method;
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
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1227
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1228
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1229
methodHandle JVMCIRuntime::get_method_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
  1230
                                          int index, Bytecodes::Code bc,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1231
                                          InstanceKlass* accessor) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1232
  if (bc == Bytecodes::_invokedynamic) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1233
    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
  1234
    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
  1235
    if (is_resolved) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1236
      // 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
  1237
      // (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
  1238
      Method* adapter = cpce->f1_as_method();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1239
      return methodHandle(adapter);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1240
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1241
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1242
    return NULL;
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
  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
  1246
  bool holder_is_accessible;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1247
  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
  1248
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1249
  // 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
  1250
  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
  1251
  Symbol* sig_sym  = cpool->signature_ref_at(index);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1252
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1253
  if (cpool->has_preresolution()
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1254
      || ((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
  1255
          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
  1256
    // 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
  1257
    // 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
  1258
    // 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
  1259
    switch (bc) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1260
    case Bytecodes::_invokevirtual:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1261
    case Bytecodes::_invokeinterface:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1262
    case Bytecodes::_invokespecial:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1263
    case Bytecodes::_invokestatic:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1264
      {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1265
        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
  1266
        if (m != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1267
          return m;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1268
        }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1269
      }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1270
      break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1271
    default:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1272
      break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1273
    }
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
  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
  1277
    constantTag tag = cpool->tag_ref_at(index);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1278
    methodHandle m = lookup_method(accessor, holder, name_sym, sig_sym, bc, tag);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1279
    if (!m.is_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1280
      // We found the method.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1281
      return m;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1282
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1283
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1284
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1285
  // 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
  1286
  // not be found.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1287
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1288
  return NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1289
}
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
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1292
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
  1293
  // 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
  1294
  // 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
  1295
  // 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
  1296
  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
  1297
    return InstanceKlass::cast(method_holder);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1298
  } else if (method_holder->is_array_klass()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1299
    return InstanceKlass::cast(SystemDictionary::Object_klass());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1300
  } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1301
    ShouldNotReachHere();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1302
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1303
  return NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1304
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1305
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
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
methodHandle JVMCIRuntime::get_method_by_index(const constantPoolHandle& cpool,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1309
                                     int index, Bytecodes::Code bc,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1310
                                     InstanceKlass* accessor) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1311
  ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1312
  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
  1313
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1314
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1315
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1316
// 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
  1317
// class loads, evolution, breakpoints
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1318
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
  1319
  // 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
  1320
  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
  1321
    *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
  1322
    return JVMCI::dependencies_failed;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
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
  // Dependencies must be checked when the system dictionary changes
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1326
  // or if we don't know whether it has changed (i.e., compile_state == NULL).
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1327
  bool counter_changed = compile_state == NULL || compile_state->system_dictionary_modification_counter() != SystemDictionary::number_of_modifications();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1328
  CompileTask* task = compile_state == NULL ? NULL : compile_state->task();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1329
  Dependencies::DepType result = dependencies->validate_dependencies(task, counter_changed, failure_detail);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1330
  if (result == Dependencies::end_marker) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1331
    return JVMCI::ok;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1332
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1333
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1334
  if (!Dependencies::is_klass_type(result) || counter_changed) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1335
    return JVMCI::dependencies_failed;
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
  // The dependencies were invalid at the time of installation
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1338
  // without any intervening modification of the system
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1339
  // dictionary.  That means they were invalidly constructed.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1340
  return JVMCI::dependencies_invalid;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1341
}
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1342
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1343
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1344
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
  1345
  JVMCI_EXCEPTION_CONTEXT
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1346
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1347
  JVMCICompileState* compile_state = JVMCIENV->compile_state();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1348
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1349
  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
  1350
  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
  1351
    // 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
  1352
    // 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
  1353
    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
  1354
    return;
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
  HandleMark hm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1358
  JVMCIObject receiver = get_HotSpotJVMCIRuntime(JVMCIENV);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1359
  if (JVMCIENV->has_pending_exception()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1360
    JVMCIENV->describe_pending_exception(true);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1361
    compile_state->set_failure(false, "exception getting HotSpotJVMCIRuntime object");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1362
    return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1363
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1364
  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
  1365
  if (JVMCIENV->has_pending_exception()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1366
    JVMCIENV->describe_pending_exception(true);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1367
    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
  1368
    return;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1369
  }
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
  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
  1372
                                                                     (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
  1373
  if (!JVMCIENV->has_pending_exception()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1374
    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
  1375
      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
  1376
      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
  1377
        // 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
  1378
        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
  1379
        // ... 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
  1380
        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
  1381
        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
  1382
        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
  1383
      } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1384
        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
  1385
          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
  1386
        } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1387
          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
  1388
          compiler->inc_methods_compiled();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1389
        }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1390
      }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1391
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1392
      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
  1393
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1394
  } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1395
    // An uncaught exception was thrown during compilation. Generally these
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1396
    // should be handled by the Java code in some useful way but if they leak
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1397
    // through to here report them instead of dying or silently ignoring them.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1398
    JVMCIENV->describe_pending_exception(true);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1399
    compile_state->set_failure(false, "unexpected exception thrown");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1400
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1401
  if (compiler->is_bootstrapping()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1402
    compiler->set_bootstrap_compilation_request_handled();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1403
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1404
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1405
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1406
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1407
// ------------------------------------------------------------------
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1408
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
  1409
                                const methodHandle& method,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1410
                                nmethod*& nm,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1411
                                int entry_bci,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1412
                                CodeOffsets* offsets,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1413
                                int orig_pc_offset,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1414
                                CodeBuffer* code_buffer,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1415
                                int frame_words,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1416
                                OopMapSet* oop_map_set,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1417
                                ExceptionHandlerTable* handler_table,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1418
                                AbstractCompiler* compiler,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1419
                                DebugInformationRecorder* debug_info,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1420
                                Dependencies* dependencies,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1421
                                int compile_id,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1422
                                bool has_unsafe_access,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1423
                                bool has_wide_vector,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1424
                                JVMCIObject compiled_code,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1425
                                JVMCIObject nmethod_mirror,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1426
                                FailedSpeculation** failed_speculations,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1427
                                char* speculations,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1428
                                int speculations_len) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1429
  JVMCI_EXCEPTION_CONTEXT;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1430
  nm = NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1431
  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
  1432
  char* failure_detail = NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1433
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1434
  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
  1435
  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
  1436
  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
  1437
  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
  1438
  int nmethod_mirror_index;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1439
  if (!install_default) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1440
    // 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
  1441
    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
  1442
    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
  1443
  } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1444
    // 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
  1445
    nmethod_mirror_index = -1;
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
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1448
  JVMCI::CodeInstallResult result;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1449
  {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1450
    // To prevent compile queue updates.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1451
    MutexLocker locker(MethodCompileQueue_lock, THREAD);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1452
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1453
    // 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
  1454
    // 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
  1455
    MutexLocker ml(Compile_lock);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1456
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1457
    // 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
  1458
    dependencies->encode_content_bytes();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1459
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1460
    // 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
  1461
    if (LogCompilation) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1462
      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
  1463
        deps.log_dependency();
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
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1466
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1467
    // 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
  1468
    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
  1469
    if (result != JVMCI::ok) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1470
      // 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
  1471
      MethodData* mdp = method()->method_data();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1472
      if (mdp != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1473
        mdp->inc_decompile_count();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1474
#ifdef ASSERT
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1475
        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
  1476
          ResourceMark m;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1477
          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
  1478
        }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1479
#endif
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1480
      }
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
      // 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
  1483
      // 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
  1484
      // 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
  1485
      //code_buffer->free_blob();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1486
    } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1487
      ImplicitExceptionTable implicit_tbl;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1488
      nm =  nmethod::new_nmethod(method,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1489
                                 compile_id,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1490
                                 entry_bci,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1491
                                 offsets,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1492
                                 orig_pc_offset,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1493
                                 debug_info, dependencies, code_buffer,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1494
                                 frame_words, oop_map_set,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1495
                                 handler_table, &implicit_tbl,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1496
                                 compiler, comp_level,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1497
                                 speculations, speculations_len,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1498
                                 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
  1499
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1500
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1501
      // Free codeBlobs
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1502
      if (nm == NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1503
        // 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
  1504
        {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1505
          MutexUnlocker ml(Compile_lock);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1506
          MutexUnlocker locker(MethodCompileQueue_lock);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1507
          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
  1508
        }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1509
      } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1510
        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
  1511
        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
  1512
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1513
        // Record successful registration.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1514
        // (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
  1515
        if (JVMCIENV->compile_state() != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1516
          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
  1517
        }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1518
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1519
        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
  1520
        assert(data != NULL, "must be");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1521
        if (install_default) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1522
          assert(!nmethod_mirror.is_hotspot() || data->get_nmethod_mirror(nm) == NULL, "must be");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1523
          if (entry_bci == InvocationEntryBci) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1524
            if (TieredCompilation) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1525
              // 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
  1526
              CompiledMethod* old = method->code();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1527
              if (TraceMethodReplacement && old != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1528
                ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1529
                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
  1530
                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
  1531
              }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1532
              if (old != NULL ) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1533
                old->make_not_entrant();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1534
              }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1535
            }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1536
            if (TraceNMethodInstalls) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1537
              ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1538
              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
  1539
              ttyLocker ttyl;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1540
              tty->print_cr("Installing method (%d) %s [entry point: %p]",
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1541
                            comp_level,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1542
                            method_name, nm->entry_point());
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1543
            }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1544
            // Allow the code to be executed
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1545
            method->set_code(method, nm);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1546
          } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1547
            if (TraceNMethodInstalls ) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1548
              ResourceMark rm;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1549
              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
  1550
              ttyLocker ttyl;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1551
              tty->print_cr("Installing osr method (%d) %s @ %d",
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1552
                            comp_level,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1553
                            method_name,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1554
                            entry_bci);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1555
            }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1556
            InstanceKlass::cast(method->method_holder())->add_osr_nmethod(nm);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1557
          }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1558
        } else {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1559
          assert(!nmethod_mirror.is_hotspot() || data->get_nmethod_mirror(nm) == HotSpotJVMCI::resolve(nmethod_mirror), "must be");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1560
        }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1561
        nm->make_in_use();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1562
      }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1563
      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
  1564
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1565
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1566
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1567
  // 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
  1568
  if (failure_detail != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1569
    // 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
  1570
    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
  1571
    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
  1572
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1573
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1574
  // 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
  1575
  if (nm != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1576
    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
  1577
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1578
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54647
diff changeset
  1579
  return result;
38674
eacc567feae8 8156034: [JVMCI] Notify the jvmci compiler on completion of a bootstrap
never
parents: 38666
diff changeset
  1580
}