author | serb |
Wed, 18 Apr 2018 14:07:41 -0700 | |
changeset 49998 | 9070717a16a1 |
parent 47216 | 71c04702a3d5 |
child 51996 | 84743156e780 |
permissions | -rw-r--r-- |
42065 | 1 |
/* |
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* Copyright (c) 2016 SAP SE. All rights reserved. |
|
4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 |
* |
|
6 |
* This code is free software; you can redistribute it and/or modify it |
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
|
8 |
* published by the Free Software Foundation. |
|
9 |
* |
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
23 |
* |
|
24 |
*/ |
|
25 |
||
26 |
#include "precompiled.hpp" |
|
27 |
#include "asm/macroAssembler.inline.hpp" |
|
28 |
#include "code/compiledIC.hpp" |
|
29 |
#include "code/icBuffer.hpp" |
|
30 |
#include "code/nmethod.hpp" |
|
31 |
#include "memory/resourceArea.hpp" |
|
32 |
#include "runtime/mutexLocker.hpp" |
|
33 |
#include "runtime/safepoint.hpp" |
|
34 |
#ifdef COMPILER2 |
|
35 |
#include "opto/matcher.hpp" |
|
36 |
#endif |
|
37 |
||
38 |
// ---------------------------------------------------------------------------- |
|
39 |
||
40 |
#undef __ |
|
41 |
#define __ _masm. |
|
42 |
||
43 |
address CompiledStaticCall::emit_to_interp_stub(CodeBuffer &cbuf, address mark/* = NULL*/) { |
|
44 |
#ifdef COMPILER2 |
|
45 |
// Stub is fixed up when the corresponding call is converted from calling |
|
46 |
// compiled code to calling interpreted code. |
|
47 |
if (mark == NULL) { |
|
48 |
// Get the mark within main instrs section which is set to the address of the call. |
|
49 |
mark = cbuf.insts_mark(); |
|
50 |
} |
|
51 |
assert(mark != NULL, "mark must not be NULL"); |
|
52 |
||
53 |
// Note that the code buffer's insts_mark is always relative to insts. |
|
54 |
// That's why we must use the macroassembler to generate a stub. |
|
55 |
MacroAssembler _masm(&cbuf); |
|
56 |
||
57 |
address stub = __ start_a_stub(Compile::MAX_stubs_size); |
|
58 |
if (stub == NULL) { |
|
59 |
return NULL; // CodeBuffer::expand failed. |
|
60 |
} |
|
61 |
__ relocate(static_stub_Relocation::spec(mark)); |
|
62 |
||
63 |
AddressLiteral meta = __ allocate_metadata_address(NULL); |
|
64 |
bool success = __ load_const_from_toc(as_Register(Matcher::inline_cache_reg_encode()), meta); |
|
65 |
||
66 |
__ set_inst_mark(); |
|
67 |
AddressLiteral a((address)-1); |
|
68 |
success = success && __ load_const_from_toc(Z_R1, a); |
|
69 |
if (!success) { |
|
70 |
return NULL; // CodeCache is full. |
|
71 |
} |
|
72 |
||
73 |
__ z_br(Z_R1); |
|
74 |
__ end_a_stub(); // Update current stubs pointer and restore insts_end. |
|
75 |
return stub; |
|
76 |
#else |
|
77 |
ShouldNotReachHere(); |
|
78 |
#endif |
|
79 |
} |
|
80 |
||
81 |
#undef __ |
|
82 |
||
83 |
int CompiledStaticCall::to_interp_stub_size() { |
|
84 |
return 2 * MacroAssembler::load_const_from_toc_size() + |
|
85 |
2; // branch |
|
86 |
} |
|
87 |
||
88 |
// Relocation entries for call stub, compiled java to interpreter. |
|
89 |
int CompiledStaticCall::reloc_to_interp_stub() { |
|
90 |
return 5; // 4 in emit_java_to_interp + 1 in Java_Static_Call |
|
91 |
} |
|
92 |
||
42650 | 93 |
void CompiledDirectStaticCall::set_to_interpreted(const methodHandle& callee, address entry) { |
94 |
address stub = find_stub(/*is_aot*/ false); |
|
42065 | 95 |
guarantee(stub != NULL, "stub not found"); |
96 |
||
97 |
if (TraceICs) { |
|
98 |
ResourceMark rm; |
|
42650 | 99 |
tty->print_cr("CompiledDirectStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s", |
42065 | 100 |
p2i(instruction_address()), |
101 |
callee->name_and_sig_as_C_string()); |
|
102 |
} |
|
103 |
||
104 |
// Creation also verifies the object. |
|
42650 | 105 |
NativeMovConstReg* method_holder = nativeMovConstReg_at(stub + NativeCall::get_IC_pos_in_java_to_interp_stub()); |
42065 | 106 |
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); |
107 |
||
46953
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
42650
diff
changeset
|
108 |
#ifdef ASSERT |
42065 | 109 |
// A generated lambda form might be deleted from the Lambdaform |
110 |
// cache in MethodTypeForm. If a jit compiled lambdaform method |
|
111 |
// becomes not entrant and the cache access returns null, the new |
|
112 |
// resolve will lead to a new generated LambdaForm. |
|
46953
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
42650
diff
changeset
|
113 |
volatile intptr_t data = method_holder->data(); |
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
42650
diff
changeset
|
114 |
volatile address destination = jump->jump_destination(); |
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
42650
diff
changeset
|
115 |
assert(data == 0 || data == (intptr_t)callee() || callee->is_compiled_lambda_form(), |
42065 | 116 |
"a) MT-unsafe modification of inline cache"); |
46953
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
42650
diff
changeset
|
117 |
assert(destination == (address)-1 || destination == entry, |
42065 | 118 |
"b) MT-unsafe modification of inline cache"); |
46953
39063b484ec2
8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents:
42650
diff
changeset
|
119 |
#endif |
42065 | 120 |
|
121 |
// Update stub. |
|
122 |
method_holder->set_data((intptr_t)callee()); |
|
123 |
jump->set_jump_destination(entry); |
|
124 |
||
125 |
// Update jump to call. |
|
126 |
set_destination_mt_safe(stub); |
|
127 |
} |
|
128 |
||
42650 | 129 |
void CompiledDirectStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) { |
42065 | 130 |
assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call"); |
131 |
// Reset stub. |
|
132 |
address stub = static_stub->addr(); |
|
133 |
assert(stub != NULL, "stub not found"); |
|
134 |
// Creation also verifies the object. |
|
42650 | 135 |
NativeMovConstReg* method_holder = nativeMovConstReg_at(stub + NativeCall::get_IC_pos_in_java_to_interp_stub()); |
42065 | 136 |
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); |
137 |
method_holder->set_data(0); |
|
138 |
jump->set_jump_destination((address)-1); |
|
139 |
} |
|
140 |
||
141 |
//----------------------------------------------------------------------------- |
|
142 |
||
143 |
#ifndef PRODUCT |
|
144 |
||
42650 | 145 |
void CompiledDirectStaticCall::verify() { |
42065 | 146 |
// Verify call. |
42650 | 147 |
_call->verify(); |
42065 | 148 |
if (os::is_MP()) { |
42650 | 149 |
_call->verify_alignment(); |
42065 | 150 |
} |
151 |
||
152 |
// Verify stub. |
|
42650 | 153 |
address stub = find_stub(/*is_aot*/ false); |
42065 | 154 |
assert(stub != NULL, "no stub found for static call"); |
155 |
// Creation also verifies the object. |
|
42650 | 156 |
NativeMovConstReg* method_holder = nativeMovConstReg_at(stub + NativeCall::get_IC_pos_in_java_to_interp_stub()); |
42065 | 157 |
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); |
158 |
||
159 |
// Verify state. |
|
160 |
assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check"); |
|
161 |
} |
|
162 |
||
163 |
#endif // !PRODUCT |