23 */
24
25 #include "code/debugInfo.hpp"
26 #include "oops/access.hpp"
27 #include "oops/compressedOops.inline.hpp"
28 #include "oops/oop.hpp"
29 #include "runtime/frame.inline.hpp"
30 #include "runtime/globals.hpp"
31 #include "runtime/handles.inline.hpp"
32 #include "runtime/stackValue.hpp"
33 #if INCLUDE_ZGC
34 #include "gc/z/zBarrier.inline.hpp"
35 #endif
36 #if INCLUDE_SHENANDOAHGC
37 #include "gc/shenandoah/shenandoahBarrierSet.inline.hpp"
38 #endif
39
40 class RegisterMap;
41 class SmallRegisterMap;
42
43 template StackValue* StackValue::create_stack_value(const frame* fr, const RegisterMap* reg_map, ScopeValue* sv);
44 template StackValue* StackValue::create_stack_value(const frame* fr, const SmallRegisterMap* reg_map, ScopeValue* sv);
45
46 template<typename RegisterMapT>
47 StackValue* StackValue::create_stack_value(const frame* fr, const RegisterMapT* reg_map, ScopeValue* sv) {
48 return create_stack_value(sv, stack_value_address(fr, reg_map, sv), reg_map);
49 }
50
51 static oop oop_from_oop_location(stackChunkOop chunk, void* addr) {
52 if (addr == nullptr) {
53 return nullptr;
54 }
55
56 if (UseCompressedOops) {
57 // When compressed oops is enabled, an oop location may
58 // contain narrow oop values - we deal with that here
59
60 if (chunk != nullptr && chunk->has_bitmap()) {
61 // Transformed stack chunk with narrow oops
62 return chunk->load_oop((narrowOop*)addr);
63 }
64
65 #ifdef _LP64
66 if (CompressedOops::is_base(*(void**)addr)) {
67 // Compiled code may produce decoded oop = narrow_oop_base
68 // when a narrow oop implicit null check is used.
69 // The narrow_oop_base could be null or be the address
130
131 return val;
132 }
133
134 StackValue* StackValue::create_stack_value_from_oop_location(stackChunkOop chunk, void* addr) {
135 oop val = oop_from_oop_location(chunk, addr);
136 assert(oopDesc::is_oop_or_null(val), "bad oop found at " INTPTR_FORMAT " in_cont: %d compressed: %d",
137 p2i(addr), chunk != nullptr, chunk != nullptr && chunk->has_bitmap() && UseCompressedOops);
138 Handle h(Thread::current(), val); // Wrap a handle around the oop
139 return new StackValue(h);
140 }
141
142 StackValue* StackValue::create_stack_value_from_narrowOop_location(stackChunkOop chunk, void* addr, bool is_register) {
143 oop val = oop_from_narrowOop_location(chunk, addr, is_register);
144 assert(oopDesc::is_oop_or_null(val), "bad oop found at " INTPTR_FORMAT " in_cont: %d compressed: %d",
145 p2i(addr), chunk != nullptr, chunk != nullptr && chunk->has_bitmap() && UseCompressedOops);
146 Handle h(Thread::current(), val); // Wrap a handle around the oop
147 return new StackValue(h);
148 }
149
150 template<typename RegisterMapT>
151 StackValue* StackValue::create_stack_value(ScopeValue* sv, address value_addr, const RegisterMapT* reg_map) {
152 stackChunkOop chunk = reg_map->stack_chunk()();
153 if (sv->is_location()) {
154 // Stack or register value
155 Location loc = ((LocationValue *)sv)->location();
156
157 // Then package it right depending on type
158 // Note: the transfer of the data is thru a union that contains
159 // an intptr_t. This is because an interpreter stack slot is
160 // really an intptr_t. The use of a union containing an intptr_t
161 // ensures that on a 64 bit platform we have proper alignment
162 // and that we store the value where the interpreter will expect
163 // to find it (i.e. proper endian). Similarly on a 32bit platform
164 // using the intptr_t ensures that when a value is larger than
165 // a stack slot (jlong/jdouble) that we capture the proper part
166 // of the value for the stack slot in question.
167 //
168 switch( loc.type() ) {
169 case Location::float_in_dbl: { // Holds a float in a double register?
170 // The callee has no clue whether the register holds a float,
171 // double or is unused. He always saves a double. Here we know
232 } else if (sv->is_constant_oop()) {
233 // constant oop
234 return new StackValue(sv->as_ConstantOopReadValue()->value());
235 #ifdef _LP64
236 } else if (sv->is_constant_double()) {
237 // Constant double in a single stack slot
238 union { intptr_t p; double d; } value;
239 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
240 value.d = ((ConstantDoubleValue *)sv)->value();
241 return new StackValue(value.p);
242 } else if (sv->is_constant_long()) {
243 // Constant long in a single stack slot
244 union { intptr_t p; jlong jl; } value;
245 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
246 value.jl = ((ConstantLongValue *)sv)->value();
247 return new StackValue(value.p);
248 #endif
249 } else if (sv->is_object()) { // Scalar replaced object in compiled frame
250 ObjectValue* ov = (ObjectValue *)sv;
251 Handle hdl = ov->value();
252 return new StackValue(hdl, hdl.is_null() && ov->is_scalar_replaced() ? 1 : 0);
253 } else if (sv->is_marker()) {
254 // Should never need to directly construct a marker.
255 ShouldNotReachHere();
256 }
257 // Unknown ScopeValue type
258 ShouldNotReachHere();
259 return new StackValue((intptr_t) 0); // dummy
260 }
261
262 template address StackValue::stack_value_address(const frame* fr, const RegisterMap* reg_map, ScopeValue* sv);
263 template address StackValue::stack_value_address(const frame* fr, const SmallRegisterMap* reg_map, ScopeValue* sv);
264
265 template<typename RegisterMapT>
266 address StackValue::stack_value_address(const frame* fr, const RegisterMapT* reg_map, ScopeValue* sv) {
267 if (!sv->is_location()) {
268 return nullptr;
269 }
270 Location loc = ((LocationValue *)sv)->location();
271 if (loc.type() == Location::invalid) {
272 return nullptr;
|
23 */
24
25 #include "code/debugInfo.hpp"
26 #include "oops/access.hpp"
27 #include "oops/compressedOops.inline.hpp"
28 #include "oops/oop.hpp"
29 #include "runtime/frame.inline.hpp"
30 #include "runtime/globals.hpp"
31 #include "runtime/handles.inline.hpp"
32 #include "runtime/stackValue.hpp"
33 #if INCLUDE_ZGC
34 #include "gc/z/zBarrier.inline.hpp"
35 #endif
36 #if INCLUDE_SHENANDOAHGC
37 #include "gc/shenandoah/shenandoahBarrierSet.inline.hpp"
38 #endif
39
40 class RegisterMap;
41 class SmallRegisterMap;
42
43
44 static oop oop_from_oop_location(stackChunkOop chunk, void* addr) {
45 if (addr == nullptr) {
46 return nullptr;
47 }
48
49 if (UseCompressedOops) {
50 // When compressed oops is enabled, an oop location may
51 // contain narrow oop values - we deal with that here
52
53 if (chunk != nullptr && chunk->has_bitmap()) {
54 // Transformed stack chunk with narrow oops
55 return chunk->load_oop((narrowOop*)addr);
56 }
57
58 #ifdef _LP64
59 if (CompressedOops::is_base(*(void**)addr)) {
60 // Compiled code may produce decoded oop = narrow_oop_base
61 // when a narrow oop implicit null check is used.
62 // The narrow_oop_base could be null or be the address
123
124 return val;
125 }
126
127 StackValue* StackValue::create_stack_value_from_oop_location(stackChunkOop chunk, void* addr) {
128 oop val = oop_from_oop_location(chunk, addr);
129 assert(oopDesc::is_oop_or_null(val), "bad oop found at " INTPTR_FORMAT " in_cont: %d compressed: %d",
130 p2i(addr), chunk != nullptr, chunk != nullptr && chunk->has_bitmap() && UseCompressedOops);
131 Handle h(Thread::current(), val); // Wrap a handle around the oop
132 return new StackValue(h);
133 }
134
135 StackValue* StackValue::create_stack_value_from_narrowOop_location(stackChunkOop chunk, void* addr, bool is_register) {
136 oop val = oop_from_narrowOop_location(chunk, addr, is_register);
137 assert(oopDesc::is_oop_or_null(val), "bad oop found at " INTPTR_FORMAT " in_cont: %d compressed: %d",
138 p2i(addr), chunk != nullptr, chunk != nullptr && chunk->has_bitmap() && UseCompressedOops);
139 Handle h(Thread::current(), val); // Wrap a handle around the oop
140 return new StackValue(h);
141 }
142
143
144 template StackValue* StackValue::create_stack_value(const frame* fr, const RegisterMap* reg_map, ScopeValue* sv);
145 template StackValue* StackValue::create_stack_value(const frame* fr, const SmallRegisterMap* reg_map, ScopeValue* sv);
146
147 template<typename RegisterMapT>
148 StackValue* StackValue::create_stack_value(const frame* fr, const RegisterMapT* reg_map, ScopeValue* sv) {
149 address value_addr = stack_value_address(fr, reg_map, sv);
150 stackChunkOop chunk = reg_map->stack_chunk()();
151 if (sv->is_location()) {
152 // Stack or register value
153 Location loc = ((LocationValue *)sv)->location();
154
155 // Then package it right depending on type
156 // Note: the transfer of the data is thru a union that contains
157 // an intptr_t. This is because an interpreter stack slot is
158 // really an intptr_t. The use of a union containing an intptr_t
159 // ensures that on a 64 bit platform we have proper alignment
160 // and that we store the value where the interpreter will expect
161 // to find it (i.e. proper endian). Similarly on a 32bit platform
162 // using the intptr_t ensures that when a value is larger than
163 // a stack slot (jlong/jdouble) that we capture the proper part
164 // of the value for the stack slot in question.
165 //
166 switch( loc.type() ) {
167 case Location::float_in_dbl: { // Holds a float in a double register?
168 // The callee has no clue whether the register holds a float,
169 // double or is unused. He always saves a double. Here we know
230 } else if (sv->is_constant_oop()) {
231 // constant oop
232 return new StackValue(sv->as_ConstantOopReadValue()->value());
233 #ifdef _LP64
234 } else if (sv->is_constant_double()) {
235 // Constant double in a single stack slot
236 union { intptr_t p; double d; } value;
237 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
238 value.d = ((ConstantDoubleValue *)sv)->value();
239 return new StackValue(value.p);
240 } else if (sv->is_constant_long()) {
241 // Constant long in a single stack slot
242 union { intptr_t p; jlong jl; } value;
243 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
244 value.jl = ((ConstantLongValue *)sv)->value();
245 return new StackValue(value.p);
246 #endif
247 } else if (sv->is_object()) { // Scalar replaced object in compiled frame
248 ObjectValue* ov = (ObjectValue *)sv;
249 Handle hdl = ov->value();
250 bool scalar_replaced = hdl.is_null() && ov->is_scalar_replaced();
251 if (ov->maybe_null()) {
252 // Don't treat inline type as scalar replaced if it is null
253 jint is_init = StackValue::create_stack_value(fr, reg_map, ov->is_init())->get_jint();
254 scalar_replaced &= (is_init != 0);
255 }
256 return new StackValue(hdl, scalar_replaced ? 1 : 0);
257 } else if (sv->is_marker()) {
258 // Should never need to directly construct a marker.
259 ShouldNotReachHere();
260 }
261 // Unknown ScopeValue type
262 ShouldNotReachHere();
263 return new StackValue((intptr_t) 0); // dummy
264 }
265
266 template address StackValue::stack_value_address(const frame* fr, const RegisterMap* reg_map, ScopeValue* sv);
267 template address StackValue::stack_value_address(const frame* fr, const SmallRegisterMap* reg_map, ScopeValue* sv);
268
269 template<typename RegisterMapT>
270 address StackValue::stack_value_address(const frame* fr, const RegisterMapT* reg_map, ScopeValue* sv) {
271 if (!sv->is_location()) {
272 return nullptr;
273 }
274 Location loc = ((LocationValue *)sv)->location();
275 if (loc.type() == Location::invalid) {
276 return nullptr;
|