src/hotspot/share/jvmci/jvmciCodeInstaller.cpp
author coleenp
Wed, 13 Nov 2019 08:23:23 -0500
changeset 59056 15936b142f86
parent 58563 78bbb5dde2a3
permissions -rw-r--r--
8233913: Remove implicit conversion from Method* to methodHandle Summary: Fix call sites to use existing THREAD local or pass down THREAD local for shallower callsites. Make linkResolver methods return Method* for caller to handleize if needed. Reviewed-by: iklam, thartmann, hseigel
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: 52450
diff changeset
     2
 * Copyright (c) 2011, 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 "code/compiledIC.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    26
#include "compiler/compileBroker.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    27
#include "jvmci/jvmciCodeInstaller.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    28
#include "jvmci/jvmciCompilerToVM.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    29
#include "jvmci/jvmciRuntime.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54780
diff changeset
    30
#include "memory/universe.hpp"
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54669
diff changeset
    31
#include "oops/compressedOops.inline.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49360
diff changeset
    32
#include "runtime/interfaceSupport.inline.hpp"
49192
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
    33
#include "runtime/jniHandles.inline.hpp"
49593
4dd58ecc9912 8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents: 49592
diff changeset
    34
#include "runtime/sharedRuntime.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46620
diff changeset
    35
#include "utilities/align.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    36
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    37
// frequently used constants
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    38
// Allocate them with new so they are never destroyed (otherwise, a
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    39
// forced exit could destroy these objects while they are still in
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    40
// use).
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    41
ConstantOopWriteValue* CodeInstaller::_oop_null_scope_value = new (ResourceObj::C_HEAP, mtJVMCI) ConstantOopWriteValue(NULL);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    42
ConstantIntValue*      CodeInstaller::_int_m1_scope_value = new (ResourceObj::C_HEAP, mtJVMCI) ConstantIntValue(-1);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    43
ConstantIntValue*      CodeInstaller::_int_0_scope_value =  new (ResourceObj::C_HEAP, mtJVMCI) ConstantIntValue((jint)0);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    44
ConstantIntValue*      CodeInstaller::_int_1_scope_value =  new (ResourceObj::C_HEAP, mtJVMCI) ConstantIntValue(1);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    45
ConstantIntValue*      CodeInstaller::_int_2_scope_value =  new (ResourceObj::C_HEAP, mtJVMCI) ConstantIntValue(2);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    46
LocationValue*         CodeInstaller::_illegal_value = new (ResourceObj::C_HEAP, mtJVMCI) LocationValue(Location());
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    47
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    48
VMReg CodeInstaller::getVMRegFromLocation(JVMCIObject location, int total_frame_size, JVMCI_TRAPS) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    49
  if (location.is_null()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    50
    JVMCI_THROW_NULL(NullPointerException);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    51
  }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    52
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    53
  JVMCIObject reg = jvmci_env()->get_code_Location_reg(location);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    54
  jint offset = jvmci_env()->get_code_Location_offset(location);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    55
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    56
  if (reg.is_non_null()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    57
    // register
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    58
    jint number = jvmci_env()->get_code_Register_number(reg);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    59
    VMReg vmReg = CodeInstaller::get_hotspot_reg(number, JVMCI_CHECK_NULL);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    60
    if (offset % 4 == 0) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    61
      return vmReg->next(offset / 4);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    62
    } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    63
      JVMCI_ERROR_NULL("unaligned subregister offset %d in oop map", offset);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    64
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    65
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    66
    // stack slot
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    67
    if (offset % 4 == 0) {
39441
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    68
      VMReg vmReg = VMRegImpl::stack2reg(offset / 4);
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    69
      if (!OopMapValue::legal_vm_reg_name(vmReg)) {
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    70
        // This restriction only applies to VMRegs that are used in OopMap but
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    71
        // since that's the only use of VMRegs it's simplest to put this test
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    72
        // here.  This test should also be equivalent legal_vm_reg_name but JVMCI
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    73
        // clients can use max_oop_map_stack_stack_offset to detect this problem
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    74
        // directly.  The asserts just ensure that the tests are in agreement.
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    75
        assert(offset > CompilerToVM::Data::max_oop_map_stack_offset(), "illegal VMReg");
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    76
        JVMCI_ERROR_NULL("stack offset %d is too large to be encoded in OopMap (max %d)",
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    77
                         offset, CompilerToVM::Data::max_oop_map_stack_offset());
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    78
      }
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    79
      assert(OopMapValue::legal_vm_reg_name(vmReg), "illegal VMReg");
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    80
      return vmReg;
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    81
    } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    82
      JVMCI_ERROR_NULL("unaligned stack offset %d in oop map", offset);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    83
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    84
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    85
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    86
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    87
// creates a HotSpot oop map out of the byte arrays provided by DebugInfo
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    88
OopMap* CodeInstaller::create_oop_map(JVMCIObject debug_info, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    89
  JVMCIObject reference_map = jvmci_env()->get_DebugInfo_referenceMap(debug_info);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    90
  if (reference_map.is_null()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    91
    JVMCI_THROW_NULL(NullPointerException);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    92
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    93
  if (!jvmci_env()->isa_HotSpotReferenceMap(reference_map)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    94
    JVMCI_ERROR_NULL("unknown reference map: %s", jvmci_env()->klass_name(reference_map));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    95
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
    96
  if (!_has_wide_vector && SharedRuntime::is_wide_vector(jvmci_env()->get_HotSpotReferenceMap_maxRegisterSize(reference_map))) {
49342
9597f957122e 8198571: [JVMCI] must not install wide vector code unless runtime supports it
dnsimon
parents: 49192
diff changeset
    97
    if (SharedRuntime::polling_page_vectors_safepoint_handler_blob() == NULL) {
9597f957122e 8198571: [JVMCI] must not install wide vector code unless runtime supports it
dnsimon
parents: 49192
diff changeset
    98
      JVMCI_ERROR_NULL("JVMCI is producing code using vectors larger than the runtime supports");
9597f957122e 8198571: [JVMCI] must not install wide vector code unless runtime supports it
dnsimon
parents: 49192
diff changeset
    99
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   100
    _has_wide_vector = true;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   101
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   102
  OopMap* map = new OopMap(_total_frame_size, _parameter_count);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   103
  JVMCIObjectArray objects = jvmci_env()->get_HotSpotReferenceMap_objects(reference_map);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   104
  JVMCIObjectArray derivedBase = jvmci_env()->get_HotSpotReferenceMap_derivedBase(reference_map);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   105
  JVMCIPrimitiveArray sizeInBytes = jvmci_env()->get_HotSpotReferenceMap_sizeInBytes(reference_map);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   106
  if (objects.is_null() || derivedBase.is_null() || sizeInBytes.is_null()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   107
    JVMCI_THROW_NULL(NullPointerException);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   108
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   109
  if (JVMCIENV->get_length(objects) != JVMCIENV->get_length(derivedBase) || JVMCIENV->get_length(objects) != JVMCIENV->get_length(sizeInBytes)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   110
    JVMCI_ERROR_NULL("arrays in reference map have different sizes: %d %d %d", JVMCIENV->get_length(objects), JVMCIENV->get_length(derivedBase), JVMCIENV->get_length(sizeInBytes));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   111
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   112
  for (int i = 0; i < JVMCIENV->get_length(objects); i++) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   113
    JVMCIObject location = JVMCIENV->get_object_at(objects, i);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   114
    JVMCIObject baseLocation = JVMCIENV->get_object_at(derivedBase, i);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   115
    jint bytes = JVMCIENV->get_int_at(sizeInBytes, i);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   116
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   117
    VMReg vmReg = getVMRegFromLocation(location, _total_frame_size, JVMCI_CHECK_NULL);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   118
    if (baseLocation.is_non_null()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   119
      // derived oop
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   120
#ifdef _LP64
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   121
      if (bytes == 8) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   122
#else
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   123
      if (bytes == 4) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   124
#endif
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   125
        VMReg baseReg = getVMRegFromLocation(baseLocation, _total_frame_size, JVMCI_CHECK_NULL);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   126
        map->set_derived_oop(vmReg, baseReg);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   127
      } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   128
        JVMCI_ERROR_NULL("invalid derived oop size in ReferenceMap: %d", bytes);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   129
      }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   130
#ifdef _LP64
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   131
    } else if (bytes == 8) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   132
      // wide oop
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   133
      map->set_oop(vmReg);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   134
    } else if (bytes == 4) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   135
      // narrow oop
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   136
      map->set_narrowoop(vmReg);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   137
#else
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   138
    } else if (bytes == 4) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   139
      map->set_oop(vmReg);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   140
#endif
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   141
    } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   142
      JVMCI_ERROR_NULL("invalid oop size in ReferenceMap: %d", bytes);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   143
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   144
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   145
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   146
  JVMCIObject callee_save_info = jvmci_env()->get_DebugInfo_calleeSaveInfo(debug_info);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   147
  if (callee_save_info.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   148
    JVMCIObjectArray registers = jvmci_env()->get_RegisterSaveLayout_registers(callee_save_info);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   149
    JVMCIPrimitiveArray slots = jvmci_env()->get_RegisterSaveLayout_slots(callee_save_info);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   150
    for (jint i = 0; i < JVMCIENV->get_length(slots); i++) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   151
      JVMCIObject jvmci_reg = JVMCIENV->get_object_at(registers, i);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   152
      jint jvmci_reg_number = jvmci_env()->get_code_Register_number(jvmci_reg);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   153
      VMReg hotspot_reg = CodeInstaller::get_hotspot_reg(jvmci_reg_number, JVMCI_CHECK_NULL);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   154
      // HotSpot stack slots are 4 bytes
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   155
      jint jvmci_slot = JVMCIENV->get_int_at(slots, i);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   156
      jint hotspot_slot = jvmci_slot * VMRegImpl::slots_per_word;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   157
      VMReg hotspot_slot_as_reg = VMRegImpl::stack2reg(hotspot_slot);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   158
      map->set_callee_saved(hotspot_slot_as_reg, hotspot_reg);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   159
#ifdef _LP64
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   160
      // (copied from generate_oop_map() in c1_Runtime1_x86.cpp)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   161
      VMReg hotspot_slot_hi_as_reg = VMRegImpl::stack2reg(hotspot_slot + 1);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   162
      map->set_callee_saved(hotspot_slot_hi_as_reg, hotspot_reg->next());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   163
#endif
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
  return map;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   167
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   168
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
   169
#if INCLUDE_AOT
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   170
AOTOopRecorder::AOTOopRecorder(CodeInstaller* code_inst, Arena* arena, bool deduplicate) : OopRecorder(arena, deduplicate) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   171
  _code_inst = code_inst;
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   172
  _meta_refs = new GrowableArray<jobject>();
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   173
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   174
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   175
int AOTOopRecorder::nr_meta_refs() const {
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   176
  return _meta_refs->length();
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   177
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   178
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   179
jobject AOTOopRecorder::meta_element(int pos) const {
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   180
  return _meta_refs->at(pos);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   181
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   182
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   183
int AOTOopRecorder::find_index(Metadata* h) {
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   184
  JavaThread* THREAD = JavaThread::current();
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   185
  JVMCIEnv* JVMCIENV = _code_inst->jvmci_env();
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   186
  int oldCount = metadata_count();
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   187
  int index =  this->OopRecorder::find_index(h);
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   188
  int newCount = metadata_count();
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   189
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   190
  if (oldCount == newCount) {
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   191
    // found a match
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   192
    return index;
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   193
  }
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   194
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   195
  vmassert(index + 1 == newCount, "must be last");
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   196
50746
85789fb05154 8198909: [Graal] compiler/codecache/stress/UnexpectedDeoptimizationTest.java crashed with SIGSEGV
never
parents: 50729
diff changeset
   197
  JVMCIKlassHandle klass(THREAD);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   198
  JVMCIObject result;
51078
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 50858
diff changeset
   199
  guarantee(h != NULL,
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 50858
diff changeset
   200
            "If DebugInformationRecorder::describe_scope passes NULL oldCount == newCount must hold.");
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   201
  if (h->is_klass()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   202
    klass = (Klass*) h;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   203
    result = JVMCIENV->get_jvmci_type(klass, JVMCI_CATCH);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   204
  } else if (h->is_method()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   205
    Method* method = (Method*) h;
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
   206
    methodHandle mh(THREAD, method);
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
   207
    result = JVMCIENV->get_jvmci_method(mh, JVMCI_CATCH);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   208
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   209
  jobject ref = JVMCIENV->get_jobject(result);
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   210
  record_meta_ref(ref, index);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   211
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   212
  return index;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   213
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   214
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   215
int AOTOopRecorder::find_index(jobject h) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   216
  if (h == NULL) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   217
    return 0;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   218
  }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   219
  oop javaMirror = JNIHandles::resolve(h);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   220
  Klass* klass = java_lang_Class::as_Klass(javaMirror);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   221
  return find_index(klass);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   222
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   223
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   224
void AOTOopRecorder::record_meta_ref(jobject o, int index) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   225
  assert(index > 0, "must be 1..n");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   226
  index -= 1; // reduce by one to convert to array index
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   227
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   228
  assert(index == _meta_refs->length(), "must be last");
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   229
  _meta_refs->append(o);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   230
}
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
   231
#endif // INCLUDE_AOT
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   232
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   233
void* CodeInstaller::record_metadata_reference(CodeSection* section, address dest, JVMCIObject constant, JVMCI_TRAPS) {
36842
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36329
diff changeset
   234
  /*
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36329
diff changeset
   235
   * This method needs to return a raw (untyped) pointer, since the value of a pointer to the base
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36329
diff changeset
   236
   * class is in general not equal to the pointer of the subclass. When patching metaspace pointers,
38678
06d6c40ce33b 8156768: [JVMCI] remove support for patching Symbol pointers
rschatz
parents: 36842
diff changeset
   237
   * the compiler expects a direct pointer to the subclass (Klass* or Method*), not a pointer to the
06d6c40ce33b 8156768: [JVMCI] remove support for patching Symbol pointers
rschatz
parents: 36842
diff changeset
   238
   * base class (Metadata* or MetaspaceObj*).
36842
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36329
diff changeset
   239
   */
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   240
  JVMCIObject obj = jvmci_env()->get_HotSpotMetaspaceConstantImpl_metaspaceObject(constant);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   241
  if (jvmci_env()->isa_HotSpotResolvedObjectTypeImpl(obj)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   242
    Klass* klass = JVMCIENV->asKlass(obj);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   243
    assert(!jvmci_env()->get_HotSpotMetaspaceConstantImpl_compressed(constant), "unexpected compressed klass pointer %s @ " INTPTR_FORMAT, klass->name()->as_C_string(), p2i(klass));
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   244
    int index = _oop_recorder->find_index(klass);
41697
94ef14db8a20 8166869: [JVMCI] record metadata relocations for metadata references
never
parents: 40093
diff changeset
   245
    section->relocate(dest, metadata_Relocation::spec(index));
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   246
    TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string());
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   247
    return klass;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   248
  } else if (jvmci_env()->isa_HotSpotResolvedJavaMethodImpl(obj)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   249
    Method* method = jvmci_env()->asMethod(obj);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   250
    assert(!jvmci_env()->get_HotSpotMetaspaceConstantImpl_compressed(constant), "unexpected compressed method pointer %s @ " INTPTR_FORMAT, method->name()->as_C_string(), p2i(method));
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   251
    int index = _oop_recorder->find_index(method);
41697
94ef14db8a20 8166869: [JVMCI] record metadata relocations for metadata references
never
parents: 40093
diff changeset
   252
    section->relocate(dest, metadata_Relocation::spec(index));
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   253
    TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), method->name()->as_C_string());
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   254
    return method;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   255
  } else {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   256
    JVMCI_ERROR_NULL("unexpected metadata reference for constant of type %s", jvmci_env()->klass_name(obj));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   257
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   258
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   259
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   260
#ifdef _LP64
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   261
narrowKlass CodeInstaller::record_narrow_metadata_reference(CodeSection* section, address dest, JVMCIObject constant, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   262
  JVMCIObject obj = jvmci_env()->get_HotSpotMetaspaceConstantImpl_metaspaceObject(constant);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   263
  assert(jvmci_env()->get_HotSpotMetaspaceConstantImpl_compressed(constant), "unexpected uncompressed pointer");
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   264
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   265
  if (!jvmci_env()->isa_HotSpotResolvedObjectTypeImpl(obj)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   266
    JVMCI_ERROR_0("unexpected compressed pointer of type %s", jvmci_env()->klass_name(obj));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   267
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   268
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   269
  Klass* klass = JVMCIENV->asKlass(obj);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   270
  int index = _oop_recorder->find_index(klass);
41697
94ef14db8a20 8166869: [JVMCI] record metadata relocations for metadata references
never
parents: 40093
diff changeset
   271
  section->relocate(dest, metadata_Relocation::spec(index));
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   272
  TRACE_jvmci_3("narrowKlass[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string());
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54669
diff changeset
   273
  return CompressedKlassPointers::encode(klass);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   274
}
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   275
#endif
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   276
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   277
Location::Type CodeInstaller::get_oop_type(JVMCIObject value) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   278
  JVMCIObject valueKind = jvmci_env()->get_Value_valueKind(value);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   279
  JVMCIObject platformKind = jvmci_env()->get_ValueKind_platformKind(valueKind);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   280
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   281
  if (jvmci_env()->equals(platformKind, word_kind())) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   282
    return Location::oop;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   283
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   284
    return Location::narrowoop;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   285
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   286
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   287
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   288
ScopeValue* CodeInstaller::get_scope_value(JVMCIObject value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, JVMCI_TRAPS) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   289
  second = NULL;
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   290
  if (value.is_null()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   291
    JVMCI_THROW_NULL(NullPointerException);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   292
  } else if (JVMCIENV->equals(value, jvmci_env()->get_Value_ILLEGAL())) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   293
    if (type != T_ILLEGAL) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   294
      JVMCI_ERROR_NULL("unexpected illegal value, expected %s", basictype_to_str(type));
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   295
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   296
    return _illegal_value;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   297
  } else if (jvmci_env()->isa_RegisterValue(value)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   298
    JVMCIObject reg = jvmci_env()->get_RegisterValue_reg(value);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   299
    jint number = jvmci_env()->get_code_Register_number(reg);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   300
    VMReg hotspotRegister = get_hotspot_reg(number, JVMCI_CHECK_NULL);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   301
    if (is_general_purpose_reg(hotspotRegister)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   302
      Location::Type locationType;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   303
      if (type == T_OBJECT) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   304
        locationType = get_oop_type(value);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   305
      } else if (type == T_LONG) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   306
        locationType = Location::lng;
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   307
      } else if (type == T_INT || type == T_FLOAT || type == T_SHORT || type == T_CHAR || type == T_BYTE || type == T_BOOLEAN) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   308
        locationType = Location::int_in_long;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   309
      } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   310
        JVMCI_ERROR_NULL("unexpected type %s in cpu register", basictype_to_str(type));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   311
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   312
      ScopeValue* value = new LocationValue(Location::new_reg_loc(locationType, hotspotRegister));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   313
      if (type == T_LONG) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   314
        second = value;
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
      return value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   317
    } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   318
      Location::Type locationType;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   319
      if (type == T_FLOAT) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   320
        // this seems weird, but the same value is used in c1_LinearScan
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   321
        locationType = Location::normal;
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   322
      } else if (type == T_DOUBLE) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   323
        locationType = Location::dbl;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   324
      } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   325
        JVMCI_ERROR_NULL("unexpected type %s in floating point register", basictype_to_str(type));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   326
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   327
      ScopeValue* value = new LocationValue(Location::new_reg_loc(locationType, hotspotRegister));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   328
      if (type == T_DOUBLE) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   329
        second = value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   330
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   331
      return value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   332
    }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   333
  } else if (jvmci_env()->isa_StackSlot(value)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   334
    jint offset = jvmci_env()->get_StackSlot_offset(value);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   335
    if (jvmci_env()->get_StackSlot_addFrameSize(value)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   336
      offset += _total_frame_size;
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
    Location::Type locationType;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   340
    if (type == T_OBJECT) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   341
      locationType = get_oop_type(value);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   342
    } else if (type == T_LONG) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   343
      locationType = Location::lng;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   344
    } else if (type == T_DOUBLE) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   345
      locationType = Location::dbl;
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   346
    } else if (type == T_INT || type == T_FLOAT || type == T_SHORT || type == T_CHAR || type == T_BYTE || type == T_BOOLEAN) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   347
      locationType = Location::normal;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   348
    } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   349
      JVMCI_ERROR_NULL("unexpected type %s in stack slot", basictype_to_str(type));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   350
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   351
    ScopeValue* value = new LocationValue(Location::new_stk_loc(locationType, offset));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   352
    if (type == T_DOUBLE || type == T_LONG) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   353
      second = value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   354
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   355
    return value;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   356
  } else if (jvmci_env()->isa_JavaConstant(value)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   357
    if (jvmci_env()->isa_PrimitiveConstant(value)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   358
      if (jvmci_env()->isa_RawConstant(value)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   359
        jlong prim = jvmci_env()->get_PrimitiveConstant_primitive(value);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   360
        return new ConstantLongValue(prim);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   361
      } else {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   362
        BasicType constantType = jvmci_env()->kindToBasicType(jvmci_env()->get_PrimitiveConstant_kind(value), JVMCI_CHECK_NULL);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   363
        if (type != constantType) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   364
          JVMCI_ERROR_NULL("primitive constant type doesn't match, expected %s but got %s", basictype_to_str(type), basictype_to_str(constantType));
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   365
        }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   366
        if (type == T_INT || type == T_FLOAT) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   367
          jint prim = (jint)jvmci_env()->get_PrimitiveConstant_primitive(value);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   368
          switch (prim) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   369
            case -1: return _int_m1_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   370
            case  0: return _int_0_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   371
            case  1: return _int_1_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   372
            case  2: return _int_2_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   373
            default: return new ConstantIntValue(prim);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   374
          }
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   375
        } else if (type == T_LONG || type == T_DOUBLE) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   376
          jlong prim = jvmci_env()->get_PrimitiveConstant_primitive(value);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   377
          second = _int_1_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   378
          return new ConstantLongValue(prim);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   379
        } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   380
          JVMCI_ERROR_NULL("unexpected primitive constant type %s", basictype_to_str(type));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   381
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   382
      }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   383
    } else if (jvmci_env()->isa_NullConstant(value) || jvmci_env()->isa_HotSpotCompressedNullConstant(value)) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   384
      if (type == T_OBJECT) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   385
        return _oop_null_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   386
      } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   387
        JVMCI_ERROR_NULL("unexpected null constant, expected %s", basictype_to_str(type));
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   388
      }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   389
    } else if (jvmci_env()->isa_HotSpotObjectConstantImpl(value)) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   390
      if (type == T_OBJECT) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   391
        Handle obj = jvmci_env()->asConstant(value, JVMCI_CHECK_NULL);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   392
        if (obj == NULL) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   393
          JVMCI_ERROR_NULL("null value must be in NullConstant");
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   394
        }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   395
        return new ConstantOopWriteValue(JNIHandles::make_local(obj()));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   396
      } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   397
        JVMCI_ERROR_NULL("unexpected object constant, expected %s", basictype_to_str(type));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   398
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   399
    }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   400
  } else if (jvmci_env()->isa_VirtualObject(value)) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   401
    if (type == T_OBJECT) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   402
      int id = jvmci_env()->get_VirtualObject_id(value);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   403
      if (0 <= id && id < objects->length()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   404
        ScopeValue* object = objects->at(id);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   405
        if (object != NULL) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   406
          return object;
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   407
        }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   408
      }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   409
      JVMCI_ERROR_NULL("unknown virtual object id %d", id);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   410
    } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   411
      JVMCI_ERROR_NULL("unexpected virtual object, expected %s", basictype_to_str(type));
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   412
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   413
  }
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   414
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   415
  JVMCI_ERROR_NULL("unexpected value in scope: %s", jvmci_env()->klass_name(value))
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   416
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   417
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   418
void CodeInstaller::record_object_value(ObjectValue* sv, JVMCIObject value, GrowableArray<ScopeValue*>* objects, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   419
  JVMCIObject type = jvmci_env()->get_VirtualObject_type(value);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   420
  int id = jvmci_env()->get_VirtualObject_id(value);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   421
  Klass* klass = JVMCIENV->asKlass(type);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   422
  bool isLongArray = klass == Universe::longArrayKlassObj();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   423
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   424
  JVMCIObjectArray values = jvmci_env()->get_VirtualObject_values(value);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   425
  JVMCIObjectArray slotKinds = jvmci_env()->get_VirtualObject_slotKinds(value);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   426
  for (jint i = 0; i < JVMCIENV->get_length(values); i++) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   427
    ScopeValue* cur_second = NULL;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   428
    JVMCIObject object = JVMCIENV->get_object_at(values, i);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   429
    BasicType type = jvmci_env()->kindToBasicType(JVMCIENV->get_object_at(slotKinds, i), JVMCI_CHECK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   430
    ScopeValue* value = get_scope_value(object, type, objects, cur_second, JVMCI_CHECK);
33160
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 (isLongArray && cur_second == NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   433
      // we're trying to put ints into a long array... this isn't really valid, but it's used for some optimizations.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   434
      // add an int 0 constant
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   435
      cur_second = _int_0_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   436
    }
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
    if (cur_second != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   439
      sv->field_values()->append(cur_second);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   440
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   441
    assert(value != NULL, "missing value");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   442
    sv->field_values()->append(value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   443
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   444
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   445
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   446
MonitorValue* CodeInstaller::get_monitor_value(JVMCIObject value, GrowableArray<ScopeValue*>* objects, JVMCI_TRAPS) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   447
  if (value.is_null()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   448
    JVMCI_THROW_NULL(NullPointerException);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   449
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   450
  if (!jvmci_env()->isa_StackLockValue(value)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   451
    JVMCI_ERROR_NULL("Monitors must be of type StackLockValue, got %s", jvmci_env()->klass_name(value));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   452
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   453
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   454
  ScopeValue* second = NULL;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   455
  ScopeValue* owner_value = get_scope_value(jvmci_env()->get_StackLockValue_owner(value), T_OBJECT, objects, second, JVMCI_CHECK_NULL);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   456
  assert(second == NULL, "monitor cannot occupy two stack slots");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   457
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   458
  ScopeValue* lock_data_value = get_scope_value(jvmci_env()->get_StackLockValue_slot(value), T_LONG, objects, second, JVMCI_CHECK_NULL);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   459
  assert(second == lock_data_value, "monitor is LONG value that occupies two stack slots");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   460
  assert(lock_data_value->is_location(), "invalid monitor location");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   461
  Location lock_data_loc = ((LocationValue*)lock_data_value)->location();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   462
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   463
  bool eliminated = false;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   464
  if (jvmci_env()->get_StackLockValue_eliminated(value)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   465
    eliminated = true;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   466
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   467
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   468
  return new MonitorValue(owner_value, lock_data_loc, eliminated);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   469
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   470
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   471
void CodeInstaller::initialize_dependencies(JVMCIObject compiled_code, OopRecorder* oop_recorder, JVMCI_TRAPS) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   472
  JavaThread* thread = JavaThread::current();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   473
  CompilerThread* compilerThread = thread->is_Compiler_thread() ? thread->as_CompilerThread() : NULL;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   474
  _oop_recorder = oop_recorder;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   475
  _dependencies = new Dependencies(&_arena, _oop_recorder, compilerThread != NULL ? compilerThread->log() : NULL);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   476
  JVMCIObjectArray assumptions = jvmci_env()->get_HotSpotCompiledCode_assumptions(compiled_code);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   477
  if (assumptions.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   478
    int length = JVMCIENV->get_length(assumptions);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   479
    for (int i = 0; i < length; ++i) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   480
      JVMCIObject assumption = JVMCIENV->get_object_at(assumptions, i);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   481
      if (assumption.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   482
        if (jvmci_env()->isa_Assumptions_NoFinalizableSubclass(assumption)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   483
          assumption_NoFinalizableSubclass(assumption);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   484
        } else if (jvmci_env()->isa_Assumptions_ConcreteSubtype(assumption)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   485
          assumption_ConcreteSubtype(assumption);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   486
        } else if (jvmci_env()->isa_Assumptions_LeafType(assumption)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   487
          assumption_LeafType(assumption);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   488
        } else if (jvmci_env()->isa_Assumptions_ConcreteMethod(assumption)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   489
          assumption_ConcreteMethod(assumption);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   490
        } else if (jvmci_env()->isa_Assumptions_CallSiteTargetValue(assumption)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   491
          assumption_CallSiteTargetValue(assumption, JVMCI_CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   492
        } else {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   493
          JVMCI_ERROR("unexpected Assumption subclass %s", jvmci_env()->klass_name(assumption));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   494
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   495
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   496
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   497
  }
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   498
  if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   499
    JVMCIObjectArray methods = jvmci_env()->get_HotSpotCompiledCode_methods(compiled_code);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   500
    if (methods.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   501
      int length = JVMCIENV->get_length(methods);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   502
      for (int i = 0; i < length; ++i) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   503
        JVMCIObject method_handle = JVMCIENV->get_object_at(methods, i);
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
   504
        Method* method = jvmci_env()->asMethod(method_handle);
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
   505
        _dependencies->assert_evol_method(method);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   506
      }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   507
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   508
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   509
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   510
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
   511
#if INCLUDE_AOT
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   512
RelocBuffer::~RelocBuffer() {
58084
cddef3bde924 8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents: 55293
diff changeset
   513
  FREE_C_HEAP_ARRAY(char, _buffer);
33160
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
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   516
address RelocBuffer::begin() const {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   517
  if (_buffer != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   518
    return (address) _buffer;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   519
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   520
  return (address) _static_buffer;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   521
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   522
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   523
void RelocBuffer::set_size(size_t bytes) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   524
  assert(bytes <= _size, "can't grow in size!");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   525
  _size = bytes;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   526
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   527
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   528
void RelocBuffer::ensure_size(size_t bytes) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   529
  assert(_buffer == NULL, "can only be used once");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   530
  assert(_size == 0, "can only be used once");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   531
  if (bytes >= RelocBuffer::stack_size) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   532
    _buffer = NEW_C_HEAP_ARRAY(char, bytes, mtJVMCI);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   533
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   534
  _size = bytes;
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
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   537
JVMCI::CodeInstallResult CodeInstaller::gather_metadata(JVMCIObject target, JVMCIObject compiled_code, CodeMetadata& metadata, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   538
  assert(JVMCIENV->is_hotspot(), "AOT code is executed only in HotSpot mode");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   539
  CodeBuffer buffer("JVMCI Compiler CodeBuffer for Metadata");
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   540
  AOTOopRecorder* recorder = new AOTOopRecorder(this, &_arena, true);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   541
  initialize_dependencies(compiled_code, recorder, JVMCI_CHECK_OK);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   542
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   543
  metadata.set_oop_recorder(recorder);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   544
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   545
  // Get instructions and constants CodeSections early because we need it.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   546
  _instructions = buffer.insts();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   547
  _constants = buffer.consts();
50104
4ea7917929b9 8185505: AArch64: Port AOT to AArch64
aph
parents: 49593
diff changeset
   548
  buffer.set_immutable_PIC(_immutable_pic_compilation);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   549
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   550
  initialize_fields(target, compiled_code, JVMCI_CHECK_OK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   551
  JVMCI::CodeInstallResult result = initialize_buffer(buffer, false, JVMCI_CHECK_OK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   552
  if (result != JVMCI::ok) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   553
    return result;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   554
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   555
38695
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38692
diff changeset
   556
  _debug_recorder->pcs_size(); // create the sentinel record
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   557
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   558
  assert(_debug_recorder->pcs_length() >= 2, "must be at least 2");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   559
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   560
  metadata.set_pc_desc(_debug_recorder->pcs(), _debug_recorder->pcs_length());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   561
  metadata.set_scopes(_debug_recorder->stream()->buffer(), _debug_recorder->data_size());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   562
  metadata.set_exception_table(&_exception_handler_table);
55293
d19dc5b10fbb 8209626: [JVMCI] Use implicit exception table for dispatch and printing
never
parents: 55159
diff changeset
   563
  metadata.set_implicit_exception_table(&_implicit_exception_table);
33160
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
  RelocBuffer* reloc_buffer = metadata.get_reloc_buffer();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   566
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   567
  reloc_buffer->ensure_size(buffer.total_relocation_size());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   568
  size_t size = (size_t) buffer.copy_relocations_to(reloc_buffer->begin(), (CodeBuffer::csize_t) reloc_buffer->size(), true);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   569
  reloc_buffer->set_size(size);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   570
  return JVMCI::ok;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   571
}
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
   572
#endif // INCLUDE_AOT
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   573
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   574
// constructor used to create a method
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   575
JVMCI::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   576
    JVMCIObject target,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   577
    JVMCIObject compiled_code,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   578
    CodeBlob*& cb,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   579
    JVMCIObject installed_code,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   580
    FailedSpeculation** failed_speculations,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   581
    char* speculations,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   582
    int speculations_len,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   583
    JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   584
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   585
  CodeBuffer buffer("JVMCI Compiler CodeBuffer");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   586
  OopRecorder* recorder = new OopRecorder(&_arena, true);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   587
  initialize_dependencies(compiled_code, recorder, JVMCI_CHECK_OK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   588
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   589
  // Get instructions and constants CodeSections early because we need it.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   590
  _instructions = buffer.insts();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   591
  _constants = buffer.consts();
50104
4ea7917929b9 8185505: AArch64: Port AOT to AArch64
aph
parents: 49593
diff changeset
   592
#if INCLUDE_AOT
4ea7917929b9 8185505: AArch64: Port AOT to AArch64
aph
parents: 49593
diff changeset
   593
  buffer.set_immutable_PIC(_immutable_pic_compilation);
4ea7917929b9 8185505: AArch64: Port AOT to AArch64
aph
parents: 49593
diff changeset
   594
#endif
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   595
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   596
  initialize_fields(target, compiled_code, JVMCI_CHECK_OK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   597
  JVMCI::CodeInstallResult result = initialize_buffer(buffer, true, JVMCI_CHECK_OK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   598
  if (result != JVMCI::ok) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   599
    return result;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   600
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   601
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   602
  int stack_slots = _total_frame_size / HeapWordSize; // conversion to words
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   603
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   604
  if (!jvmci_env()->isa_HotSpotCompiledNmethod(compiled_code)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   605
    JVMCIObject stubName = jvmci_env()->get_HotSpotCompiledCode_name(compiled_code);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   606
    if (stubName.is_null()) {
48443
8935285e8759 8194271: jaotc crashes with --debug flag
iveresov
parents: 47881
diff changeset
   607
      JVMCI_ERROR_OK("stub should have a name");
8935285e8759 8194271: jaotc crashes with --debug flag
iveresov
parents: 47881
diff changeset
   608
    }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   609
    char* name = strdup(jvmci_env()->as_utf8_string(stubName));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   610
    cb = RuntimeStub::new_runtime_stub(name,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   611
                                       &buffer,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   612
                                       CodeOffsets::frame_never_safe,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   613
                                       stack_slots,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   614
                                       _debug_recorder->_oopmaps,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   615
                                       false);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   616
    result = JVMCI::ok;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   617
  } else {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   618
    JVMCICompileState* compile_state = (JVMCICompileState*) (address) jvmci_env()->get_HotSpotCompiledNmethod_compileState(compiled_code);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   619
    if (compile_state != NULL) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   620
      jvmci_env()->set_compile_state(compile_state);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   621
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   622
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
   623
    Thread* thread = Thread::current();
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
   624
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
   625
    methodHandle method(thread, jvmci_env()->asMethod(jvmci_env()->get_HotSpotCompiledNmethod_method(compiled_code)));
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   626
    jint entry_bci = jvmci_env()->get_HotSpotCompiledNmethod_entryBCI(compiled_code);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   627
    bool has_unsafe_access = jvmci_env()->get_HotSpotCompiledNmethod_hasUnsafeAccess(compiled_code) == JNI_TRUE;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   628
    jint id = jvmci_env()->get_HotSpotCompiledNmethod_id(compiled_code);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   629
    if (id == -1) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   630
      // Make sure a valid compile_id is associated with every compile
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
   631
      id = CompileBroker::assign_compile_id_unlocked(thread, method, entry_bci);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   632
      jvmci_env()->set_HotSpotCompiledNmethod_id(compiled_code, id);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   633
    }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   634
    if (!jvmci_env()->isa_HotSpotNmethod(installed_code)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   635
      JVMCI_THROW_MSG_(IllegalArgumentException, "InstalledCode object must be a HotSpotNmethod when installing a HotSpotCompiledNmethod", JVMCI::ok);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   636
    }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   637
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   638
    JVMCIObject mirror = installed_code;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   639
    nmethod* nm = NULL;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   640
    result = runtime()->register_method(jvmci_env(), method, nm, entry_bci, &_offsets, _orig_pc_offset, &buffer,
55293
d19dc5b10fbb 8209626: [JVMCI] Use implicit exception table for dispatch and printing
never
parents: 55159
diff changeset
   641
                                        stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, &_implicit_exception_table,
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   642
                                        compiler, _debug_recorder, _dependencies, id,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   643
                                        has_unsafe_access, _has_wide_vector, compiled_code, mirror,
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   644
                                        failed_speculations, speculations, speculations_len);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   645
    cb = nm->as_codeblob_or_null();
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   646
    if (nm != NULL && compile_state == NULL) {
58563
78bbb5dde2a3 8231659: [JVMCI] Could not work PrintAssembly for JVMCI installed code
never
parents: 58084
diff changeset
   647
      // This compile didn't come through the CompileBroker so perform the printing here
36329
06727ae6971e 8150561: [AArch64] JVMCI improvements
twisti
parents: 36063
diff changeset
   648
      DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, compiler);
58563
78bbb5dde2a3 8231659: [JVMCI] Could not work PrintAssembly for JVMCI installed code
never
parents: 58084
diff changeset
   649
      nm->maybe_print_nmethod(directive);
36329
06727ae6971e 8150561: [AArch64] JVMCI improvements
twisti
parents: 36063
diff changeset
   650
      DirectivesStack::release(directive);
06727ae6971e 8150561: [AArch64] JVMCI improvements
twisti
parents: 36063
diff changeset
   651
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   652
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   653
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   654
  if (cb != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   655
    // Make sure the pre-calculated constants section size was correct.
33198
dlong
parents: 33160
diff changeset
   656
    guarantee((cb->code_begin() - cb->content_begin()) >= _constants_size, "%d < %d", (int)(cb->code_begin() - cb->content_begin()), _constants_size);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   657
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   658
  return result;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   659
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   660
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   661
void CodeInstaller::initialize_fields(JVMCIObject target, JVMCIObject compiled_code, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   662
  if (jvmci_env()->isa_HotSpotCompiledNmethod(compiled_code)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   663
    JVMCIObject hotspotJavaMethod = jvmci_env()->get_HotSpotCompiledNmethod_method(compiled_code);
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
   664
    Thread* thread = Thread::current();
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
   665
    methodHandle method(thread, jvmci_env()->asMethod(hotspotJavaMethod));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   666
    _parameter_count = method->size_of_parameters();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   667
    TRACE_jvmci_2("installing code for %s", method->name_and_sig_as_C_string());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   668
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   669
    // Must be a HotSpotCompiledRuntimeStub.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   670
    // Only used in OopMap constructor for non-product builds
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   671
    _parameter_count = 0;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   672
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   673
  _sites_handle = jvmci_env()->get_HotSpotCompiledCode_sites(compiled_code);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   674
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   675
  _code_handle = jvmci_env()->get_HotSpotCompiledCode_targetCode(compiled_code);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   676
  _code_size = jvmci_env()->get_HotSpotCompiledCode_targetCodeSize(compiled_code);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   677
  _total_frame_size = jvmci_env()->get_HotSpotCompiledCode_totalFrameSize(compiled_code);
35823
59a847ec6ee3 8146608: [JVMCI] DebugInfo Tests on DeoptimizeALot runs fails in assert(_pc == *pc_addr || pc == *pc_addr) frame::patch_pc() /frame_x86.cpp:285
rschatz
parents: 35582
diff changeset
   678
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   679
  JVMCIObject deoptRescueSlot = jvmci_env()->get_HotSpotCompiledCode_deoptRescueSlot(compiled_code);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   680
  if (deoptRescueSlot.is_null()) {
35823
59a847ec6ee3 8146608: [JVMCI] DebugInfo Tests on DeoptimizeALot runs fails in assert(_pc == *pc_addr || pc == *pc_addr) frame::patch_pc() /frame_x86.cpp:285
rschatz
parents: 35582
diff changeset
   681
    _orig_pc_offset = -1;
59a847ec6ee3 8146608: [JVMCI] DebugInfo Tests on DeoptimizeALot runs fails in assert(_pc == *pc_addr || pc == *pc_addr) frame::patch_pc() /frame_x86.cpp:285
rschatz
parents: 35582
diff changeset
   682
  } else {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   683
    _orig_pc_offset = jvmci_env()->get_StackSlot_offset(deoptRescueSlot);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   684
    if (jvmci_env()->get_StackSlot_addFrameSize(deoptRescueSlot)) {
35823
59a847ec6ee3 8146608: [JVMCI] DebugInfo Tests on DeoptimizeALot runs fails in assert(_pc == *pc_addr || pc == *pc_addr) frame::patch_pc() /frame_x86.cpp:285
rschatz
parents: 35582
diff changeset
   685
      _orig_pc_offset += _total_frame_size;
59a847ec6ee3 8146608: [JVMCI] DebugInfo Tests on DeoptimizeALot runs fails in assert(_pc == *pc_addr || pc == *pc_addr) frame::patch_pc() /frame_x86.cpp:285
rschatz
parents: 35582
diff changeset
   686
    }
59a847ec6ee3 8146608: [JVMCI] DebugInfo Tests on DeoptimizeALot runs fails in assert(_pc == *pc_addr || pc == *pc_addr) frame::patch_pc() /frame_x86.cpp:285
rschatz
parents: 35582
diff changeset
   687
    if (_orig_pc_offset < 0) {
59a847ec6ee3 8146608: [JVMCI] DebugInfo Tests on DeoptimizeALot runs fails in assert(_pc == *pc_addr || pc == *pc_addr) frame::patch_pc() /frame_x86.cpp:285
rschatz
parents: 35582
diff changeset
   688
      JVMCI_ERROR("invalid deopt rescue slot: %d", _orig_pc_offset);
59a847ec6ee3 8146608: [JVMCI] DebugInfo Tests on DeoptimizeALot runs fails in assert(_pc == *pc_addr || pc == *pc_addr) frame::patch_pc() /frame_x86.cpp:285
rschatz
parents: 35582
diff changeset
   689
    }
59a847ec6ee3 8146608: [JVMCI] DebugInfo Tests on DeoptimizeALot runs fails in assert(_pc == *pc_addr || pc == *pc_addr) frame::patch_pc() /frame_x86.cpp:285
rschatz
parents: 35582
diff changeset
   690
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   691
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   692
  // Pre-calculate the constants section size.  This is required for PC-relative addressing.
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   693
  _data_section_handle = jvmci_env()->get_HotSpotCompiledCode_dataSection(compiled_code);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   694
  if ((_constants->alignment() % jvmci_env()->get_HotSpotCompiledCode_dataSectionAlignment(compiled_code)) != 0) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   695
    JVMCI_ERROR("invalid data section alignment: %d", jvmci_env()->get_HotSpotCompiledCode_dataSectionAlignment(compiled_code));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   696
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   697
  _constants_size = JVMCIENV->get_length(data_section());
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   698
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   699
  _data_section_patches_handle = jvmci_env()->get_HotSpotCompiledCode_dataSectionPatches(compiled_code);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   700
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   701
#ifndef PRODUCT
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   702
  _comments_handle = jvmci_env()->get_HotSpotCompiledCode_comments(compiled_code);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   703
#endif
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   704
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   705
  _next_call_type = INVOKE_INVALID;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   706
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   707
  _has_wide_vector = false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   708
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   709
  JVMCIObject arch = jvmci_env()->get_TargetDescription_arch(target);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   710
  _word_kind_handle = jvmci_env()->get_Architecture_wordKind(arch);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   711
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   712
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   713
int CodeInstaller::estimate_stubs_size(JVMCI_TRAPS) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   714
  // Estimate the number of static and aot call stubs that might be emitted.
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   715
  int static_call_stubs = 0;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   716
  int aot_call_stubs = 0;
48487
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   717
  int trampoline_stubs = 0;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   718
  JVMCIObjectArray sites = this->sites();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   719
  for (int i = 0; i < JVMCIENV->get_length(sites); i++) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   720
    JVMCIObject site = JVMCIENV->get_object_at(sites, i);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   721
    if (!site.is_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   722
      if (jvmci_env()->isa_site_Mark(site)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   723
        JVMCIObject id_obj = jvmci_env()->get_site_Mark_id(site);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   724
        if (id_obj.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   725
          if (!jvmci_env()->is_boxing_object(T_INT, id_obj)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   726
            JVMCI_ERROR_0("expected Integer id, got %s", jvmci_env()->klass_name(id_obj));
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   727
          }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   728
          jint id = jvmci_env()->get_boxed_value(T_INT, id_obj).i;
48487
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   729
          switch (id) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   730
            case INVOKEINTERFACE:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   731
            case INVOKEVIRTUAL:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   732
              trampoline_stubs++;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   733
              break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   734
            case INVOKESTATIC:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   735
            case INVOKESPECIAL:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   736
              static_call_stubs++;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   737
              trampoline_stubs++;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   738
              break;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   739
            default:
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   740
              break;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   741
          }
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   742
        }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   743
      }
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
   744
#if INCLUDE_AOT
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   745
      if (UseAOT && jvmci_env()->isa_site_Call(site)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   746
        JVMCIObject target = jvmci_env()-> get_site_Call_target(site);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   747
        if (!jvmci_env()->isa_HotSpotForeignCallTarget(target)) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   748
          // Add far aot trampolines.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   749
          aot_call_stubs++;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   750
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   751
      }
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
   752
#endif
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   753
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   754
  }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   755
  int size = static_call_stubs * CompiledStaticCall::to_interp_stub_size();
48487
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   756
  size += trampoline_stubs * CompiledStaticCall::to_trampoline_stub_size();
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   757
#if INCLUDE_AOT
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   758
  size += aot_call_stubs * CompiledStaticCall::to_aot_stub_size();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   759
#endif
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   760
  return size;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   761
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   762
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   763
// perform data and call relocation on the CodeBuffer
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   764
JVMCI::CodeInstallResult CodeInstaller::initialize_buffer(CodeBuffer& buffer, bool check_size, JVMCI_TRAPS) {
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   765
  HandleMark hm;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   766
  JVMCIObjectArray sites = this->sites();
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   767
  int locs_buffer_size = JVMCIENV->get_length(sites) * (relocInfo::length_limit + sizeof(relocInfo));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   768
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   769
  // Allocate enough space in the stub section for the static call
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   770
  // stubs.  Stubs have extra relocs but they are managed by the stub
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   771
  // section itself so they don't need to be accounted for in the
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   772
  // locs_buffer above.
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   773
  int stubs_size = estimate_stubs_size(JVMCI_CHECK_OK);
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46479
diff changeset
   774
  int total_size = align_up(_code_size, buffer.insts()->alignment()) + align_up(_constants_size, buffer.consts()->alignment()) + align_up(stubs_size, buffer.stubs()->alignment());
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   775
43416
f8c241512446 8171082: [AOT] AOT'd SystemModules.modules() fails to load when too large
rbackman
parents: 42861
diff changeset
   776
  if (check_size && total_size > JVMCINMethodSizeLimit) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   777
    return JVMCI::code_too_large;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   778
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   779
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   780
  buffer.initialize(total_size, locs_buffer_size);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   781
  if (buffer.blob() == NULL) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   782
    return JVMCI::cache_full;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   783
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   784
  buffer.initialize_stubs_size(stubs_size);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   785
  buffer.initialize_consts_size(_constants_size);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   786
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   787
  _debug_recorder = new DebugInformationRecorder(_oop_recorder);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   788
  _debug_recorder->set_oopmaps(new OopMapSet());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   789
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   790
  buffer.initialize_oop_recorder(_oop_recorder);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   791
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   792
  // copy the constant data into the newly created CodeBuffer
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   793
  address end_data = _constants->start() + _constants_size;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   794
  JVMCIENV->copy_bytes_to(data_section(), (jbyte*) _constants->start(), 0, _constants_size);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   795
  _constants->set_end(end_data);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   796
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   797
  // copy the code into the newly created CodeBuffer
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   798
  address end_pc = _instructions->start() + _code_size;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   799
  guarantee(_instructions->allocates2(end_pc), "initialize should have reserved enough space for all the code");
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   800
  JVMCIENV->copy_bytes_to(code(), (jbyte*) _instructions->start(), 0, _code_size);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   801
  _instructions->set_end(end_pc);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   802
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   803
  for (int i = 0; i < JVMCIENV->get_length(data_section_patches()); i++) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   804
    // HandleMark hm(THREAD);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   805
    JVMCIObject patch = JVMCIENV->get_object_at(data_section_patches(), i);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   806
    if (patch.is_null()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   807
      JVMCI_THROW_(NullPointerException, JVMCI::ok);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   808
    }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   809
    JVMCIObject reference = jvmci_env()->get_site_DataPatch_reference(patch);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   810
    if (reference.is_null()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   811
      JVMCI_THROW_(NullPointerException, JVMCI::ok);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   812
    }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   813
    if (!jvmci_env()->isa_site_ConstantReference(reference)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   814
      JVMCI_ERROR_OK("invalid patch in data section: %s", jvmci_env()->klass_name(reference));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   815
    }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   816
    JVMCIObject constant = jvmci_env()->get_site_ConstantReference_constant(reference);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   817
    if (constant.is_null()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   818
      JVMCI_THROW_(NullPointerException, JVMCI::ok);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   819
    }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   820
    address dest = _constants->start() + jvmci_env()->get_site_Site_pcOffset(patch);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   821
    if (jvmci_env()->isa_HotSpotMetaspaceConstantImpl(constant)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   822
      if (jvmci_env()->get_HotSpotMetaspaceConstantImpl_compressed(constant)) {
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   823
#ifdef _LP64
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   824
        *((narrowKlass*) dest) = record_narrow_metadata_reference(_constants, dest, constant, JVMCI_CHECK_OK);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   825
#else
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   826
        JVMCI_ERROR_OK("unexpected compressed Klass* in 32-bit mode");
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   827
#endif
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   828
      } else {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   829
        *((void**) dest) = record_metadata_reference(_constants, dest, constant, JVMCI_CHECK_OK);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   830
      }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   831
    } else if (jvmci_env()->isa_HotSpotObjectConstantImpl(constant)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   832
      Handle obj = jvmci_env()->asConstant(constant, JVMCI_CHECK_OK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   833
      jobject value = JNIHandles::make_local(obj());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   834
      int oop_index = _oop_recorder->find_index(value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   835
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   836
      if (jvmci_env()->get_HotSpotObjectConstantImpl_compressed(constant)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   837
#ifdef _LP64
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   838
        _constants->relocate(dest, oop_Relocation::spec(oop_index), relocInfo::narrow_oop_in_const);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   839
#else
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   840
        JVMCI_ERROR_OK("unexpected compressed oop in 32-bit mode");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   841
#endif
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   842
      } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   843
        _constants->relocate(dest, oop_Relocation::spec(oop_index));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   844
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   845
    } else {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   846
      JVMCI_ERROR_OK("invalid constant in data section: %s", jvmci_env()->klass_name(constant));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   847
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   848
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   849
  jint last_pc_offset = -1;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   850
  for (int i = 0; i < JVMCIENV->get_length(sites); i++) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   851
    // HandleMark hm(THREAD);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   852
    JVMCIObject site = JVMCIENV->get_object_at(sites, i);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   853
    if (site.is_null()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   854
      JVMCI_THROW_(NullPointerException, JVMCI::ok);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   855
    }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   856
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   857
    jint pc_offset = jvmci_env()->get_site_Site_pcOffset(site);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   858
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   859
    if (jvmci_env()->isa_site_Call(site)) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   860
      TRACE_jvmci_4("call at %i", pc_offset);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   861
      site_Call(buffer, pc_offset, site, JVMCI_CHECK_OK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   862
    } else if (jvmci_env()->isa_site_Infopoint(site)) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   863
      // three reasons for infopoints denote actual safepoints
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   864
      JVMCIObject reason = jvmci_env()->get_site_Infopoint_reason(site);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   865
      if (JVMCIENV->equals(reason, jvmci_env()->get_site_InfopointReason_SAFEPOINT()) ||
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   866
          JVMCIENV->equals(reason, jvmci_env()->get_site_InfopointReason_CALL()) ||
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   867
          JVMCIENV->equals(reason, jvmci_env()->get_site_InfopointReason_IMPLICIT_EXCEPTION())) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   868
        TRACE_jvmci_4("safepoint at %i", pc_offset);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   869
        site_Safepoint(buffer, pc_offset, site, JVMCI_CHECK_OK);
35823
59a847ec6ee3 8146608: [JVMCI] DebugInfo Tests on DeoptimizeALot runs fails in assert(_pc == *pc_addr || pc == *pc_addr) frame::patch_pc() /frame_x86.cpp:285
rschatz
parents: 35582
diff changeset
   870
        if (_orig_pc_offset < 0) {
35827
24e567453a33 8149105: typo in jvmciCodeInstaller.cpp
rschatz
parents: 35823
diff changeset
   871
          JVMCI_ERROR_OK("method contains safepoint, but has no deopt rescue slot");
35823
59a847ec6ee3 8146608: [JVMCI] DebugInfo Tests on DeoptimizeALot runs fails in assert(_pc == *pc_addr || pc == *pc_addr) frame::patch_pc() /frame_x86.cpp:285
rschatz
parents: 35582
diff changeset
   872
        }
55293
d19dc5b10fbb 8209626: [JVMCI] Use implicit exception table for dispatch and printing
never
parents: 55159
diff changeset
   873
        if (JVMCIENV->equals(reason, jvmci_env()->get_site_InfopointReason_IMPLICIT_EXCEPTION())) {
d19dc5b10fbb 8209626: [JVMCI] Use implicit exception table for dispatch and printing
never
parents: 55159
diff changeset
   874
          TRACE_jvmci_4("implicit exception at %i", pc_offset);
d19dc5b10fbb 8209626: [JVMCI] Use implicit exception table for dispatch and printing
never
parents: 55159
diff changeset
   875
          _implicit_exception_table.add_deoptimize(pc_offset);
d19dc5b10fbb 8209626: [JVMCI] Use implicit exception table for dispatch and printing
never
parents: 55159
diff changeset
   876
        }
34502
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
   877
      } else {
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
   878
        TRACE_jvmci_4("infopoint at %i", pc_offset);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   879
        site_Infopoint(buffer, pc_offset, site, JVMCI_CHECK_OK);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   880
      }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   881
    } else if (jvmci_env()->isa_site_DataPatch(site)) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   882
      TRACE_jvmci_4("datapatch at %i", pc_offset);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   883
      site_DataPatch(buffer, pc_offset, site, JVMCI_CHECK_OK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   884
    } else if (jvmci_env()->isa_site_Mark(site)) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   885
      TRACE_jvmci_4("mark at %i", pc_offset);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   886
      site_Mark(buffer, pc_offset, site, JVMCI_CHECK_OK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   887
    } else if (jvmci_env()->isa_site_ExceptionHandler(site)) {
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   888
      TRACE_jvmci_4("exceptionhandler at %i", pc_offset);
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   889
      site_ExceptionHandler(pc_offset, site);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   890
    } else {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   891
      JVMCI_ERROR_OK("unexpected site subclass: %s", jvmci_env()->klass_name(site));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   892
    }
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   893
    last_pc_offset = pc_offset;
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   894
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47765
diff changeset
   895
    JavaThread* thread = JavaThread::current();
52450
2790da836dc3 8211403: Rename SafepointMechanism::poll(...)
rehn
parents: 52381
diff changeset
   896
    if (SafepointMechanism::should_block(thread)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   897
      // this is a hacky way to force a safepoint check but nothing else was jumping out at me.
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47765
diff changeset
   898
      ThreadToNativeFromVM ttnfv(thread);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   899
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   900
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   901
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   902
#ifndef PRODUCT
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   903
  if (comments().is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   904
    for (int i = 0; i < JVMCIENV->get_length(comments()); i++) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   905
      JVMCIObject comment = JVMCIENV->get_object_at(comments(), i);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   906
      assert(jvmci_env()->isa_HotSpotCompiledCode_Comment(comment), "cce");
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   907
      jint offset = jvmci_env()->get_HotSpotCompiledCode_Comment_pcOffset(comment);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   908
      const char* text = jvmci_env()->as_utf8_string(jvmci_env()->get_HotSpotCompiledCode_Comment_text(comment));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   909
      buffer.block_comment(offset, text);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   910
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   911
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   912
#endif
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   913
  return JVMCI::ok;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   914
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   915
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   916
void CodeInstaller::assumption_NoFinalizableSubclass(JVMCIObject assumption) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   917
  JVMCIObject receiverType_handle = jvmci_env()->get_Assumptions_NoFinalizableSubclass_receiverType(assumption);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   918
  Klass* receiverType = jvmci_env()->asKlass(receiverType_handle);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   919
  _dependencies->assert_has_no_finalizable_subclasses(receiverType);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   920
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   921
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   922
void CodeInstaller::assumption_ConcreteSubtype(JVMCIObject assumption) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   923
  JVMCIObject context_handle = jvmci_env()->get_Assumptions_ConcreteSubtype_context(assumption);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   924
  JVMCIObject subtype_handle = jvmci_env()->get_Assumptions_ConcreteSubtype_subtype(assumption);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   925
  Klass* context = jvmci_env()->asKlass(context_handle);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   926
  Klass* subtype = jvmci_env()->asKlass(subtype_handle);
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
  assert(context->is_abstract(), "");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   929
  _dependencies->assert_abstract_with_unique_concrete_subtype(context, subtype);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   930
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   931
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   932
void CodeInstaller::assumption_LeafType(JVMCIObject assumption) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   933
  JVMCIObject context_handle = jvmci_env()->get_Assumptions_LeafType_context(assumption);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   934
  Klass* context = jvmci_env()->asKlass(context_handle);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   935
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   936
  _dependencies->assert_leaf_type(context);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   937
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   938
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   939
void CodeInstaller::assumption_ConcreteMethod(JVMCIObject assumption) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   940
  JVMCIObject impl_handle = jvmci_env()->get_Assumptions_ConcreteMethod_impl(assumption);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   941
  JVMCIObject context_handle = jvmci_env()->get_Assumptions_ConcreteMethod_context(assumption);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   942
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
   943
  Method* impl = jvmci_env()->asMethod(impl_handle);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   944
  Klass* context = jvmci_env()->asKlass(context_handle);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   945
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
   946
  _dependencies->assert_unique_concrete_method(context, impl);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   947
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   948
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   949
void CodeInstaller::assumption_CallSiteTargetValue(JVMCIObject assumption, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   950
  JVMCIObject callSiteConstant = jvmci_env()->get_Assumptions_CallSiteTargetValue_callSite(assumption);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   951
  Handle callSite = jvmci_env()->asConstant(callSiteConstant, JVMCI_CHECK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   952
  JVMCIObject methodConstant = jvmci_env()->get_Assumptions_CallSiteTargetValue_methodHandle(assumption);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   953
  Handle methodHandle = jvmci_env()->asConstant(methodConstant, JVMCI_CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   954
  _dependencies->assert_call_site_target_value(callSite(), methodHandle());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   955
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   956
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   957
void CodeInstaller::site_ExceptionHandler(jint pc_offset, JVMCIObject exc) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   958
  jint handler_offset = jvmci_env()->get_site_ExceptionHandler_handlerPos(exc);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   959
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   960
  // Subtable header
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   961
  _exception_handler_table.add_entry(HandlerTableEntry(1, pc_offset, 0));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   962
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   963
  // Subtable entry
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   964
  _exception_handler_table.add_entry(HandlerTableEntry(-1, handler_offset, 0));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   965
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   966
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   967
// If deoptimization happens, the interpreter should reexecute these bytecodes.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   968
// This function mainly helps the compilers to set up the reexecute bit.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   969
static bool bytecode_should_reexecute(Bytecodes::Code code) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   970
  switch (code) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   971
    case Bytecodes::_invokedynamic:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   972
    case Bytecodes::_invokevirtual:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   973
    case Bytecodes::_invokeinterface:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   974
    case Bytecodes::_invokespecial:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   975
    case Bytecodes::_invokestatic:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   976
      return false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   977
    default:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   978
      return true;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   979
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   980
  return true;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   981
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   982
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   983
GrowableArray<ScopeValue*>* CodeInstaller::record_virtual_objects(JVMCIObject debug_info, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   984
  JVMCIObjectArray virtualObjects = jvmci_env()->get_DebugInfo_virtualObjectMapping(debug_info);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   985
  if (virtualObjects.is_null()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   986
    return NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   987
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   988
  GrowableArray<ScopeValue*>* objects = new GrowableArray<ScopeValue*>(JVMCIENV->get_length(virtualObjects), JVMCIENV->get_length(virtualObjects), NULL);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   989
  // Create the unique ObjectValues
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   990
  for (int i = 0; i < JVMCIENV->get_length(virtualObjects); i++) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   991
    // HandleMark hm(THREAD);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   992
    JVMCIObject value = JVMCIENV->get_object_at(virtualObjects, i);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   993
    int id = jvmci_env()->get_VirtualObject_id(value);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   994
    JVMCIObject type = jvmci_env()->get_VirtualObject_type(value);
55159
a38132298eda 8223320: [AOT] jck test api/javax_script/ScriptEngine/PutGet.html fails when test classes are AOTed
iveresov
parents: 54786
diff changeset
   995
    bool is_auto_box = jvmci_env()->get_VirtualObject_isAutoBox(value);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   996
    Klass* klass = jvmci_env()->asKlass(type);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
   997
    oop javaMirror = klass->java_mirror();
55159
a38132298eda 8223320: [AOT] jck test api/javax_script/ScriptEngine/PutGet.html fails when test classes are AOTed
iveresov
parents: 54786
diff changeset
   998
    ScopeValue *klass_sv = new ConstantOopWriteValue(JNIHandles::make_local(Thread::current(), javaMirror));
a38132298eda 8223320: [AOT] jck test api/javax_script/ScriptEngine/PutGet.html fails when test classes are AOTed
iveresov
parents: 54786
diff changeset
   999
    ObjectValue* sv = is_auto_box ? new AutoBoxObjectValue(id, klass_sv) : new ObjectValue(id, klass_sv);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1000
    if (id < 0 || id >= objects->length()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1001
      JVMCI_ERROR_NULL("virtual object id %d out of bounds", id);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1002
    }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1003
    if (objects->at(id) != NULL) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1004
      JVMCI_ERROR_NULL("duplicate virtual object id %d", id);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1005
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1006
    objects->at_put(id, sv);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1007
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1008
  // All the values which could be referenced by the VirtualObjects
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1009
  // exist, so now describe all the VirtualObjects themselves.
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1010
  for (int i = 0; i < JVMCIENV->get_length(virtualObjects); i++) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1011
    // HandleMark hm(THREAD);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1012
    JVMCIObject value = JVMCIENV->get_object_at(virtualObjects, i);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1013
    int id = jvmci_env()->get_VirtualObject_id(value);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1014
    record_object_value(objects->at(id)->as_ObjectValue(), value, objects, JVMCI_CHECK_NULL);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1015
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1016
  _debug_recorder->dump_object_pool(objects);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1017
  return objects;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1018
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1019
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1020
void CodeInstaller::record_scope(jint pc_offset, JVMCIObject debug_info, ScopeMode scope_mode, bool return_oop, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1021
  JVMCIObject position = jvmci_env()->get_DebugInfo_bytecodePosition(debug_info);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1022
  if (position.is_null()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1023
    // Stubs do not record scope info, just oop maps
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1024
    return;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1025
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1026
34502
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1027
  GrowableArray<ScopeValue*>* objectMapping;
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1028
  if (scope_mode == CodeInstaller::FullFrame) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1029
    objectMapping = record_virtual_objects(debug_info, JVMCI_CHECK);
34502
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1030
  } else {
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1031
    objectMapping = NULL;
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1032
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1033
  record_scope(pc_offset, position, scope_mode, objectMapping, return_oop, JVMCI_CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1034
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1035
50729
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1036
int CodeInstaller::map_jvmci_bci(int bci) {
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1037
  if (bci < 0) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1038
    if (bci == jvmci_env()->get_BytecodeFrame_BEFORE_BCI()) {
50729
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1039
      return BeforeBci;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1040
    } else if (bci == jvmci_env()->get_BytecodeFrame_AFTER_BCI()) {
50729
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1041
      return AfterBci;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1042
    } else if (bci == jvmci_env()->get_BytecodeFrame_UNWIND_BCI()) {
50729
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1043
      return UnwindBci;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1044
    } else if (bci == jvmci_env()->get_BytecodeFrame_AFTER_EXCEPTION_BCI()) {
50729
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1045
      return AfterExceptionBci;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1046
    } else if (bci == jvmci_env()->get_BytecodeFrame_UNKNOWN_BCI()) {
50729
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1047
      return UnknownBci;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1048
    } else if (bci == jvmci_env()->get_BytecodeFrame_INVALID_FRAMESTATE_BCI()) {
50729
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1049
      return InvalidFrameStateBci;
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1050
    }
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1051
    ShouldNotReachHere();
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1052
  }
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1053
  return bci;
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1054
}
7755c93d3923 8204209: [Graal] Compilation fails during nmethod printing with "assert(bci == 0 || 0 <= bci && bci < code_size()) failed: illegal bci"
iveresov
parents: 50104
diff changeset
  1055
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1056
void CodeInstaller::record_scope(jint pc_offset, JVMCIObject position, ScopeMode scope_mode, GrowableArray<ScopeValue*>* objects, bool return_oop, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1057
  JVMCIObject frame;
34502
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1058
  if (scope_mode == CodeInstaller::FullFrame) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1059
    if (!jvmci_env()->isa_BytecodeFrame(position)) {
34502
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1060
      JVMCI_ERROR("Full frame expected for debug info at %i", pc_offset);
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1061
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1062
    frame = position;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1063
  }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1064
  JVMCIObject caller_frame = jvmci_env()->get_BytecodePosition_caller(position);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1065
  if (caller_frame.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1066
    record_scope(pc_offset, caller_frame, scope_mode, objects, return_oop, JVMCI_CHECK);
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
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1069
  JVMCIObject hotspot_method = jvmci_env()->get_BytecodePosition_method(position);
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
  1070
  Thread* thread = Thread::current();
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
  1071
  methodHandle method(thread, jvmci_env()->asMethod(hotspot_method));
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1072
  jint bci = map_jvmci_bci(jvmci_env()->get_BytecodePosition_bci(position));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1073
  if (bci == jvmci_env()->get_BytecodeFrame_BEFORE_BCI()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1074
    bci = SynchronizationEntryBCI;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1075
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1076
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1077
  TRACE_jvmci_2("Recording scope pc_offset=%d bci=%d method=%s", pc_offset, bci, method->name_and_sig_as_C_string());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1078
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1079
  bool reexecute = false;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1080
  if (frame.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1081
    if (bci < 0){
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1082
       reexecute = false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1083
    } else {
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58563
diff changeset
  1084
      Bytecodes::Code code = Bytecodes::java_code_at(method(), method->bcp_from(bci));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1085
      reexecute = bytecode_should_reexecute(code);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1086
      if (frame.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1087
        reexecute = (jvmci_env()->get_BytecodeFrame_duringCall(frame) == JNI_FALSE);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1088
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1089
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1090
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1091
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1092
  DebugToken* locals_token = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1093
  DebugToken* expressions_token = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1094
  DebugToken* monitors_token = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1095
  bool throw_exception = false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1096
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1097
  if (frame.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1098
    jint local_count = jvmci_env()->get_BytecodeFrame_numLocals(frame);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1099
    jint expression_count = jvmci_env()->get_BytecodeFrame_numStack(frame);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1100
    jint monitor_count = jvmci_env()->get_BytecodeFrame_numLocks(frame);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1101
    JVMCIObjectArray values = jvmci_env()->get_BytecodeFrame_values(frame);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1102
    JVMCIObjectArray slotKinds = jvmci_env()->get_BytecodeFrame_slotKinds(frame);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1103
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1104
    if (values.is_null() || slotKinds.is_null()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1105
      JVMCI_THROW(NullPointerException);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1106
    }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1107
    if (local_count + expression_count + monitor_count != JVMCIENV->get_length(values)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1108
      JVMCI_ERROR("unexpected values length %d in scope (%d locals, %d expressions, %d monitors)", JVMCIENV->get_length(values), local_count, expression_count, monitor_count);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1109
    }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1110
    if (local_count + expression_count != JVMCIENV->get_length(slotKinds)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1111
      JVMCI_ERROR("unexpected slotKinds length %d in scope (%d locals, %d expressions)", JVMCIENV->get_length(slotKinds), local_count, expression_count);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1112
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1113
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1114
    GrowableArray<ScopeValue*>* locals = local_count > 0 ? new GrowableArray<ScopeValue*> (local_count) : NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1115
    GrowableArray<ScopeValue*>* expressions = expression_count > 0 ? new GrowableArray<ScopeValue*> (expression_count) : NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1116
    GrowableArray<MonitorValue*>* monitors = monitor_count > 0 ? new GrowableArray<MonitorValue*> (monitor_count) : NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1117
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1118
    TRACE_jvmci_2("Scope at bci %d with %d values", bci, JVMCIENV->get_length(values));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1119
    TRACE_jvmci_2("%d locals %d expressions, %d monitors", local_count, expression_count, monitor_count);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1120
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1121
    for (jint i = 0; i < JVMCIENV->get_length(values); i++) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1122
      // HandleMark hm(THREAD);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1123
      ScopeValue* second = NULL;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1124
      JVMCIObject value = JVMCIENV->get_object_at(values, i);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1125
      if (i < local_count) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1126
        BasicType type = jvmci_env()->kindToBasicType(JVMCIENV->get_object_at(slotKinds, i), JVMCI_CHECK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1127
        ScopeValue* first = get_scope_value(value, type, objects, second, JVMCI_CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1128
        if (second != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1129
          locals->append(second);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1130
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1131
        locals->append(first);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1132
      } else if (i < local_count + expression_count) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1133
        BasicType type = jvmci_env()->kindToBasicType(JVMCIENV->get_object_at(slotKinds, i), JVMCI_CHECK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1134
        ScopeValue* first = get_scope_value(value, type, objects, second, JVMCI_CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1135
        if (second != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1136
          expressions->append(second);
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
        expressions->append(first);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1139
      } else {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1140
        MonitorValue *monitor = get_monitor_value(value, objects, JVMCI_CHECK);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1141
        monitors->append(monitor);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1142
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1143
      if (second != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1144
        i++;
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1145
        if (i >= JVMCIENV->get_length(values) || !JVMCIENV->equals(JVMCIENV->get_object_at(values, i), jvmci_env()->get_Value_ILLEGAL())) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1146
          JVMCI_ERROR("double-slot value not followed by Value.ILLEGAL");
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1147
        }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1148
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1149
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1150
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1151
    locals_token = _debug_recorder->create_scope_values(locals);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1152
    expressions_token = _debug_recorder->create_scope_values(expressions);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1153
    monitors_token = _debug_recorder->create_monitor_values(monitors);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1154
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1155
    throw_exception = jvmci_env()->get_BytecodeFrame_rethrowException(frame) == JNI_TRUE;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1156
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1157
42861
1d4dfdf4390b 8169938: [AOT] SIGSEGV at ~BufferBlob::vtable chunks
dlong
parents: 42650
diff changeset
  1158
  _debug_recorder->describe_scope(pc_offset, method, NULL, bci, reexecute, throw_exception, false, return_oop,
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1159
                                  locals_token, expressions_token, monitors_token);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1160
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1161
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1162
void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, JVMCIObject site, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1163
  JVMCIObject debug_info = jvmci_env()->get_site_Infopoint_debugInfo(site);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1164
  if (debug_info.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1165
    JVMCI_ERROR("debug info expected at safepoint at %i", pc_offset);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1166
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1167
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1168
  // address instruction = _instructions->start() + pc_offset;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1169
  // jint next_pc_offset = Assembler::locate_next_instruction(instruction) - _instructions->start();
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1170
  OopMap *map = create_oop_map(debug_info, JVMCI_CHECK);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1171
  _debug_recorder->add_safepoint(pc_offset, map);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1172
  record_scope(pc_offset, debug_info, CodeInstaller::FullFrame, JVMCI_CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1173
  _debug_recorder->end_safepoint(pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1174
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1175
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1176
void CodeInstaller::site_Infopoint(CodeBuffer& buffer, jint pc_offset, JVMCIObject site, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1177
  JVMCIObject debug_info = jvmci_env()->get_site_Infopoint_debugInfo(site);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1178
  if (debug_info.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1179
    JVMCI_ERROR("debug info expected at infopoint at %i", pc_offset);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1180
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1181
34502
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1182
  // We'd like to check that pc_offset is greater than the
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1183
  // last pc recorded with _debug_recorder (raising an exception if not)
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1184
  // but DebugInformationRecorder doesn't have sufficient public API.
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1185
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1186
  _debug_recorder->add_non_safepoint(pc_offset);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1187
  record_scope(pc_offset, debug_info, CodeInstaller::BytecodePosition, JVMCI_CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1188
  _debug_recorder->end_non_safepoint(pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1189
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1190
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1191
void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, JVMCIObject site, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1192
  JVMCIObject target = jvmci_env()->get_site_Call_target(site);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1193
  JVMCIObject hotspot_method; // JavaMethod
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1194
  JVMCIObject foreign_call;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1195
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1196
  if (jvmci_env()->isa_HotSpotForeignCallTarget(target)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1197
    foreign_call = target;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1198
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1199
    hotspot_method = target;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1200
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1201
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1202
  JVMCIObject debug_info = jvmci_env()->get_site_Infopoint_debugInfo(site);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1203
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1204
  assert(hotspot_method.is_non_null() ^ foreign_call.is_non_null(), "Call site needs exactly one type");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1205
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1206
  NativeInstruction* inst = nativeInstruction_at(_instructions->start() + pc_offset);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1207
  jint next_pc_offset = CodeInstaller::pd_next_offset(inst, pc_offset, hotspot_method, JVMCI_CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1208
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1209
  if (debug_info.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1210
    OopMap *map = create_oop_map(debug_info, JVMCI_CHECK);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1211
    _debug_recorder->add_safepoint(next_pc_offset, map);
42861
1d4dfdf4390b 8169938: [AOT] SIGSEGV at ~BufferBlob::vtable chunks
dlong
parents: 42650
diff changeset
  1212
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1213
    bool return_oop = hotspot_method.is_non_null() && jvmci_env()->asMethod(hotspot_method)->is_returning_oop();
42861
1d4dfdf4390b 8169938: [AOT] SIGSEGV at ~BufferBlob::vtable chunks
dlong
parents: 42650
diff changeset
  1214
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1215
    record_scope(next_pc_offset, debug_info, CodeInstaller::FullFrame, return_oop, JVMCI_CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1216
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1217
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1218
  if (foreign_call.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1219
    jlong foreign_call_destination = jvmci_env()->get_HotSpotForeignCallTarget_address(foreign_call);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1220
    if (_immutable_pic_compilation) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1221
      // Use fake short distance during PIC compilation.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1222
      foreign_call_destination = (jlong)(_instructions->start() + pc_offset);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1223
    }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1224
    CodeInstaller::pd_relocate_ForeignCall(inst, foreign_call_destination, JVMCI_CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1225
  } else { // method != NULL
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1226
    if (debug_info.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1227
      JVMCI_ERROR("debug info expected at call at %i", pc_offset);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1228
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1229
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1230
    TRACE_jvmci_3("method call");
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1231
    CodeInstaller::pd_relocate_JavaMethod(buffer, hotspot_method, pc_offset, JVMCI_CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1232
    if (_next_call_type == INVOKESTATIC || _next_call_type == INVOKESPECIAL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1233
      // Need a static call stub for transitions from compiled to interpreted.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1234
      CompiledStaticCall::emit_to_interp_stub(buffer, _instructions->start() + pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1235
    }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1236
#if INCLUDE_AOT
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1237
    // Trampoline to far aot code.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1238
    CompiledStaticCall::emit_to_aot_stub(buffer, _instructions->start() + pc_offset);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1239
#endif
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1240
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1241
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1242
  _next_call_type = INVOKE_INVALID;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1243
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1244
  if (debug_info.is_non_null()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1245
    _debug_recorder->end_safepoint(next_pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1246
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1247
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1248
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1249
void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, JVMCIObject site, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1250
  JVMCIObject reference = jvmci_env()->get_site_DataPatch_reference(site);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1251
  if (reference.is_null()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1252
    JVMCI_THROW(NullPointerException);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1253
  } else if (jvmci_env()->isa_site_ConstantReference(reference)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1254
    JVMCIObject constant = jvmci_env()->get_site_ConstantReference_constant(reference);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1255
    if (constant.is_null()) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1256
      JVMCI_THROW(NullPointerException);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1257
    } else if (jvmci_env()->isa_DirectHotSpotObjectConstantImpl(constant)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1258
      if (!JVMCIENV->is_hotspot()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1259
        JVMCIObject string = JVMCIENV->call_HotSpotJVMCIRuntime_callToString(constant, JVMCI_CHECK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1260
        const char* to_string = JVMCIENV->as_utf8_string(string);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1261
        JVMCI_THROW_MSG(IllegalArgumentException, err_msg("Direct object constant reached the backend: %s", to_string));
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1262
      }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1263
      if (!_immutable_pic_compilation) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1264
        // Do not patch during PIC compilation.
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1265
        pd_patch_OopConstant(pc_offset, constant, JVMCI_CHECK);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1266
      }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1267
    } else if (jvmci_env()->isa_IndirectHotSpotObjectConstantImpl(constant)) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1268
      if (!_immutable_pic_compilation) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1269
        // Do not patch during PIC compilation.
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1270
        pd_patch_OopConstant(pc_offset, constant, JVMCI_CHECK);
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1271
      }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1272
    } else if (jvmci_env()->isa_HotSpotMetaspaceConstantImpl(constant)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1273
      if (!_immutable_pic_compilation) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1274
        pd_patch_MetaspaceConstant(pc_offset, constant, JVMCI_CHECK);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1275
      }
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
  1276
#if INCLUDE_AOT
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1277
    } else if (jvmci_env()->isa_HotSpotSentinelConstant(constant)) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1278
      if (!_immutable_pic_compilation) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1279
        JVMCI_ERROR("sentinel constant not supported for normal compiles: %s", jvmci_env()->klass_name(constant));
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1280
      }
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
  1281
#endif
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1282
    } else {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1283
      JVMCI_ERROR("unknown constant type in data patch: %s", jvmci_env()->klass_name(constant));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1284
    }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1285
  } else if (jvmci_env()->isa_site_DataSectionReference(reference)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1286
    int data_offset = jvmci_env()->get_site_DataSectionReference_offset(reference);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1287
    if (0 <= data_offset && data_offset < _constants_size) {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1288
      pd_patch_DataSectionReference(pc_offset, data_offset, JVMCI_CHECK);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1289
    } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1290
      JVMCI_ERROR("data offset 0x%X points outside data section (size 0x%X)", data_offset, _constants_size);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1291
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1292
  } else {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1293
    JVMCI_ERROR("unknown data patch type: %s", jvmci_env()->klass_name(reference));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1294
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1295
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1296
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1297
void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, JVMCIObject site, JVMCI_TRAPS) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1298
  JVMCIObject id_obj = jvmci_env()->get_site_Mark_id(site);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1299
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1300
  if (id_obj.is_non_null()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1301
    if (!jvmci_env()->is_boxing_object(T_INT, id_obj)) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1302
      JVMCI_ERROR("expected Integer id, got %s", jvmci_env()->klass_name(id_obj));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1303
    }
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1304
    jint id = jvmci_env()->get_boxed_value(T_INT, id_obj).i;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1305
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1306
    address pc = _instructions->start() + pc_offset;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1307
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1308
    switch (id) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1309
      case UNVERIFIED_ENTRY:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1310
        _offsets.set_value(CodeOffsets::Entry, pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1311
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1312
      case VERIFIED_ENTRY:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1313
        _offsets.set_value(CodeOffsets::Verified_Entry, pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1314
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1315
      case OSR_ENTRY:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1316
        _offsets.set_value(CodeOffsets::OSR_Entry, pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1317
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1318
      case EXCEPTION_HANDLER_ENTRY:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1319
        _offsets.set_value(CodeOffsets::Exceptions, pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1320
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1321
      case DEOPT_HANDLER_ENTRY:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1322
        _offsets.set_value(CodeOffsets::Deopt, pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1323
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1324
      case INVOKEVIRTUAL:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1325
      case INVOKEINTERFACE:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1326
      case INLINE_INVOKE:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1327
      case INVOKESTATIC:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1328
      case INVOKESPECIAL:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1329
        _next_call_type = (MarkId) id;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1330
        _invoke_mark_pc = pc;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1331
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1332
      case POLL_NEAR:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1333
      case POLL_FAR:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1334
      case POLL_RETURN_NEAR:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1335
      case POLL_RETURN_FAR:
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53582
diff changeset
  1336
        pd_relocate_poll(pc, id, JVMCI_CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1337
        break;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
  1338
      case CARD_TABLE_SHIFT:
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1339
      case CARD_TABLE_ADDRESS:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1340
      case HEAP_TOP_ADDRESS:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1341
      case HEAP_END_ADDRESS:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1342
      case NARROW_KLASS_BASE_ADDRESS:
43435
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 43416
diff changeset
  1343
      case NARROW_OOP_BASE_ADDRESS:
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1344
      case CRC_TABLE_ADDRESS:
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1345
      case LOG_OF_HEAP_REGION_GRAIN_BYTES:
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1346
      case INLINE_CONTIGUOUS_ALLOCATION_SUPPORTED:
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1347
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1348
      default:
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1349
        JVMCI_ERROR("invalid mark id: %d", id);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1350
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1351
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1352
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1353
}