src/hotspot/share/jvmci/jvmciCodeInstaller.cpp
author rehn
Thu, 31 Jan 2019 10:31:39 +0100
changeset 53582 881c5fbeb849
parent 52450 2790da836dc3
child 54669 ad45b3802d4e
permissions -rw-r--r--
8218041: Assorted wrong/missing includes Reviewed-by: dholmes, kbarrett, stefank, shade
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"
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 39441
diff changeset
    25
#include "asm/register.hpp"
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 39441
diff changeset
    26
#include "classfile/vmSymbols.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    27
#include "code/compiledIC.hpp"
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 39441
diff changeset
    28
#include "code/vmreg.inline.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    29
#include "compiler/compileBroker.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    30
#include "compiler/disassembler.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    31
#include "jvmci/jvmciEnv.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    32
#include "jvmci/jvmciCompiler.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    33
#include "jvmci/jvmciCodeInstaller.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    34
#include "jvmci/jvmciJavaClasses.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    35
#include "jvmci/jvmciCompilerToVM.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    36
#include "jvmci/jvmciRuntime.hpp"
49360
886acec3b4c6 8199275: Fix inclusions of allocation.inline.hpp
stefank
parents: 49342
diff changeset
    37
#include "memory/allocation.inline.hpp"
49041
44122f767467 8198286: Direct memory accessors in typeArrayOop.hpp should use Access API
eosterlund
parents: 49036
diff changeset
    38
#include "oops/arrayOop.inline.hpp"
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 39441
diff changeset
    39
#include "oops/oop.inline.hpp"
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 39441
diff changeset
    40
#include "oops/objArrayOop.inline.hpp"
49036
bc92debe57e4 8197999: Accessors in typeArrayOopDesc should use new Access API
rkennke
parents: 48490
diff changeset
    41
#include "oops/typeArrayOop.inline.hpp"
53582
881c5fbeb849 8218041: Assorted wrong/missing includes
rehn
parents: 52450
diff changeset
    42
#include "runtime/handles.inline.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49360
diff changeset
    43
#include "runtime/interfaceSupport.inline.hpp"
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 39441
diff changeset
    44
#include "runtime/javaCalls.hpp"
49192
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
    45
#include "runtime/jniHandles.inline.hpp"
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47765
diff changeset
    46
#include "runtime/safepointMechanism.inline.hpp"
49593
4dd58ecc9912 8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents: 49592
diff changeset
    47
#include "runtime/sharedRuntime.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46620
diff changeset
    48
#include "utilities/align.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    49
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    50
// frequently used constants
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    51
// Allocate them with new so they are never destroyed (otherwise, a
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    52
// forced exit could destroy these objects while they are still in
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    53
// use).
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    54
ConstantOopWriteValue* CodeInstaller::_oop_null_scope_value = new (ResourceObj::C_HEAP, mtCompiler) ConstantOopWriteValue(NULL);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    55
ConstantIntValue*      CodeInstaller::_int_m1_scope_value = new (ResourceObj::C_HEAP, mtCompiler) ConstantIntValue(-1);
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47668
diff changeset
    56
ConstantIntValue*      CodeInstaller::_int_0_scope_value =  new (ResourceObj::C_HEAP, mtCompiler) ConstantIntValue((jint)0);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    57
ConstantIntValue*      CodeInstaller::_int_1_scope_value =  new (ResourceObj::C_HEAP, mtCompiler) ConstantIntValue(1);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    58
ConstantIntValue*      CodeInstaller::_int_2_scope_value =  new (ResourceObj::C_HEAP, mtCompiler) ConstantIntValue(2);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    59
LocationValue*         CodeInstaller::_illegal_value = new (ResourceObj::C_HEAP, mtCompiler) LocationValue(Location());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    60
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    61
Method* getMethodFromHotSpotMethod(oop hotspot_method) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    62
  assert(hotspot_method != NULL && hotspot_method->is_a(HotSpotResolvedJavaMethodImpl::klass()), "sanity");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    63
  return CompilerToVM::asMethod(hotspot_method);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    64
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    65
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    66
VMReg getVMRegFromLocation(Handle location, int total_frame_size, TRAPS) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    67
  if (location.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    68
    THROW_NULL(vmSymbols::java_lang_NullPointerException());
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    69
  }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    70
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
    71
  Handle reg(THREAD, code_Location::reg(location));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    72
  jint offset = code_Location::offset(location);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    73
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    74
  if (reg.not_null()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    75
    // register
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    76
    jint number = code_Register::number(reg);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    77
    VMReg vmReg = CodeInstaller::get_hotspot_reg(number, CHECK_NULL);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    78
    if (offset % 4 == 0) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    79
      return vmReg->next(offset / 4);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    80
    } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    81
      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
    82
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    83
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    84
    // stack slot
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    85
    if (offset % 4 == 0) {
39441
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    86
      VMReg vmReg = VMRegImpl::stack2reg(offset / 4);
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    87
      if (!OopMapValue::legal_vm_reg_name(vmReg)) {
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    88
        // 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
    89
        // 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
    90
        // 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
    91
        // 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
    92
        // 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
    93
        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
    94
        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
    95
                         offset, CompilerToVM::Data::max_oop_map_stack_offset());
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    96
      }
7464b1552bf7 8158850: [JVMCI] be more precise when enforcing OopMapValue encoding limitations
never
parents: 38695
diff changeset
    97
      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
    98
      return vmReg;
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
    99
    } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   100
      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
   101
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   102
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   103
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   104
49192
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   105
objArrayOop CodeInstaller::sites() {
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   106
  return (objArrayOop) JNIHandles::resolve(_sites_handle);
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   107
}
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   108
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   109
arrayOop CodeInstaller::code() {
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   110
  return (arrayOop) JNIHandles::resolve(_code_handle);
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   111
}
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   112
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   113
arrayOop CodeInstaller::data_section() {
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   114
  return (arrayOop) JNIHandles::resolve(_data_section_handle);
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   115
}
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   116
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   117
objArrayOop CodeInstaller::data_section_patches() {
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   118
  return (objArrayOop) JNIHandles::resolve(_data_section_patches_handle);
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   119
}
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   120
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   121
#ifndef PRODUCT
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   122
objArrayOop CodeInstaller::comments() {
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   123
  return (objArrayOop) JNIHandles::resolve(_comments_handle);
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   124
}
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   125
#endif
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   126
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   127
oop CodeInstaller::word_kind() {
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   128
  return JNIHandles::resolve(_word_kind_handle);
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   129
}
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
   130
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   131
// creates a HotSpot oop map out of the byte arrays provided by DebugInfo
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   132
OopMap* CodeInstaller::create_oop_map(Handle debug_info, TRAPS) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   133
  Handle reference_map(THREAD, DebugInfo::referenceMap(debug_info));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   134
  if (reference_map.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   135
    THROW_NULL(vmSymbols::java_lang_NullPointerException());
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   136
  }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   137
  if (!reference_map->is_a(HotSpotReferenceMap::klass())) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   138
    JVMCI_ERROR_NULL("unknown reference map: %s", reference_map->klass()->signature_name());
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   139
  }
49342
9597f957122e 8198571: [JVMCI] must not install wide vector code unless runtime supports it
dnsimon
parents: 49192
diff changeset
   140
  if (!_has_wide_vector && SharedRuntime::is_wide_vector(HotSpotReferenceMap::maxRegisterSize(reference_map))) {
9597f957122e 8198571: [JVMCI] must not install wide vector code unless runtime supports it
dnsimon
parents: 49192
diff changeset
   141
    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
   142
      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
   143
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   144
    _has_wide_vector = true;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   145
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   146
  OopMap* map = new OopMap(_total_frame_size, _parameter_count);
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   147
  objArrayHandle objects(THREAD, HotSpotReferenceMap::objects(reference_map));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   148
  objArrayHandle derivedBase(THREAD, HotSpotReferenceMap::derivedBase(reference_map));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   149
  typeArrayHandle sizeInBytes(THREAD, HotSpotReferenceMap::sizeInBytes(reference_map));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   150
  if (objects.is_null() || derivedBase.is_null() || sizeInBytes.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   151
    THROW_NULL(vmSymbols::java_lang_NullPointerException());
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   152
  }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   153
  if (objects->length() != derivedBase->length() || objects->length() != sizeInBytes->length()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   154
    JVMCI_ERROR_NULL("arrays in reference map have different sizes: %d %d %d", objects->length(), derivedBase->length(), sizeInBytes->length());
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   155
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   156
  for (int i = 0; i < objects->length(); i++) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   157
    Handle location(THREAD, objects->obj_at(i));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   158
    Handle baseLocation(THREAD, derivedBase->obj_at(i));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   159
    int bytes = sizeInBytes->int_at(i);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   160
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   161
    VMReg vmReg = getVMRegFromLocation(location, _total_frame_size, CHECK_NULL);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   162
    if (baseLocation.not_null()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   163
      // derived oop
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   164
#ifdef _LP64
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   165
      if (bytes == 8) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   166
#else
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   167
      if (bytes == 4) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   168
#endif
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   169
        VMReg baseReg = getVMRegFromLocation(baseLocation, _total_frame_size, CHECK_NULL);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   170
        map->set_derived_oop(vmReg, baseReg);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   171
      } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   172
        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
   173
      }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   174
#ifdef _LP64
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   175
    } else if (bytes == 8) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   176
      // wide oop
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   177
      map->set_oop(vmReg);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   178
    } else if (bytes == 4) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   179
      // narrow oop
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   180
      map->set_narrowoop(vmReg);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   181
#else
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   182
    } else if (bytes == 4) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   183
      map->set_oop(vmReg);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   184
#endif
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   185
    } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   186
      JVMCI_ERROR_NULL("invalid oop size in ReferenceMap: %d", bytes);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   187
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   188
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   189
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   190
  Handle callee_save_info(THREAD, (oop) DebugInfo::calleeSaveInfo(debug_info));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   191
  if (callee_save_info.not_null()) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   192
    objArrayHandle registers(THREAD, RegisterSaveLayout::registers(callee_save_info));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   193
    typeArrayHandle slots(THREAD, RegisterSaveLayout::slots(callee_save_info));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   194
    for (jint i = 0; i < slots->length(); i++) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   195
      Handle jvmci_reg (THREAD, registers->obj_at(i));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   196
      jint jvmci_reg_number = code_Register::number(jvmci_reg);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   197
      VMReg hotspot_reg = CodeInstaller::get_hotspot_reg(jvmci_reg_number, CHECK_NULL);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   198
      // HotSpot stack slots are 4 bytes
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   199
      jint jvmci_slot = slots->int_at(i);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   200
      jint hotspot_slot = jvmci_slot * VMRegImpl::slots_per_word;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   201
      VMReg hotspot_slot_as_reg = VMRegImpl::stack2reg(hotspot_slot);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   202
      map->set_callee_saved(hotspot_slot_as_reg, hotspot_reg);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   203
#ifdef _LP64
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   204
      // (copied from generate_oop_map() in c1_Runtime1_x86.cpp)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   205
      VMReg hotspot_slot_hi_as_reg = VMRegImpl::stack2reg(hotspot_slot + 1);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   206
      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
   207
#endif
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   208
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   209
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   210
  return map;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   211
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   212
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
   213
#if INCLUDE_AOT
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   214
AOTOopRecorder::AOTOopRecorder(Arena* arena, bool deduplicate) : OopRecorder(arena, deduplicate) {
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   215
  _meta_refs = new GrowableArray<jobject>();
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   216
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   217
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   218
int AOTOopRecorder::nr_meta_refs() const {
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   219
  return _meta_refs->length();
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   220
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   221
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   222
jobject AOTOopRecorder::meta_element(int pos) const {
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   223
  return _meta_refs->at(pos);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   224
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   225
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   226
int AOTOopRecorder::find_index(Metadata* h) {
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   227
  JavaThread* THREAD = JavaThread::current();
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   228
  int oldCount = metadata_count();
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   229
  int index =  this->OopRecorder::find_index(h);
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   230
  int newCount = metadata_count();
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   231
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   232
  if (oldCount == newCount) {
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   233
    // found a match
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   234
    return index;
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   235
  }
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   236
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   237
  vmassert(index + 1 == newCount, "must be last");
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   238
50746
85789fb05154 8198909: [Graal] compiler/codecache/stress/UnexpectedDeoptimizationTest.java crashed with SIGSEGV
never
parents: 50729
diff changeset
   239
  JVMCIKlassHandle klass(THREAD);
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   240
  oop result = NULL;
51078
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 50858
diff changeset
   241
  guarantee(h != NULL,
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 50858
diff changeset
   242
            "If DebugInformationRecorder::describe_scope passes NULL oldCount == newCount must hold.");
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   243
  if (h->is_klass()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   244
    klass = (Klass*) h;
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   245
    result = CompilerToVM::get_jvmci_type(klass, CATCH);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   246
  } else if (h->is_method()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   247
    Method* method = (Method*) h;
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   248
    methodHandle mh(method);
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   249
    result = CompilerToVM::get_jvmci_method(method, CATCH);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   250
  }
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   251
  jobject ref = JNIHandles::make_local(THREAD, result);
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   252
  record_meta_ref(ref, index);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   253
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   254
  return index;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   255
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   256
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   257
int AOTOopRecorder::find_index(jobject h) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   258
  if (h == NULL) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   259
    return 0;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   260
  }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   261
  oop javaMirror = JNIHandles::resolve(h);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   262
  Klass* klass = java_lang_Class::as_Klass(javaMirror);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   263
  return find_index(klass);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   264
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   265
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   266
void AOTOopRecorder::record_meta_ref(jobject o, int index) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   267
  assert(index > 0, "must be 1..n");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   268
  index -= 1; // reduce by one to convert to array index
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   269
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   270
  assert(index == _meta_refs->length(), "must be last");
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   271
  _meta_refs->append(o);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   272
}
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
   273
#endif // INCLUDE_AOT
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   274
41697
94ef14db8a20 8166869: [JVMCI] record metadata relocations for metadata references
never
parents: 40093
diff changeset
   275
void* CodeInstaller::record_metadata_reference(CodeSection* section, address dest, Handle constant, TRAPS) {
36842
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36329
diff changeset
   276
  /*
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36329
diff changeset
   277
   * 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
   278
   * 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
   279
   * 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
   280
   * base class (Metadata* or MetaspaceObj*).
36842
8f0d0faa51e2 8152634: generalize exception throwing routines in JVMCIRuntime
rschatz
parents: 36329
diff changeset
   281
   */
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   282
  oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   283
  if (obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   284
    Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj));
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   285
    assert(!HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected compressed klass pointer %s @ " INTPTR_FORMAT, klass->name()->as_C_string(), p2i(klass));
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   286
    int index = _oop_recorder->find_index(klass);
41697
94ef14db8a20 8166869: [JVMCI] record metadata relocations for metadata references
never
parents: 40093
diff changeset
   287
    section->relocate(dest, metadata_Relocation::spec(index));
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   288
    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
   289
    return klass;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   290
  } else if (obj->is_a(HotSpotResolvedJavaMethodImpl::klass())) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   291
    Method* method = (Method*) (address) HotSpotResolvedJavaMethodImpl::metaspaceMethod(obj);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   292
    assert(!HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected compressed method pointer %s @ " INTPTR_FORMAT, method->name()->as_C_string(), p2i(method));
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   293
    int index = _oop_recorder->find_index(method);
41697
94ef14db8a20 8166869: [JVMCI] record metadata relocations for metadata references
never
parents: 40093
diff changeset
   294
    section->relocate(dest, metadata_Relocation::spec(index));
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   295
    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
   296
    return method;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   297
  } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   298
    JVMCI_ERROR_NULL("unexpected metadata reference for constant of type %s", obj->klass()->signature_name());
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   299
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   300
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   301
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   302
#ifdef _LP64
41697
94ef14db8a20 8166869: [JVMCI] record metadata relocations for metadata references
never
parents: 40093
diff changeset
   303
narrowKlass CodeInstaller::record_narrow_metadata_reference(CodeSection* section, address dest, Handle constant, TRAPS) {
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   304
  oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   305
  assert(HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected uncompressed pointer");
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   306
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   307
  if (!obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   308
    JVMCI_ERROR_0("unexpected compressed pointer of type %s", obj->klass()->signature_name());
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   309
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   310
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   311
  Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj));
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   312
  int index = _oop_recorder->find_index(klass);
41697
94ef14db8a20 8166869: [JVMCI] record metadata relocations for metadata references
never
parents: 40093
diff changeset
   313
  section->relocate(dest, metadata_Relocation::spec(index));
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   314
  TRACE_jvmci_3("narrowKlass[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string());
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   315
  return Klass::encode_klass(klass);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   316
}
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   317
#endif
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   318
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   319
Location::Type CodeInstaller::get_oop_type(Thread* thread, Handle value) {
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   320
  Handle valueKind(thread, Value::valueKind(value));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   321
  Handle platformKind(thread, ValueKind::platformKind(valueKind));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   322
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   323
  if (platformKind == word_kind()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   324
    return Location::oop;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   325
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   326
    return Location::narrowoop;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   327
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   328
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   329
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   330
ScopeValue* CodeInstaller::get_scope_value(Handle value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, TRAPS) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   331
  second = NULL;
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   332
  if (value.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   333
    THROW_NULL(vmSymbols::java_lang_NullPointerException());
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   334
  } else if (value == Value::ILLEGAL()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   335
    if (type != T_ILLEGAL) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   336
      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
   337
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   338
    return _illegal_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   339
  } else if (value->is_a(RegisterValue::klass())) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   340
    Handle reg(THREAD, RegisterValue::reg(value));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   341
    jint number = code_Register::number(reg);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   342
    VMReg hotspotRegister = get_hotspot_reg(number, CHECK_NULL);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   343
    if (is_general_purpose_reg(hotspotRegister)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   344
      Location::Type locationType;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   345
      if (type == T_OBJECT) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   346
        locationType = get_oop_type(THREAD, value);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   347
      } else if (type == T_LONG) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   348
        locationType = Location::lng;
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   349
      } 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
   350
        locationType = Location::int_in_long;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   351
      } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   352
        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
   353
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   354
      ScopeValue* value = new LocationValue(Location::new_reg_loc(locationType, hotspotRegister));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   355
      if (type == T_LONG) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   356
        second = value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   357
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   358
      return value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   359
    } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   360
      Location::Type locationType;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   361
      if (type == T_FLOAT) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   362
        // 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
   363
        locationType = Location::normal;
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   364
      } else if (type == T_DOUBLE) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   365
        locationType = Location::dbl;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   366
      } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   367
        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
   368
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   369
      ScopeValue* value = new LocationValue(Location::new_reg_loc(locationType, hotspotRegister));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   370
      if (type == T_DOUBLE) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   371
        second = value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   372
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   373
      return value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   374
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   375
  } else if (value->is_a(StackSlot::klass())) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   376
    jint offset = StackSlot::offset(value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   377
    if (StackSlot::addFrameSize(value)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   378
      offset += _total_frame_size;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   379
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   380
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   381
    Location::Type locationType;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   382
    if (type == T_OBJECT) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   383
      locationType = get_oop_type(THREAD, value);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   384
    } else if (type == T_LONG) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   385
      locationType = Location::lng;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   386
    } else if (type == T_DOUBLE) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   387
      locationType = Location::dbl;
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   388
    } 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
   389
      locationType = Location::normal;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   390
    } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   391
      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
   392
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   393
    ScopeValue* value = new LocationValue(Location::new_stk_loc(locationType, offset));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   394
    if (type == T_DOUBLE || type == T_LONG) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   395
      second = value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   396
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   397
    return value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   398
  } else if (value->is_a(JavaConstant::klass())) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   399
    if (value->is_a(PrimitiveConstant::klass())) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   400
      if (value->is_a(RawConstant::klass())) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   401
        jlong prim = PrimitiveConstant::primitive(value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   402
        return new ConstantLongValue(prim);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   403
      } else {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   404
        Handle primitive_constant_kind(THREAD, PrimitiveConstant::kind(value));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   405
        BasicType constantType = JVMCIRuntime::kindToBasicType(primitive_constant_kind, CHECK_NULL);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   406
        if (type != constantType) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   407
          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
   408
        }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   409
        if (type == T_INT || type == T_FLOAT) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   410
          jint prim = (jint)PrimitiveConstant::primitive(value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   411
          switch (prim) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   412
            case -1: return _int_m1_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   413
            case  0: return _int_0_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   414
            case  1: return _int_1_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   415
            case  2: return _int_2_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   416
            default: return new ConstantIntValue(prim);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   417
          }
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   418
        } else if (type == T_LONG || type == T_DOUBLE) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   419
          jlong prim = PrimitiveConstant::primitive(value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   420
          second = _int_1_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   421
          return new ConstantLongValue(prim);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   422
        } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   423
          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
   424
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   425
      }
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   426
    } else if (value->is_a(NullConstant::klass()) || value->is_a(HotSpotCompressedNullConstant::klass())) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   427
      if (type == T_OBJECT) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   428
        return _oop_null_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   429
      } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   430
        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
   431
      }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   432
    } else if (value->is_a(HotSpotObjectConstantImpl::klass())) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   433
      if (type == T_OBJECT) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   434
        oop obj = HotSpotObjectConstantImpl::object(value);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   435
        if (obj == NULL) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   436
          JVMCI_ERROR_NULL("null value must be in NullConstant");
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   437
        }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   438
        return new ConstantOopWriteValue(JNIHandles::make_local(obj));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   439
      } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   440
        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
   441
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   442
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   443
  } else if (value->is_a(VirtualObject::klass())) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   444
    if (type == T_OBJECT) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   445
      int id = VirtualObject::id(value);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   446
      if (0 <= id && id < objects->length()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   447
        ScopeValue* object = objects->at(id);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   448
        if (object != NULL) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   449
          return object;
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   450
        }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   451
      }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   452
      JVMCI_ERROR_NULL("unknown virtual object id %d", id);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   453
    } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   454
      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
   455
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   456
  }
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   457
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   458
  JVMCI_ERROR_NULL("unexpected value in scope: %s", value->klass()->signature_name())
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   459
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   460
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   461
void CodeInstaller::record_object_value(ObjectValue* sv, Handle value, GrowableArray<ScopeValue*>* objects, TRAPS) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   462
  // Might want a HandleMark here.
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   463
  Handle type(THREAD, VirtualObject::type(value));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   464
  int id = VirtualObject::id(value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   465
  oop javaMirror = HotSpotResolvedObjectTypeImpl::javaClass(type);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   466
  Klass* klass = java_lang_Class::as_Klass(javaMirror);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   467
  bool isLongArray = klass == Universe::longArrayKlassObj();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   468
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   469
  objArrayHandle values(THREAD, VirtualObject::values(value));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   470
  objArrayHandle slotKinds(THREAD, VirtualObject::slotKinds(value));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   471
  for (jint i = 0; i < values->length(); i++) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   472
    HandleMark hm(THREAD);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   473
    ScopeValue* cur_second = NULL;
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   474
    Handle object(THREAD, values->obj_at(i));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   475
    Handle slot_kind (THREAD, slotKinds->obj_at(i));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   476
    BasicType type = JVMCIRuntime::kindToBasicType(slot_kind, CHECK);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   477
    ScopeValue* value = get_scope_value(object, type, objects, cur_second, CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   478
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   479
    if (isLongArray && cur_second == NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   480
      // 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
   481
      // add an int 0 constant
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   482
      cur_second = _int_0_scope_value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   483
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   484
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   485
    if (cur_second != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   486
      sv->field_values()->append(cur_second);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   487
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   488
    assert(value != NULL, "missing value");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   489
    sv->field_values()->append(value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   490
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   491
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   492
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   493
MonitorValue* CodeInstaller::get_monitor_value(Handle value, GrowableArray<ScopeValue*>* objects, TRAPS) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   494
  if (value.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   495
    THROW_NULL(vmSymbols::java_lang_NullPointerException());
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   496
  }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   497
  if (!value->is_a(StackLockValue::klass())) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   498
    JVMCI_ERROR_NULL("Monitors must be of type StackLockValue, got %s", value->klass()->signature_name());
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   499
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   500
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   501
  ScopeValue* second = NULL;
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   502
  Handle stack_lock_owner(THREAD, StackLockValue::owner(value));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   503
  ScopeValue* owner_value = get_scope_value(stack_lock_owner, T_OBJECT, objects, second, CHECK_NULL);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   504
  assert(second == NULL, "monitor cannot occupy two stack slots");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   505
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   506
  Handle stack_lock_slot(THREAD, StackLockValue::slot(value));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   507
  ScopeValue* lock_data_value = get_scope_value(stack_lock_slot, T_LONG, objects, second, CHECK_NULL);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   508
  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
   509
  assert(lock_data_value->is_location(), "invalid monitor location");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   510
  Location lock_data_loc = ((LocationValue*)lock_data_value)->location();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   511
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   512
  bool eliminated = false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   513
  if (StackLockValue::eliminated(value)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   514
    eliminated = true;
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
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   517
  return new MonitorValue(owner_value, lock_data_loc, eliminated);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   518
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   519
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   520
void CodeInstaller::initialize_dependencies(oop compiled_code, OopRecorder* recorder, TRAPS) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   521
  JavaThread* thread = JavaThread::current();
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   522
  assert(THREAD == thread, "");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   523
  CompilerThread* compilerThread = thread->is_Compiler_thread() ? thread->as_CompilerThread() : NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   524
  _oop_recorder = recorder;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   525
  _dependencies = new Dependencies(&_arena, _oop_recorder, compilerThread != NULL ? compilerThread->log() : NULL);
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   526
  objArrayHandle assumptions(THREAD, HotSpotCompiledCode::assumptions(compiled_code));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   527
  if (!assumptions.is_null()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   528
    int length = assumptions->length();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   529
    for (int i = 0; i < length; ++i) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   530
      Handle assumption(THREAD, assumptions->obj_at(i));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   531
      if (!assumption.is_null()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   532
        if (assumption->klass() == Assumptions_NoFinalizableSubclass::klass()) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   533
          assumption_NoFinalizableSubclass(THREAD, assumption);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   534
        } else if (assumption->klass() == Assumptions_ConcreteSubtype::klass()) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   535
          assumption_ConcreteSubtype(THREAD, assumption);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   536
        } else if (assumption->klass() == Assumptions_LeafType::klass()) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   537
          assumption_LeafType(THREAD, assumption);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   538
        } else if (assumption->klass() == Assumptions_ConcreteMethod::klass()) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   539
          assumption_ConcreteMethod(THREAD, assumption);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   540
        } else if (assumption->klass() == Assumptions_CallSiteTargetValue::klass()) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   541
          assumption_CallSiteTargetValue(THREAD, assumption);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   542
        } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   543
          JVMCI_ERROR("unexpected Assumption subclass %s", assumption->klass()->signature_name());
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
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   546
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   547
  }
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   548
  if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   549
    objArrayHandle methods(THREAD, HotSpotCompiledCode::methods(compiled_code));
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   550
    if (!methods.is_null()) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   551
      int length = methods->length();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   552
      for (int i = 0; i < length; ++i) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   553
        Handle method_handle(THREAD, methods->obj_at(i));
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   554
        methodHandle method = getMethodFromHotSpotMethod(method_handle());
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   555
        _dependencies->assert_evol_method(method());
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   556
      }
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
  }
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
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
   561
#if INCLUDE_AOT
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   562
RelocBuffer::~RelocBuffer() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   563
  if (_buffer != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   564
    FREE_C_HEAP_ARRAY(char, _buffer);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   565
  }
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
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   568
address RelocBuffer::begin() const {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   569
  if (_buffer != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   570
    return (address) _buffer;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   571
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   572
  return (address) _static_buffer;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   573
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   574
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   575
void RelocBuffer::set_size(size_t bytes) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   576
  assert(bytes <= _size, "can't grow in size!");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   577
  _size = bytes;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   578
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   579
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   580
void RelocBuffer::ensure_size(size_t bytes) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   581
  assert(_buffer == NULL, "can only be used once");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   582
  assert(_size == 0, "can only be used once");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   583
  if (bytes >= RelocBuffer::stack_size) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   584
    _buffer = NEW_C_HEAP_ARRAY(char, bytes, mtInternal);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   585
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   586
  _size = bytes;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   587
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   588
34165
66826441022f 8142329: [JVMCI] pass Handle by value
twisti
parents: 34153
diff changeset
   589
JVMCIEnv::CodeInstallResult CodeInstaller::gather_metadata(Handle target, Handle compiled_code, CodeMetadata& metadata, TRAPS) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   590
  CodeBuffer buffer("JVMCI Compiler CodeBuffer for Metadata");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   591
  jobject compiled_code_obj = JNIHandles::make_local(compiled_code());
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   592
  AOTOopRecorder* recorder = new AOTOopRecorder(&_arena, true);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   593
  initialize_dependencies(JNIHandles::resolve(compiled_code_obj), recorder, CHECK_OK);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   594
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   595
  metadata.set_oop_recorder(recorder);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   596
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   597
  // Get instructions and constants CodeSections early because we need it.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   598
  _instructions = buffer.insts();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   599
  _constants = buffer.consts();
50104
4ea7917929b9 8185505: AArch64: Port AOT to AArch64
aph
parents: 49593
diff changeset
   600
  buffer.set_immutable_PIC(_immutable_pic_compilation);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   601
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   602
  initialize_fields(target(), JNIHandles::resolve(compiled_code_obj), CHECK_OK);
43416
f8c241512446 8171082: [AOT] AOT'd SystemModules.modules() fails to load when too large
rbackman
parents: 42861
diff changeset
   603
  JVMCIEnv::CodeInstallResult result = initialize_buffer(buffer, false, CHECK_OK);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   604
  if (result != JVMCIEnv::ok) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   605
    return result;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   606
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   607
38695
08b834856583 8156835: [JVMCI] clean up and minimize JVMCI
dnsimon
parents: 38692
diff changeset
   608
  _debug_recorder->pcs_size(); // create the sentinel record
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   609
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   610
  assert(_debug_recorder->pcs_length() >= 2, "must be at least 2");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   611
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   612
  metadata.set_pc_desc(_debug_recorder->pcs(), _debug_recorder->pcs_length());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   613
  metadata.set_scopes(_debug_recorder->stream()->buffer(), _debug_recorder->data_size());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   614
  metadata.set_exception_table(&_exception_handler_table);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   615
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   616
  RelocBuffer* reloc_buffer = metadata.get_reloc_buffer();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   617
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   618
  reloc_buffer->ensure_size(buffer.total_relocation_size());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   619
  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
   620
  reloc_buffer->set_size(size);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   621
  return JVMCIEnv::ok;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   622
}
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
   623
#endif // INCLUDE_AOT
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   624
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   625
// constructor used to create a method
34165
66826441022f 8142329: [JVMCI] pass Handle by value
twisti
parents: 34153
diff changeset
   626
JVMCIEnv::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler, Handle target, Handle compiled_code, CodeBlob*& cb, Handle installed_code, Handle speculation_log, TRAPS) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   627
  CodeBuffer buffer("JVMCI Compiler CodeBuffer");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   628
  jobject compiled_code_obj = JNIHandles::make_local(compiled_code());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   629
  OopRecorder* recorder = new OopRecorder(&_arena, true);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   630
  initialize_dependencies(JNIHandles::resolve(compiled_code_obj), recorder, CHECK_OK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   631
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   632
  // Get instructions and constants CodeSections early because we need it.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   633
  _instructions = buffer.insts();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   634
  _constants = buffer.consts();
50104
4ea7917929b9 8185505: AArch64: Port AOT to AArch64
aph
parents: 49593
diff changeset
   635
#if INCLUDE_AOT
4ea7917929b9 8185505: AArch64: Port AOT to AArch64
aph
parents: 49593
diff changeset
   636
  buffer.set_immutable_PIC(_immutable_pic_compilation);
4ea7917929b9 8185505: AArch64: Port AOT to AArch64
aph
parents: 49593
diff changeset
   637
#endif
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   638
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   639
  initialize_fields(target(), JNIHandles::resolve(compiled_code_obj), CHECK_OK);
43416
f8c241512446 8171082: [AOT] AOT'd SystemModules.modules() fails to load when too large
rbackman
parents: 42861
diff changeset
   640
  JVMCIEnv::CodeInstallResult result = initialize_buffer(buffer, true, CHECK_OK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   641
  if (result != JVMCIEnv::ok) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   642
    return result;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   643
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   644
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   645
  int stack_slots = _total_frame_size / HeapWordSize; // conversion to words
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   646
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   647
  if (!compiled_code->is_a(HotSpotCompiledNmethod::klass())) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   648
    oop stubName = HotSpotCompiledCode::name(compiled_code_obj);
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49449
diff changeset
   649
    if (stubName == NULL) {
48443
8935285e8759 8194271: jaotc crashes with --debug flag
iveresov
parents: 47881
diff changeset
   650
      JVMCI_ERROR_OK("stub should have a name");
8935285e8759 8194271: jaotc crashes with --debug flag
iveresov
parents: 47881
diff changeset
   651
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   652
    char* name = strdup(java_lang_String::as_utf8_string(stubName));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   653
    cb = RuntimeStub::new_runtime_stub(name,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   654
                                       &buffer,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   655
                                       CodeOffsets::frame_never_safe,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   656
                                       stack_slots,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   657
                                       _debug_recorder->_oopmaps,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   658
                                       false);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   659
    result = JVMCIEnv::ok;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   660
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   661
    nmethod* nm = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   662
    methodHandle method = getMethodFromHotSpotMethod(HotSpotCompiledNmethod::method(compiled_code));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   663
    jint entry_bci = HotSpotCompiledNmethod::entryBCI(compiled_code);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   664
    jint id = HotSpotCompiledNmethod::id(compiled_code);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   665
    bool has_unsafe_access = HotSpotCompiledNmethod::hasUnsafeAccess(compiled_code) == JNI_TRUE;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   666
    JVMCIEnv* env = (JVMCIEnv*) (address) HotSpotCompiledNmethod::jvmciEnv(compiled_code);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   667
    if (id == -1) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   668
      // Make sure a valid compile_id is associated with every compile
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   669
      id = CompileBroker::assign_compile_id_unlocked(Thread::current(), method, entry_bci);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   670
    }
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
   671
    result = JVMCIEnv::register_method(method, nm, entry_bci, &_offsets, _orig_pc_offset, &buffer,
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   672
                                       stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   673
                                       compiler, _debug_recorder, _dependencies, env, id,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   674
                                       has_unsafe_access, _has_wide_vector, installed_code, compiled_code, speculation_log);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   675
    cb = nm->as_codeblob_or_null();
36329
06727ae6971e 8150561: [AArch64] JVMCI improvements
twisti
parents: 36063
diff changeset
   676
    if (nm != NULL && env == NULL) {
06727ae6971e 8150561: [AArch64] JVMCI improvements
twisti
parents: 36063
diff changeset
   677
      DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, compiler);
06727ae6971e 8150561: [AArch64] JVMCI improvements
twisti
parents: 36063
diff changeset
   678
      bool printnmethods = directive->PrintAssemblyOption || directive->PrintNMethodsOption;
46479
a10af96a2dbb 8180601: hsdis generates duplicate output for JVMCI installed code
ysuenaga
parents: 46289
diff changeset
   679
      if (!printnmethods && (PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers)) {
36329
06727ae6971e 8150561: [AArch64] JVMCI improvements
twisti
parents: 36063
diff changeset
   680
        nm->print_nmethod(printnmethods);
06727ae6971e 8150561: [AArch64] JVMCI improvements
twisti
parents: 36063
diff changeset
   681
      }
06727ae6971e 8150561: [AArch64] JVMCI improvements
twisti
parents: 36063
diff changeset
   682
      DirectivesStack::release(directive);
06727ae6971e 8150561: [AArch64] JVMCI improvements
twisti
parents: 36063
diff changeset
   683
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   684
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   685
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   686
  if (cb != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   687
    // Make sure the pre-calculated constants section size was correct.
33198
dlong
parents: 33160
diff changeset
   688
    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
   689
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   690
  return result;
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
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   693
void CodeInstaller::initialize_fields(oop target, oop compiled_code, TRAPS) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   694
  if (compiled_code->is_a(HotSpotCompiledNmethod::klass())) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   695
    Handle hotspotJavaMethod(THREAD, HotSpotCompiledNmethod::method(compiled_code));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   696
    methodHandle method = getMethodFromHotSpotMethod(hotspotJavaMethod());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   697
    _parameter_count = method->size_of_parameters();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   698
    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
   699
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   700
    // Must be a HotSpotCompiledRuntimeStub.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   701
    // Only used in OopMap constructor for non-product builds
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   702
    _parameter_count = 0;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   703
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   704
  _sites_handle = JNIHandles::make_local(HotSpotCompiledCode::sites(compiled_code));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   705
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   706
  _code_handle = JNIHandles::make_local(HotSpotCompiledCode::targetCode(compiled_code));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   707
  _code_size = HotSpotCompiledCode::targetCodeSize(compiled_code);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   708
  _total_frame_size = 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
   709
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
   710
  oop deoptRescueSlot = HotSpotCompiledCode::deoptRescueSlot(compiled_code);
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
   711
  if (deoptRescueSlot == NULL) {
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
   712
    _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
   713
  } else {
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
   714
    _orig_pc_offset = StackSlot::offset(deoptRescueSlot);
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
   715
    if (StackSlot::addFrameSize(deoptRescueSlot)) {
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
   716
      _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
   717
    }
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
   718
    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
   719
      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
   720
    }
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
   721
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   722
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   723
  // Pre-calculate the constants section size.  This is required for PC-relative addressing.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   724
  _data_section_handle = JNIHandles::make_local(HotSpotCompiledCode::dataSection(compiled_code));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   725
  if ((_constants->alignment() % HotSpotCompiledCode::dataSectionAlignment(compiled_code)) != 0) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   726
    JVMCI_ERROR("invalid data section alignment: %d", HotSpotCompiledCode::dataSectionAlignment(compiled_code));
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   727
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   728
  _constants_size = data_section()->length();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   729
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   730
  _data_section_patches_handle = JNIHandles::make_local(HotSpotCompiledCode::dataSectionPatches(compiled_code));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   731
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   732
#ifndef PRODUCT
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   733
  _comments_handle = JNIHandles::make_local(HotSpotCompiledCode::comments(compiled_code));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   734
#endif
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   735
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   736
  _next_call_type = INVOKE_INVALID;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   737
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   738
  _has_wide_vector = false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   739
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   740
  oop arch = TargetDescription::arch(target);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   741
  _word_kind_handle = JNIHandles::make_local(Architecture::wordKind(arch));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   742
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   743
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   744
int CodeInstaller::estimate_stubs_size(TRAPS) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   745
  // 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
   746
  int static_call_stubs = 0;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   747
  int aot_call_stubs = 0;
48487
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   748
  int trampoline_stubs = 0;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   749
  objArrayOop sites = this->sites();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   750
  for (int i = 0; i < sites->length(); i++) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   751
    oop site = sites->obj_at(i);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   752
    if (site != NULL) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   753
      if (site->is_a(site_Mark::klass())) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   754
        oop id_obj = site_Mark::id(site);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   755
        if (id_obj != NULL) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   756
          if (!java_lang_boxing_object::is_instance(id_obj, T_INT)) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   757
            JVMCI_ERROR_0("expected Integer id, got %s", id_obj->klass()->signature_name());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   758
          }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   759
          jint id = id_obj->int_field(java_lang_boxing_object::value_offset_in_bytes(T_INT));
48487
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   760
          switch (id) {
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   761
          case INVOKEINTERFACE:
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   762
          case INVOKEVIRTUAL:
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   763
            trampoline_stubs++;
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   764
            break;
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   765
          case INVOKESTATIC:
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   766
          case INVOKESPECIAL:
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   767
            static_call_stubs++;
48487
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   768
            trampoline_stubs++;
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   769
            break;
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   770
          default:
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   771
            break;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   772
          }
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   773
        }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   774
      }
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
   775
#if INCLUDE_AOT
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   776
      if (UseAOT && site->is_a(site_Call::klass())) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   777
        oop target = site_Call::target(site);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   778
        InstanceKlass* target_klass = InstanceKlass::cast(target->klass());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   779
        if (!target_klass->is_subclass_of(SystemDictionary::HotSpotForeignCallTarget_klass())) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   780
          // Add far aot trampolines.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   781
          aot_call_stubs++;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   782
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   783
      }
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
   784
#endif
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   785
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   786
  }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   787
  int size = static_call_stubs * CompiledStaticCall::to_interp_stub_size();
48487
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
   788
  size += trampoline_stubs * CompiledStaticCall::to_trampoline_stub_size();
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   789
#if INCLUDE_AOT
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   790
  size += aot_call_stubs * CompiledStaticCall::to_aot_stub_size();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   791
#endif
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
   792
  return size;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   793
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   794
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   795
// perform data and call relocation on the CodeBuffer
43416
f8c241512446 8171082: [AOT] AOT'd SystemModules.modules() fails to load when too large
rbackman
parents: 42861
diff changeset
   796
JVMCIEnv::CodeInstallResult CodeInstaller::initialize_buffer(CodeBuffer& buffer, bool check_size, TRAPS) {
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   797
  HandleMark hm;
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   798
  objArrayHandle sites(THREAD, this->sites());
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   799
  int locs_buffer_size = sites->length() * (relocInfo::length_limit + sizeof(relocInfo));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   800
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   801
  // Allocate enough space in the stub section for the static call
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   802
  // 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
   803
  // 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
   804
  // locs_buffer above.
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   805
  int stubs_size = estimate_stubs_size(CHECK_OK);
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46479
diff changeset
   806
  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
   807
43416
f8c241512446 8171082: [AOT] AOT'd SystemModules.modules() fails to load when too large
rbackman
parents: 42861
diff changeset
   808
  if (check_size && total_size > JVMCINMethodSizeLimit) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   809
    return JVMCIEnv::code_too_large;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   810
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   811
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   812
  buffer.initialize(total_size, locs_buffer_size);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   813
  if (buffer.blob() == NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   814
    return JVMCIEnv::cache_full;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   815
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   816
  buffer.initialize_stubs_size(stubs_size);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   817
  buffer.initialize_consts_size(_constants_size);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   818
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   819
  _debug_recorder = new DebugInformationRecorder(_oop_recorder);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   820
  _debug_recorder->set_oopmaps(new OopMapSet());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   821
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   822
  buffer.initialize_oop_recorder(_oop_recorder);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   823
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   824
  // copy the constant data into the newly created CodeBuffer
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   825
  address end_data = _constants->start() + _constants_size;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   826
  memcpy(_constants->start(), data_section()->base(T_BYTE), _constants_size);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   827
  _constants->set_end(end_data);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   828
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   829
  // copy the code into the newly created CodeBuffer
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   830
  address end_pc = _instructions->start() + _code_size;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   831
  guarantee(_instructions->allocates2(end_pc), "initialize should have reserved enough space for all the code");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   832
  memcpy(_instructions->start(), code()->base(T_BYTE), _code_size);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   833
  _instructions->set_end(end_pc);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   834
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   835
  for (int i = 0; i < data_section_patches()->length(); i++) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   836
    HandleMark hm(THREAD);
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   837
    Handle patch(THREAD, data_section_patches()->obj_at(i));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   838
    if (patch.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   839
      THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   840
    }
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   841
    Handle reference(THREAD, site_DataPatch::reference(patch));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   842
    if (reference.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   843
      THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   844
    }
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   845
    if (!reference->is_a(site_ConstantReference::klass())) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   846
      JVMCI_ERROR_OK("invalid patch in data section: %s", reference->klass()->signature_name());
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   847
    }
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   848
    Handle constant(THREAD, site_ConstantReference::constant(reference));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   849
    if (constant.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   850
      THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   851
    }
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   852
    address dest = _constants->start() + site_Site::pcOffset(patch);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   853
    if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) {
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   854
      if (HotSpotMetaspaceConstantImpl::compressed(constant)) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   855
#ifdef _LP64
41697
94ef14db8a20 8166869: [JVMCI] record metadata relocations for metadata references
never
parents: 40093
diff changeset
   856
        *((narrowKlass*) dest) = record_narrow_metadata_reference(_constants, dest, constant, CHECK_OK);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   857
#else
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   858
        JVMCI_ERROR_OK("unexpected compressed Klass* in 32-bit mode");
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   859
#endif
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   860
      } else {
41697
94ef14db8a20 8166869: [JVMCI] record metadata relocations for metadata references
never
parents: 40093
diff changeset
   861
        *((void**) dest) = record_metadata_reference(_constants, dest, constant, CHECK_OK);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
   862
      }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   863
    } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   864
      Handle obj(THREAD, HotSpotObjectConstantImpl::object(constant));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   865
      jobject value = JNIHandles::make_local(obj());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   866
      int oop_index = _oop_recorder->find_index(value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   867
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   868
      if (HotSpotObjectConstantImpl::compressed(constant)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   869
#ifdef _LP64
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   870
        _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
   871
#else
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   872
        JVMCI_ERROR_OK("unexpected compressed oop in 32-bit mode");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   873
#endif
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   874
      } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   875
        _constants->relocate(dest, oop_Relocation::spec(oop_index));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   876
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   877
    } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   878
      JVMCI_ERROR_OK("invalid constant in data section: %s", constant->klass()->signature_name());
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   879
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   880
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   881
  jint last_pc_offset = -1;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   882
  for (int i = 0; i < sites->length(); i++) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   883
    HandleMark hm(THREAD);
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   884
    Handle site(THREAD, sites->obj_at(i));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   885
    if (site.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   886
      THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   887
    }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   888
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   889
    jint pc_offset = site_Site::pcOffset(site);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   890
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   891
    if (site->is_a(site_Call::klass())) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   892
      TRACE_jvmci_4("call at %i", pc_offset);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   893
      site_Call(buffer, pc_offset, site, CHECK_OK);
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   894
    } else if (site->is_a(site_Infopoint::klass())) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   895
      // three reasons for infopoints denote actual safepoints
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   896
      oop reason = site_Infopoint::reason(site);
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   897
      if (site_InfopointReason::SAFEPOINT() == reason || site_InfopointReason::CALL() == reason || site_InfopointReason::IMPLICIT_EXCEPTION() == reason) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   898
        TRACE_jvmci_4("safepoint at %i", pc_offset);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   899
        site_Safepoint(buffer, pc_offset, site, 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
   900
        if (_orig_pc_offset < 0) {
35827
24e567453a33 8149105: typo in jvmciCodeInstaller.cpp
rschatz
parents: 35823
diff changeset
   901
          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
   902
        }
34502
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
   903
      } else {
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
   904
        TRACE_jvmci_4("infopoint at %i", pc_offset);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   905
        site_Infopoint(buffer, pc_offset, site, CHECK_OK);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   906
      }
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   907
    } else if (site->is_a(site_DataPatch::klass())) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   908
      TRACE_jvmci_4("datapatch at %i", pc_offset);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   909
      site_DataPatch(buffer, pc_offset, site, CHECK_OK);
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   910
    } else if (site->is_a(site_Mark::klass())) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   911
      TRACE_jvmci_4("mark at %i", pc_offset);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   912
      site_Mark(buffer, pc_offset, site, CHECK_OK);
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   913
    } else if (site->is_a(site_ExceptionHandler::klass())) {
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   914
      TRACE_jvmci_4("exceptionhandler at %i", pc_offset);
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   915
      site_ExceptionHandler(pc_offset, site);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   916
    } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   917
      JVMCI_ERROR_OK("unexpected site subclass: %s", site->klass()->signature_name());
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   918
    }
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   919
    last_pc_offset = pc_offset;
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
   920
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47765
diff changeset
   921
    JavaThread* thread = JavaThread::current();
52450
2790da836dc3 8211403: Rename SafepointMechanism::poll(...)
rehn
parents: 52381
diff changeset
   922
    if (SafepointMechanism::should_block(thread)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   923
      // 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
   924
      ThreadToNativeFromVM ttnfv(thread);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   925
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   926
  }
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
#ifndef PRODUCT
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   929
  if (comments() != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   930
    for (int i = 0; i < comments()->length(); i++) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   931
      oop comment = comments()->obj_at(i);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   932
      assert(comment->is_a(HotSpotCompiledCode_Comment::klass()), "cce");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   933
      jint offset = HotSpotCompiledCode_Comment::pcOffset(comment);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   934
      char* text = java_lang_String::as_utf8_string(HotSpotCompiledCode_Comment::text(comment));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   935
      buffer.block_comment(offset, text);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   936
    }
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
#endif
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   939
  return JVMCIEnv::ok;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   940
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   941
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   942
void CodeInstaller::assumption_NoFinalizableSubclass(Thread* thread, Handle assumption) {
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   943
  Handle receiverType_handle (thread, Assumptions_NoFinalizableSubclass::receiverType(assumption()));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   944
  Klass* receiverType = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(receiverType_handle));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   945
  _dependencies->assert_has_no_finalizable_subclasses(receiverType);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   946
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   947
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   948
void CodeInstaller::assumption_ConcreteSubtype(Thread* thread, Handle assumption) {
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   949
  Handle context_handle (thread, Assumptions_ConcreteSubtype::context(assumption()));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   950
  Handle subtype_handle (thread, Assumptions_ConcreteSubtype::subtype(assumption()));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   951
  Klass* context = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(context_handle));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   952
  Klass* subtype = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(subtype_handle));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   953
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   954
  assert(context->is_abstract(), "");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   955
  _dependencies->assert_abstract_with_unique_concrete_subtype(context, subtype);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   956
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   957
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   958
void CodeInstaller::assumption_LeafType(Thread* thread, Handle assumption) {
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   959
  Handle context_handle (thread, Assumptions_LeafType::context(assumption()));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   960
  Klass* context = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(context_handle));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   961
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   962
  _dependencies->assert_leaf_type(context);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   963
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   964
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   965
void CodeInstaller::assumption_ConcreteMethod(Thread* thread, Handle assumption) {
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   966
  Handle impl_handle (thread, Assumptions_ConcreteMethod::impl(assumption()));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   967
  Handle context_handle (thread, Assumptions_ConcreteMethod::context(assumption()));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   968
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   969
  methodHandle impl = getMethodFromHotSpotMethod(impl_handle());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   970
  Klass* context = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(context_handle));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   971
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   972
  _dependencies->assert_unique_concrete_method(context, impl());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   973
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   974
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
   975
void CodeInstaller::assumption_CallSiteTargetValue(Thread* thread, Handle assumption) {
50858
2d3e99a72541 8205824: Update Graal
never
parents: 50746
diff changeset
   976
  Handle callSite(thread, HotSpotObjectConstantImpl::object(Assumptions_CallSiteTargetValue::callSite(assumption())));
2d3e99a72541 8205824: Update Graal
never
parents: 50746
diff changeset
   977
  Handle methodHandle(thread, HotSpotObjectConstantImpl::object(Assumptions_CallSiteTargetValue::methodHandle(assumption())));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   978
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   979
  _dependencies->assert_call_site_target_value(callSite(), methodHandle());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   980
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   981
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   982
void CodeInstaller::site_ExceptionHandler(jint pc_offset, Handle exc) {
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   983
  jint handler_offset = site_ExceptionHandler::handlerPos(exc);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   984
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   985
  // Subtable header
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   986
  _exception_handler_table.add_entry(HandlerTableEntry(1, pc_offset, 0));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   987
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   988
  // Subtable entry
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
   989
  _exception_handler_table.add_entry(HandlerTableEntry(-1, handler_offset, 0));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   990
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   991
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   992
// If deoptimization happens, the interpreter should reexecute these bytecodes.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   993
// 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
   994
static bool bytecode_should_reexecute(Bytecodes::Code code) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   995
  switch (code) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   996
    case Bytecodes::_invokedynamic:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   997
    case Bytecodes::_invokevirtual:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   998
    case Bytecodes::_invokeinterface:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   999
    case Bytecodes::_invokespecial:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1000
    case Bytecodes::_invokestatic:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1001
      return false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1002
    default:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1003
      return true;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1004
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1005
  return true;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1006
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1007
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1008
GrowableArray<ScopeValue*>* CodeInstaller::record_virtual_objects(Handle debug_info, TRAPS) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1009
  objArrayHandle virtualObjects(THREAD, DebugInfo::virtualObjectMapping(debug_info));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1010
  if (virtualObjects.is_null()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1011
    return NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1012
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1013
  GrowableArray<ScopeValue*>* objects = new GrowableArray<ScopeValue*>(virtualObjects->length(), virtualObjects->length(), NULL);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1014
  // Create the unique ObjectValues
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1015
  for (int i = 0; i < virtualObjects->length(); i++) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1016
    HandleMark hm(THREAD);
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1017
    Handle value(THREAD, virtualObjects->obj_at(i));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1018
    int id = VirtualObject::id(value);
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1019
    Handle type(THREAD, VirtualObject::type(value));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1020
    oop javaMirror = HotSpotResolvedObjectTypeImpl::javaClass(type);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1021
    ObjectValue* sv = new ObjectValue(id, new ConstantOopWriteValue(JNIHandles::make_local(Thread::current(), javaMirror)));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1022
    if (id < 0 || id >= objects->length()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1023
      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
  1024
    }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1025
    if (objects->at(id) != NULL) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1026
      JVMCI_ERROR_NULL("duplicate virtual object id %d", id);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1027
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1028
    objects->at_put(id, sv);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1029
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1030
  // All the values which could be referenced by the VirtualObjects
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1031
  // exist, so now describe all the VirtualObjects themselves.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1032
  for (int i = 0; i < virtualObjects->length(); i++) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1033
    HandleMark hm(THREAD);
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1034
    Handle value(THREAD, virtualObjects->obj_at(i));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1035
    int id = VirtualObject::id(value);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1036
    record_object_value(objects->at(id)->as_ObjectValue(), value, objects, CHECK_NULL);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1037
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1038
  _debug_recorder->dump_object_pool(objects);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1039
  return objects;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1040
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1041
42861
1d4dfdf4390b 8169938: [AOT] SIGSEGV at ~BufferBlob::vtable chunks
dlong
parents: 42650
diff changeset
  1042
void CodeInstaller::record_scope(jint pc_offset, Handle debug_info, ScopeMode scope_mode, bool return_oop, TRAPS) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1043
  Handle position(THREAD, DebugInfo::bytecodePosition(debug_info));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1044
  if (position.is_null()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1045
    // Stubs do not record scope info, just oop maps
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1046
    return;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1047
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1048
34502
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1049
  GrowableArray<ScopeValue*>* objectMapping;
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1050
  if (scope_mode == CodeInstaller::FullFrame) {
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1051
    objectMapping = record_virtual_objects(debug_info, CHECK);
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1052
  } else {
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1053
    objectMapping = NULL;
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1054
  }
42861
1d4dfdf4390b 8169938: [AOT] SIGSEGV at ~BufferBlob::vtable chunks
dlong
parents: 42650
diff changeset
  1055
  record_scope(pc_offset, position, scope_mode, objectMapping, return_oop, CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1056
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1057
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
  1058
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
  1059
  if (bci < 0) {
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
  1060
    if (bci == BytecodeFrame::BEFORE_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
  1061
      return BeforeBci;
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
  1062
    } else if (bci == BytecodeFrame::AFTER_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
  1063
      return AfterBci;
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
  1064
    } else if (bci == BytecodeFrame::UNWIND_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
  1065
      return UnwindBci;
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
  1066
    } else if (bci == BytecodeFrame::AFTER_EXCEPTION_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
  1067
      return AfterExceptionBci;
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
  1068
    } else if (bci == BytecodeFrame::UNKNOWN_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
  1069
      return UnknownBci;
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
  1070
    } else if (bci == BytecodeFrame::INVALID_FRAMESTATE_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
  1071
      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
  1072
    }
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
  1073
    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
  1074
  }
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
  1075
  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
  1076
}
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
  1077
42861
1d4dfdf4390b 8169938: [AOT] SIGSEGV at ~BufferBlob::vtable chunks
dlong
parents: 42650
diff changeset
  1078
void CodeInstaller::record_scope(jint pc_offset, Handle position, ScopeMode scope_mode, GrowableArray<ScopeValue*>* objects, bool return_oop, TRAPS) {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1079
  Handle frame;
34502
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1080
  if (scope_mode == CodeInstaller::FullFrame) {
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1081
    if (!position->is_a(BytecodeFrame::klass())) {
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1082
      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
  1083
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1084
    frame = position;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1085
  }
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1086
  Handle caller_frame (THREAD, BytecodePosition::caller(position));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1087
  if (caller_frame.not_null()) {
42861
1d4dfdf4390b 8169938: [AOT] SIGSEGV at ~BufferBlob::vtable chunks
dlong
parents: 42650
diff changeset
  1088
    record_scope(pc_offset, caller_frame, scope_mode, objects, return_oop, CHECK);
33160
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
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1091
  Handle hotspot_method (THREAD, BytecodePosition::method(position));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1092
  Method* method = getMethodFromHotSpotMethod(hotspot_method());
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
  1093
  jint bci = map_jvmci_bci(BytecodePosition::bci(position));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1094
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1095
  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
  1096
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1097
  bool reexecute = false;
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1098
  if (frame.not_null()) {
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
  1099
    if (bci < 0) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1100
       reexecute = false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1101
    } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1102
      Bytecodes::Code code = Bytecodes::java_code_at(method, method->bcp_from(bci));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1103
      reexecute = bytecode_should_reexecute(code);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1104
      if (frame.not_null()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1105
        reexecute = (BytecodeFrame::duringCall(frame) == JNI_FALSE);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1106
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1107
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1108
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1109
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1110
  DebugToken* locals_token = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1111
  DebugToken* expressions_token = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1112
  DebugToken* monitors_token = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1113
  bool throw_exception = false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1114
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1115
  if (frame.not_null()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1116
    jint local_count = BytecodeFrame::numLocals(frame);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1117
    jint expression_count = BytecodeFrame::numStack(frame);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1118
    jint monitor_count = BytecodeFrame::numLocks(frame);
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1119
    objArrayHandle values(THREAD, BytecodeFrame::values(frame));
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1120
    objArrayHandle slotKinds(THREAD, BytecodeFrame::slotKinds(frame));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1121
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1122
    if (values.is_null() || slotKinds.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1123
      THROW(vmSymbols::java_lang_NullPointerException());
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1124
    }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1125
    if (local_count + expression_count + monitor_count != values->length()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1126
      JVMCI_ERROR("unexpected values length %d in scope (%d locals, %d expressions, %d monitors)", values->length(), local_count, expression_count, monitor_count);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1127
    }
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1128
    if (local_count + expression_count != slotKinds->length()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1129
      JVMCI_ERROR("unexpected slotKinds length %d in scope (%d locals, %d expressions)", slotKinds->length(), local_count, expression_count);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1130
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1131
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1132
    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
  1133
    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
  1134
    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
  1135
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1136
    TRACE_jvmci_2("Scope at bci %d with %d values", bci, values->length());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1137
    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
  1138
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1139
    for (jint i = 0; i < values->length(); i++) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1140
      HandleMark hm(THREAD);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1141
      ScopeValue* second = NULL;
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1142
      Handle value(THREAD, values->obj_at(i));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1143
      if (i < local_count) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1144
        BasicType type = JVMCIRuntime::kindToBasicType(Handle(THREAD, slotKinds->obj_at(i)), CHECK);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1145
        ScopeValue* first = get_scope_value(value, type, objects, second, CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1146
        if (second != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1147
          locals->append(second);
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
        locals->append(first);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1150
      } else if (i < local_count + expression_count) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1151
        BasicType type = JVMCIRuntime::kindToBasicType(Handle(THREAD, slotKinds->obj_at(i)), CHECK);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1152
        ScopeValue* first = get_scope_value(value, type, objects, second, CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1153
        if (second != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1154
          expressions->append(second);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1155
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1156
        expressions->append(first);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1157
      } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1158
        MonitorValue *monitor = get_monitor_value(value, objects, CHECK);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1159
        monitors->append(monitor);
33160
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
      if (second != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1162
        i++;
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1163
        if (i >= values->length() || values->obj_at(i) != Value::ILLEGAL()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1164
          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
  1165
        }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1166
      }
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
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1169
    locals_token = _debug_recorder->create_scope_values(locals);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1170
    expressions_token = _debug_recorder->create_scope_values(expressions);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1171
    monitors_token = _debug_recorder->create_monitor_values(monitors);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1172
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1173
    throw_exception = BytecodeFrame::rethrowException(frame) == JNI_TRUE;
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
42861
1d4dfdf4390b 8169938: [AOT] SIGSEGV at ~BufferBlob::vtable chunks
dlong
parents: 42650
diff changeset
  1176
  _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
  1177
                                  locals_token, expressions_token, monitors_token);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1178
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1179
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1180
void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1181
  Handle debug_info (THREAD, site_Infopoint::debugInfo(site));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1182
  if (debug_info.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1183
    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
  1184
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1185
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1186
  // address instruction = _instructions->start() + pc_offset;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1187
  // jint next_pc_offset = Assembler::locate_next_instruction(instruction) - _instructions->start();
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1188
  OopMap *map = create_oop_map(debug_info, CHECK);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1189
  _debug_recorder->add_safepoint(pc_offset, map);
34502
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1190
  record_scope(pc_offset, debug_info, CodeInstaller::FullFrame, CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1191
  _debug_recorder->end_safepoint(pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1192
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1193
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1194
void CodeInstaller::site_Infopoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1195
  Handle debug_info (THREAD, site_Infopoint::debugInfo(site));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1196
  if (debug_info.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1197
    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
  1198
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1199
34502
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1200
  // 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
  1201
  // last pc recorded with _debug_recorder (raising an exception if not)
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1202
  // but DebugInformationRecorder doesn't have sufficient public API.
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1203
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1204
  _debug_recorder->add_non_safepoint(pc_offset);
34502
1cfcb971cb17 8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents: 34165
diff changeset
  1205
  record_scope(pc_offset, debug_info, CodeInstaller::BytecodePosition, CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1206
  _debug_recorder->end_non_safepoint(pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1207
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1208
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1209
void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1210
  Handle target(THREAD, site_Call::target(site));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1211
  InstanceKlass* target_klass = InstanceKlass::cast(target->klass());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1212
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1213
  Handle hotspot_method; // JavaMethod
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1214
  Handle foreign_call;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1215
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1216
  if (target_klass->is_subclass_of(SystemDictionary::HotSpotForeignCallTarget_klass())) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1217
    foreign_call = target;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1218
  } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1219
    hotspot_method = target;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1220
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1221
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1222
  Handle debug_info (THREAD, site_Call::debugInfo(site));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1223
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1224
  assert(hotspot_method.not_null() ^ foreign_call.not_null(), "Call site needs exactly one type");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1225
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1226
  NativeInstruction* inst = nativeInstruction_at(_instructions->start() + pc_offset);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1227
  jint next_pc_offset = CodeInstaller::pd_next_offset(inst, pc_offset, hotspot_method, CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1228
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1229
  if (debug_info.not_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1230
    OopMap *map = create_oop_map(debug_info, CHECK);
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1231
    _debug_recorder->add_safepoint(next_pc_offset, map);
42861
1d4dfdf4390b 8169938: [AOT] SIGSEGV at ~BufferBlob::vtable chunks
dlong
parents: 42650
diff changeset
  1232
1d4dfdf4390b 8169938: [AOT] SIGSEGV at ~BufferBlob::vtable chunks
dlong
parents: 42650
diff changeset
  1233
    bool return_oop = hotspot_method.not_null() && getMethodFromHotSpotMethod(hotspot_method())->is_returning_oop();
1d4dfdf4390b 8169938: [AOT] SIGSEGV at ~BufferBlob::vtable chunks
dlong
parents: 42650
diff changeset
  1234
1d4dfdf4390b 8169938: [AOT] SIGSEGV at ~BufferBlob::vtable chunks
dlong
parents: 42650
diff changeset
  1235
    record_scope(next_pc_offset, debug_info, CodeInstaller::FullFrame, return_oop, CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1236
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1237
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1238
  if (foreign_call.not_null()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1239
    jlong foreign_call_destination = HotSpotForeignCallTarget::address(foreign_call);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1240
    if (_immutable_pic_compilation) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1241
      // Use fake short distance during PIC compilation.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1242
      foreign_call_destination = (jlong)(_instructions->start() + pc_offset);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1243
    }
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1244
    CodeInstaller::pd_relocate_ForeignCall(inst, foreign_call_destination, CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1245
  } else { // method != NULL
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1246
    if (debug_info.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1247
      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
  1248
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1249
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1250
    TRACE_jvmci_3("method call");
48487
abf1d797e380 8193260: AArch64: JVMCI: Implement trampoline calls
aph
parents: 47881
diff changeset
  1251
    CodeInstaller::pd_relocate_JavaMethod(buffer, hotspot_method, pc_offset, CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1252
    if (_next_call_type == INVOKESTATIC || _next_call_type == INVOKESPECIAL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1253
      // Need a static call stub for transitions from compiled to interpreted.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1254
      CompiledStaticCall::emit_to_interp_stub(buffer, _instructions->start() + pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1255
    }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1256
#if INCLUDE_AOT
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1257
    // Trampoline to far aot code.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1258
    CompiledStaticCall::emit_to_aot_stub(buffer, _instructions->start() + pc_offset);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1259
#endif
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1260
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1261
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1262
  _next_call_type = INVOKE_INVALID;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1263
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1264
  if (debug_info.not_null()) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1265
    _debug_recorder->end_safepoint(next_pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1266
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1267
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1268
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1269
void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1270
  Handle reference(THREAD, site_DataPatch::reference(site));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1271
  if (reference.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1272
    THROW(vmSymbols::java_lang_NullPointerException());
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
  1273
  } else if (reference->is_a(site_ConstantReference::klass())) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1274
    Handle constant(THREAD, site_ConstantReference::constant(reference));
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1275
    if (constant.is_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1276
      THROW(vmSymbols::java_lang_NullPointerException());
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1277
    } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1278
      if (!_immutable_pic_compilation) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1279
        // Do not patch during PIC compilation.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1280
        pd_patch_OopConstant(pc_offset, constant, CHECK);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1281
      }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1282
    } else if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1283
      if (!_immutable_pic_compilation) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1284
        pd_patch_MetaspaceConstant(pc_offset, constant, CHECK);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1285
      }
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
  1286
#if INCLUDE_AOT
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1287
    } else if (constant->is_a(HotSpotSentinelConstant::klass())) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1288
      if (!_immutable_pic_compilation) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1289
        JVMCI_ERROR("sentinel constant not supported for normal compiles: %s", constant->klass()->signature_name());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1290
      }
52381
7f90bc64b0fc 8213203: [JVMCI] adopt formatting changes from jvmci 8
never
parents: 51078
diff changeset
  1291
#endif
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1292
    } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1293
      JVMCI_ERROR("unknown constant type in data patch: %s", constant->klass()->signature_name());
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1294
    }
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
  1295
  } else if (reference->is_a(site_DataSectionReference::klass())) {
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 34502
diff changeset
  1296
    int data_offset = site_DataSectionReference::offset(reference);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1297
    if (0 <= data_offset && data_offset < _constants_size) {
36063
96e86c7f8fec 8149689: [JVMCI] CodeInstaller::pd_patch_DataSectionReference should be able to throw exceptions
twisti
parents: 35827
diff changeset
  1298
      pd_patch_DataSectionReference(pc_offset, data_offset, CHECK);
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1299
    } else {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1300
      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
  1301
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1302
  } else {
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1303
    JVMCI_ERROR("unknown data patch type: %s", reference->klass()->signature_name());
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1304
  }
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
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1307
void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42861
diff changeset
  1308
  Handle id_obj (THREAD, site_Mark::id(site));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1309
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1310
  if (id_obj.not_null()) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1311
    if (!java_lang_boxing_object::is_instance(id_obj(), T_INT)) {
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1312
      JVMCI_ERROR("expected Integer id, got %s", id_obj->klass()->signature_name());
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1313
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1314
    jint id = id_obj->int_field(java_lang_boxing_object::value_offset_in_bytes(T_INT));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1315
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1316
    address pc = _instructions->start() + pc_offset;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1317
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1318
    switch (id) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1319
      case UNVERIFIED_ENTRY:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1320
        _offsets.set_value(CodeOffsets::Entry, pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1321
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1322
      case VERIFIED_ENTRY:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1323
        _offsets.set_value(CodeOffsets::Verified_Entry, pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1324
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1325
      case OSR_ENTRY:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1326
        _offsets.set_value(CodeOffsets::OSR_Entry, pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1327
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1328
      case EXCEPTION_HANDLER_ENTRY:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1329
        _offsets.set_value(CodeOffsets::Exceptions, pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1330
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1331
      case DEOPT_HANDLER_ENTRY:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1332
        _offsets.set_value(CodeOffsets::Deopt, pc_offset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1333
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1334
      case INVOKEVIRTUAL:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1335
      case INVOKEINTERFACE:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1336
      case INLINE_INVOKE:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1337
      case INVOKESTATIC:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1338
      case INVOKESPECIAL:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1339
        _next_call_type = (MarkId) id;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1340
        _invoke_mark_pc = pc;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1341
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1342
      case POLL_NEAR:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1343
      case POLL_FAR:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1344
      case POLL_RETURN_NEAR:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1345
      case POLL_RETURN_FAR:
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1346
        pd_relocate_poll(pc, id, CHECK);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1347
        break;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33198
diff changeset
  1348
      case CARD_TABLE_SHIFT:
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1349
      case CARD_TABLE_ADDRESS:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1350
      case HEAP_TOP_ADDRESS:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1351
      case HEAP_END_ADDRESS:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1352
      case NARROW_KLASS_BASE_ADDRESS:
43435
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 43416
diff changeset
  1353
      case NARROW_OOP_BASE_ADDRESS:
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1354
      case CRC_TABLE_ADDRESS:
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1355
      case LOG_OF_HEAP_REGION_GRAIN_BYTES:
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41697
diff changeset
  1356
      case INLINE_CONTIGUOUS_ALLOCATION_SUPPORTED:
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1357
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1358
      default:
34153
cbcfa2a6fe0b 8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents: 33632
diff changeset
  1359
        JVMCI_ERROR("invalid mark id: %d", id);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1360
        break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1361
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1362
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
  1363
}