src/share/vm/runtime/stackValue.cpp

Thu, 24 May 2018 19:24:53 +0800

author
aoqi
date
Thu, 24 May 2018 19:24:53 +0800
changeset 8861
2a33b32dd03c
parent 6876
710a3c8b516e
permissions
-rw-r--r--

#7046 Disable the compilation when branch offset is beyond short branch
Contributed-by: fujie, aoqi

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "code/debugInfo.hpp"
aoqi@0 27 #include "oops/oop.inline.hpp"
aoqi@0 28 #include "runtime/frame.inline.hpp"
aoqi@0 29 #include "runtime/handles.inline.hpp"
aoqi@0 30 #include "runtime/stackValue.hpp"
aoqi@0 31
aoqi@0 32 StackValue* StackValue::create_stack_value(const frame* fr, const RegisterMap* reg_map, ScopeValue* sv) {
aoqi@0 33 if (sv->is_location()) {
aoqi@0 34 // Stack or register value
aoqi@0 35 Location loc = ((LocationValue *)sv)->location();
aoqi@0 36
aoqi@0 37 #ifdef SPARC
aoqi@0 38 // %%%%% Callee-save floats will NOT be working on a Sparc until we
aoqi@0 39 // handle the case of a 2 floats in a single double register.
aoqi@0 40 assert( !(loc.is_register() && loc.type() == Location::float_in_dbl), "Sparc does not handle callee-save floats yet" );
aoqi@0 41 #endif // SPARC
aoqi@0 42
aoqi@0 43 // First find address of value
aoqi@0 44
aoqi@0 45 address value_addr = loc.is_register()
aoqi@0 46 // Value was in a callee-save register
aoqi@0 47 ? reg_map->location(VMRegImpl::as_VMReg(loc.register_number()))
aoqi@0 48 // Else value was directly saved on the stack. The frame's original stack pointer,
aoqi@0 49 // before any extension by its callee (due to Compiler1 linkage on SPARC), must be used.
aoqi@0 50 : ((address)fr->unextended_sp()) + loc.stack_offset();
aoqi@0 51
aoqi@0 52 // Then package it right depending on type
aoqi@0 53 // Note: the transfer of the data is thru a union that contains
aoqi@0 54 // an intptr_t. This is because an interpreter stack slot is
aoqi@0 55 // really an intptr_t. The use of a union containing an intptr_t
aoqi@0 56 // ensures that on a 64 bit platform we have proper alignment
aoqi@0 57 // and that we store the value where the interpreter will expect
aoqi@0 58 // to find it (i.e. proper endian). Similarly on a 32bit platform
aoqi@0 59 // using the intptr_t ensures that when a value is larger than
aoqi@0 60 // a stack slot (jlong/jdouble) that we capture the proper part
aoqi@0 61 // of the value for the stack slot in question.
aoqi@0 62 //
aoqi@0 63 switch( loc.type() ) {
aoqi@0 64 case Location::float_in_dbl: { // Holds a float in a double register?
aoqi@0 65 // The callee has no clue whether the register holds a float,
aoqi@0 66 // double or is unused. He always saves a double. Here we know
aoqi@0 67 // a double was saved, but we only want a float back. Narrow the
aoqi@0 68 // saved double to the float that the JVM wants.
aoqi@0 69 assert( loc.is_register(), "floats always saved to stack in 1 word" );
aoqi@0 70 union { intptr_t p; jfloat jf; } value;
aoqi@0 71 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
aoqi@0 72 value.jf = (jfloat) *(jdouble*) value_addr;
aoqi@0 73 return new StackValue(value.p); // 64-bit high half is stack junk
aoqi@0 74 }
aoqi@0 75 case Location::int_in_long: { // Holds an int in a long register?
aoqi@0 76 // The callee has no clue whether the register holds an int,
aoqi@0 77 // long or is unused. He always saves a long. Here we know
aoqi@0 78 // a long was saved, but we only want an int back. Narrow the
aoqi@0 79 // saved long to the int that the JVM wants.
aoqi@0 80 assert( loc.is_register(), "ints always saved to stack in 1 word" );
aoqi@0 81 union { intptr_t p; jint ji;} value;
aoqi@0 82 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
aoqi@0 83 value.ji = (jint) *(jlong*) value_addr;
aoqi@0 84 return new StackValue(value.p); // 64-bit high half is stack junk
aoqi@0 85 }
aoqi@0 86 #ifdef _LP64
aoqi@0 87 case Location::dbl:
aoqi@0 88 // Double value in an aligned adjacent pair
aoqi@0 89 return new StackValue(*(intptr_t*)value_addr);
aoqi@0 90 case Location::lng:
aoqi@0 91 // Long value in an aligned adjacent pair
aoqi@0 92 return new StackValue(*(intptr_t*)value_addr);
aoqi@0 93 case Location::narrowoop: {
aoqi@0 94 union { intptr_t p; narrowOop noop;} value;
aoqi@0 95 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
aoqi@0 96 if (loc.is_register()) {
aoqi@0 97 // The callee has no clue whether the register holds an int,
aoqi@0 98 // long or is unused. He always saves a long. Here we know
aoqi@0 99 // a long was saved, but we only want an int back. Narrow the
aoqi@0 100 // saved long to the int that the JVM wants.
aoqi@0 101 value.noop = (narrowOop) *(julong*) value_addr;
aoqi@0 102 } else {
aoqi@0 103 value.noop = *(narrowOop*) value_addr;
aoqi@0 104 }
aoqi@0 105 // Decode narrowoop and wrap a handle around the oop
aoqi@0 106 Handle h(oopDesc::decode_heap_oop(value.noop));
aoqi@0 107 return new StackValue(h);
aoqi@0 108 }
aoqi@0 109 #endif
aoqi@0 110 case Location::oop: {
aoqi@0 111 oop val = *(oop *)value_addr;
aoqi@0 112 #ifdef _LP64
aoqi@0 113 if (Universe::is_narrow_oop_base(val)) {
aoqi@0 114 // Compiled code may produce decoded oop = narrow_oop_base
aoqi@0 115 // when a narrow oop implicit null check is used.
aoqi@0 116 // The narrow_oop_base could be NULL or be the address
aoqi@0 117 // of the page below heap. Use NULL value for both cases.
aoqi@0 118 val = (oop)NULL;
aoqi@0 119 }
aoqi@0 120 #endif
aoqi@0 121 Handle h(val); // Wrap a handle around the oop
aoqi@0 122 return new StackValue(h);
aoqi@0 123 }
aoqi@0 124 case Location::addr: {
aoqi@0 125 ShouldNotReachHere(); // both C1 and C2 now inline jsrs
aoqi@0 126 }
aoqi@0 127 case Location::normal: {
aoqi@0 128 // Just copy all other bits straight through
aoqi@0 129 union { intptr_t p; jint ji;} value;
aoqi@0 130 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
aoqi@0 131 value.ji = *(jint*)value_addr;
aoqi@0 132 return new StackValue(value.p);
aoqi@0 133 }
aoqi@0 134 case Location::invalid:
aoqi@0 135 return new StackValue();
aoqi@0 136 default:
aoqi@0 137 ShouldNotReachHere();
aoqi@0 138 }
aoqi@0 139
aoqi@0 140 } else if (sv->is_constant_int()) {
aoqi@0 141 // Constant int: treat same as register int.
aoqi@0 142 union { intptr_t p; jint ji;} value;
aoqi@0 143 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
aoqi@0 144 value.ji = (jint)((ConstantIntValue*)sv)->value();
aoqi@0 145 return new StackValue(value.p);
aoqi@0 146 } else if (sv->is_constant_oop()) {
aoqi@0 147 // constant oop
aoqi@0 148 return new StackValue(sv->as_ConstantOopReadValue()->value());
aoqi@0 149 #ifdef _LP64
aoqi@0 150 } else if (sv->is_constant_double()) {
aoqi@0 151 // Constant double in a single stack slot
aoqi@0 152 union { intptr_t p; double d; } value;
aoqi@0 153 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
aoqi@0 154 value.d = ((ConstantDoubleValue *)sv)->value();
aoqi@0 155 return new StackValue(value.p);
aoqi@0 156 } else if (sv->is_constant_long()) {
aoqi@0 157 // Constant long in a single stack slot
aoqi@0 158 union { intptr_t p; jlong jl; } value;
aoqi@0 159 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
aoqi@0 160 value.jl = ((ConstantLongValue *)sv)->value();
aoqi@0 161 return new StackValue(value.p);
aoqi@0 162 #endif
aoqi@0 163 } else if (sv->is_object()) { // Scalar replaced object in compiled frame
aoqi@0 164 Handle ov = ((ObjectValue *)sv)->value();
aoqi@0 165 return new StackValue(ov, (ov.is_null()) ? 1 : 0);
aoqi@0 166 }
aoqi@0 167
aoqi@0 168 // Unknown ScopeValue type
aoqi@0 169 ShouldNotReachHere();
aoqi@0 170 return new StackValue((intptr_t) 0); // dummy
aoqi@0 171 }
aoqi@0 172
aoqi@0 173
aoqi@0 174 BasicLock* StackValue::resolve_monitor_lock(const frame* fr, Location location) {
aoqi@0 175 assert(location.is_stack(), "for now we only look at the stack");
aoqi@0 176 int word_offset = location.stack_offset() / wordSize;
aoqi@0 177 // (stack picture)
aoqi@0 178 // high: [ ] word_offset + 1
aoqi@0 179 // low [ ] word_offset
aoqi@0 180 //
aoqi@0 181 // sp-> [ ] 0
aoqi@0 182 // the word_offset is the distance from the stack pointer to the lowest address
aoqi@0 183 // The frame's original stack pointer, before any extension by its callee
aoqi@0 184 // (due to Compiler1 linkage on SPARC), must be used.
aoqi@0 185 return (BasicLock*) (fr->unextended_sp() + word_offset);
aoqi@0 186 }
aoqi@0 187
aoqi@0 188
aoqi@0 189 #ifndef PRODUCT
aoqi@0 190
aoqi@0 191 void StackValue::print_on(outputStream* st) const {
aoqi@0 192 switch(_type) {
aoqi@0 193 case T_INT:
aoqi@0 194 st->print("%d (int) %f (float) %x (hex)", *(int *)&_i, *(float *)&_i, *(int *)&_i);
aoqi@0 195 break;
aoqi@0 196
aoqi@0 197 case T_OBJECT:
aoqi@0 198 _o()->print_value_on(st);
aoqi@0 199 st->print(" <" INTPTR_FORMAT ">", p2i((address)_o()));
aoqi@0 200 break;
aoqi@0 201
aoqi@0 202 case T_CONFLICT:
aoqi@0 203 st->print("conflict");
aoqi@0 204 break;
aoqi@0 205
aoqi@0 206 default:
aoqi@0 207 ShouldNotReachHere();
aoqi@0 208 }
aoqi@0 209 }
aoqi@0 210
aoqi@0 211 #endif

mercurial