src/share/vm/runtime/vframe_hp.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 4037
da91efe96a93
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2012, 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/codeCache.hpp"
aoqi@0 27 #include "code/debugInfoRec.hpp"
aoqi@0 28 #include "code/nmethod.hpp"
aoqi@0 29 #include "code/pcDesc.hpp"
aoqi@0 30 #include "code/scopeDesc.hpp"
aoqi@0 31 #include "interpreter/interpreter.hpp"
aoqi@0 32 #include "interpreter/oopMapCache.hpp"
aoqi@0 33 #include "oops/instanceKlass.hpp"
aoqi@0 34 #include "oops/oop.inline.hpp"
aoqi@0 35 #include "runtime/basicLock.hpp"
aoqi@0 36 #include "runtime/handles.inline.hpp"
aoqi@0 37 #include "runtime/monitorChunk.hpp"
aoqi@0 38 #include "runtime/signature.hpp"
aoqi@0 39 #include "runtime/stubRoutines.hpp"
aoqi@0 40 #include "runtime/vframeArray.hpp"
aoqi@0 41 #include "runtime/vframe_hp.hpp"
aoqi@0 42 #ifdef COMPILER2
aoqi@0 43 #include "opto/matcher.hpp"
aoqi@0 44 #endif
aoqi@0 45
aoqi@0 46
aoqi@0 47 // ------------- compiledVFrame --------------
aoqi@0 48
aoqi@0 49 StackValueCollection* compiledVFrame::locals() const {
aoqi@0 50 // Natives has no scope
aoqi@0 51 if (scope() == NULL) return new StackValueCollection(0);
aoqi@0 52 GrowableArray<ScopeValue*>* scv_list = scope()->locals();
aoqi@0 53 if (scv_list == NULL) return new StackValueCollection(0);
aoqi@0 54
aoqi@0 55 // scv_list is the list of ScopeValues describing the JVM stack state.
aoqi@0 56 // There is one scv_list entry for every JVM stack state in use.
aoqi@0 57 int length = scv_list->length();
aoqi@0 58 StackValueCollection* result = new StackValueCollection(length);
aoqi@0 59 // In rare instances set_locals may have occurred in which case
aoqi@0 60 // there are local values that are not described by the ScopeValue anymore
aoqi@0 61 GrowableArray<jvmtiDeferredLocalVariable*>* deferred = NULL;
aoqi@0 62 GrowableArray<jvmtiDeferredLocalVariableSet*>* list = thread()->deferred_locals();
aoqi@0 63 if (list != NULL ) {
aoqi@0 64 // In real life this never happens or is typically a single element search
aoqi@0 65 for (int i = 0; i < list->length(); i++) {
aoqi@0 66 if (list->at(i)->matches((vframe*)this)) {
aoqi@0 67 deferred = list->at(i)->locals();
aoqi@0 68 break;
aoqi@0 69 }
aoqi@0 70 }
aoqi@0 71 }
aoqi@0 72
aoqi@0 73 for( int i = 0; i < length; i++ ) {
aoqi@0 74 result->add( create_stack_value(scv_list->at(i)) );
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 // Replace specified locals with any deferred writes that are present
aoqi@0 78 if (deferred != NULL) {
aoqi@0 79 for ( int l = 0; l < deferred->length() ; l ++) {
aoqi@0 80 jvmtiDeferredLocalVariable* val = deferred->at(l);
aoqi@0 81 switch (val->type()) {
aoqi@0 82 case T_BOOLEAN:
aoqi@0 83 result->set_int_at(val->index(), val->value().z);
aoqi@0 84 break;
aoqi@0 85 case T_CHAR:
aoqi@0 86 result->set_int_at(val->index(), val->value().c);
aoqi@0 87 break;
aoqi@0 88 case T_FLOAT:
aoqi@0 89 result->set_float_at(val->index(), val->value().f);
aoqi@0 90 break;
aoqi@0 91 case T_DOUBLE:
aoqi@0 92 result->set_double_at(val->index(), val->value().d);
aoqi@0 93 break;
aoqi@0 94 case T_BYTE:
aoqi@0 95 result->set_int_at(val->index(), val->value().b);
aoqi@0 96 break;
aoqi@0 97 case T_SHORT:
aoqi@0 98 result->set_int_at(val->index(), val->value().s);
aoqi@0 99 break;
aoqi@0 100 case T_INT:
aoqi@0 101 result->set_int_at(val->index(), val->value().i);
aoqi@0 102 break;
aoqi@0 103 case T_LONG:
aoqi@0 104 result->set_long_at(val->index(), val->value().j);
aoqi@0 105 break;
aoqi@0 106 case T_OBJECT:
aoqi@0 107 {
aoqi@0 108 Handle obj((oop)val->value().l);
aoqi@0 109 result->set_obj_at(val->index(), obj);
aoqi@0 110 }
aoqi@0 111 break;
aoqi@0 112 default:
aoqi@0 113 ShouldNotReachHere();
aoqi@0 114 }
aoqi@0 115 }
aoqi@0 116 }
aoqi@0 117
aoqi@0 118 return result;
aoqi@0 119 }
aoqi@0 120
aoqi@0 121
aoqi@0 122 void compiledVFrame::set_locals(StackValueCollection* values) const {
aoqi@0 123
aoqi@0 124 fatal("Should use update_local for each local update");
aoqi@0 125 }
aoqi@0 126
aoqi@0 127 void compiledVFrame::update_local(BasicType type, int index, jvalue value) {
aoqi@0 128
aoqi@0 129 #ifdef ASSERT
aoqi@0 130
aoqi@0 131 assert(fr().is_deoptimized_frame(), "frame must be scheduled for deoptimization");
aoqi@0 132 #endif /* ASSERT */
aoqi@0 133 GrowableArray<jvmtiDeferredLocalVariableSet*>* deferred = thread()->deferred_locals();
aoqi@0 134 if (deferred != NULL ) {
aoqi@0 135 // See if this vframe has already had locals with deferred writes
aoqi@0 136 int f;
aoqi@0 137 for ( f = 0 ; f < deferred->length() ; f++ ) {
aoqi@0 138 if (deferred->at(f)->matches(this)) {
aoqi@0 139 // Matching, vframe now see if the local already had deferred write
aoqi@0 140 GrowableArray<jvmtiDeferredLocalVariable*>* locals = deferred->at(f)->locals();
aoqi@0 141 int l;
aoqi@0 142 for (l = 0 ; l < locals->length() ; l++ ) {
aoqi@0 143 if (locals->at(l)->index() == index) {
aoqi@0 144 locals->at(l)->set_value(value);
aoqi@0 145 return;
aoqi@0 146 }
aoqi@0 147 }
aoqi@0 148 // No matching local already present. Push a new value onto the deferred collection
aoqi@0 149 locals->push(new jvmtiDeferredLocalVariable(index, type, value));
aoqi@0 150 return;
aoqi@0 151 }
aoqi@0 152 }
aoqi@0 153 // No matching vframe must push a new vframe
aoqi@0 154 } else {
aoqi@0 155 // No deferred updates pending for this thread.
aoqi@0 156 // allocate in C heap
aoqi@0 157 deferred = new(ResourceObj::C_HEAP, mtCompiler) GrowableArray<jvmtiDeferredLocalVariableSet*> (1, true);
aoqi@0 158 thread()->set_deferred_locals(deferred);
aoqi@0 159 }
aoqi@0 160 deferred->push(new jvmtiDeferredLocalVariableSet(method(), bci(), fr().id()));
aoqi@0 161 assert(deferred->top()->id() == fr().id(), "Huh? Must match");
aoqi@0 162 deferred->top()->set_local_at(index, type, value);
aoqi@0 163 }
aoqi@0 164
aoqi@0 165 StackValueCollection* compiledVFrame::expressions() const {
aoqi@0 166 // Natives has no scope
aoqi@0 167 if (scope() == NULL) return new StackValueCollection(0);
aoqi@0 168 GrowableArray<ScopeValue*>* scv_list = scope()->expressions();
aoqi@0 169 if (scv_list == NULL) return new StackValueCollection(0);
aoqi@0 170
aoqi@0 171 // scv_list is the list of ScopeValues describing the JVM stack state.
aoqi@0 172 // There is one scv_list entry for every JVM stack state in use.
aoqi@0 173 int length = scv_list->length();
aoqi@0 174 StackValueCollection* result = new StackValueCollection(length);
aoqi@0 175 for( int i = 0; i < length; i++ )
aoqi@0 176 result->add( create_stack_value(scv_list->at(i)) );
aoqi@0 177
aoqi@0 178 return result;
aoqi@0 179 }
aoqi@0 180
aoqi@0 181
aoqi@0 182 // The implementation of the following two methods was factorized into the
aoqi@0 183 // class StackValue because it is also used from within deoptimization.cpp for
aoqi@0 184 // rematerialization and relocking of non-escaping objects.
aoqi@0 185
aoqi@0 186 StackValue *compiledVFrame::create_stack_value(ScopeValue *sv) const {
aoqi@0 187 return StackValue::create_stack_value(&_fr, register_map(), sv);
aoqi@0 188 }
aoqi@0 189
aoqi@0 190 BasicLock* compiledVFrame::resolve_monitor_lock(Location location) const {
aoqi@0 191 return StackValue::resolve_monitor_lock(&_fr, location);
aoqi@0 192 }
aoqi@0 193
aoqi@0 194
aoqi@0 195 GrowableArray<MonitorInfo*>* compiledVFrame::monitors() const {
aoqi@0 196 // Natives has no scope
aoqi@0 197 if (scope() == NULL) {
aoqi@0 198 nmethod* nm = code();
aoqi@0 199 Method* method = nm->method();
aoqi@0 200 assert(method->is_native(), "");
aoqi@0 201 if (!method->is_synchronized()) {
aoqi@0 202 return new GrowableArray<MonitorInfo*>(0);
aoqi@0 203 }
aoqi@0 204 // This monitor is really only needed for UseBiasedLocking, but
aoqi@0 205 // return it in all cases for now as it might be useful for stack
aoqi@0 206 // traces and tools as well
aoqi@0 207 GrowableArray<MonitorInfo*> *monitors = new GrowableArray<MonitorInfo*>(1);
aoqi@0 208 // Casting away const
aoqi@0 209 frame& fr = (frame&) _fr;
aoqi@0 210 MonitorInfo* info = new MonitorInfo(
aoqi@0 211 fr.get_native_receiver(), fr.get_native_monitor(), false, false);
aoqi@0 212 monitors->push(info);
aoqi@0 213 return monitors;
aoqi@0 214 }
aoqi@0 215 GrowableArray<MonitorValue*>* monitors = scope()->monitors();
aoqi@0 216 if (monitors == NULL) {
aoqi@0 217 return new GrowableArray<MonitorInfo*>(0);
aoqi@0 218 }
aoqi@0 219 GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(monitors->length());
aoqi@0 220 for (int index = 0; index < monitors->length(); index++) {
aoqi@0 221 MonitorValue* mv = monitors->at(index);
aoqi@0 222 ScopeValue* ov = mv->owner();
aoqi@0 223 StackValue *owner_sv = create_stack_value(ov); // it is an oop
aoqi@0 224 if (ov->is_object() && owner_sv->obj_is_scalar_replaced()) { // The owner object was scalar replaced
aoqi@0 225 assert(mv->eliminated(), "monitor should be eliminated for scalar replaced object");
aoqi@0 226 // Put klass for scalar replaced object.
aoqi@0 227 ScopeValue* kv = ((ObjectValue *)ov)->klass();
aoqi@0 228 assert(kv->is_constant_oop(), "klass should be oop constant for scalar replaced object");
aoqi@0 229 Handle k(((ConstantOopReadValue*)kv)->value()());
aoqi@0 230 assert(java_lang_Class::is_instance(k()), "must be");
aoqi@0 231 result->push(new MonitorInfo(k(), resolve_monitor_lock(mv->basic_lock()),
aoqi@0 232 mv->eliminated(), true));
aoqi@0 233 } else {
aoqi@0 234 result->push(new MonitorInfo(owner_sv->get_obj()(), resolve_monitor_lock(mv->basic_lock()),
aoqi@0 235 mv->eliminated(), false));
aoqi@0 236 }
aoqi@0 237 }
aoqi@0 238 return result;
aoqi@0 239 }
aoqi@0 240
aoqi@0 241
aoqi@0 242 compiledVFrame::compiledVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread, nmethod* nm)
aoqi@0 243 : javaVFrame(fr, reg_map, thread) {
aoqi@0 244 _scope = NULL;
aoqi@0 245 // Compiled method (native stub or Java code)
aoqi@0 246 // native wrappers have no scope data, it is implied
aoqi@0 247 if (!nm->is_native_method()) {
aoqi@0 248 _scope = nm->scope_desc_at(_fr.pc());
aoqi@0 249 }
aoqi@0 250 }
aoqi@0 251
aoqi@0 252 compiledVFrame::compiledVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread, ScopeDesc* scope)
aoqi@0 253 : javaVFrame(fr, reg_map, thread) {
aoqi@0 254 _scope = scope;
aoqi@0 255 guarantee(_scope != NULL, "scope must be present");
aoqi@0 256 }
aoqi@0 257
aoqi@0 258
aoqi@0 259 bool compiledVFrame::is_top() const {
aoqi@0 260 // FIX IT: Remove this when new native stubs are in place
aoqi@0 261 if (scope() == NULL) return true;
aoqi@0 262 return scope()->is_top();
aoqi@0 263 }
aoqi@0 264
aoqi@0 265
aoqi@0 266 nmethod* compiledVFrame::code() const {
aoqi@0 267 return CodeCache::find_nmethod(_fr.pc());
aoqi@0 268 }
aoqi@0 269
aoqi@0 270
aoqi@0 271 Method* compiledVFrame::method() const {
aoqi@0 272 if (scope() == NULL) {
aoqi@0 273 // native nmethods have no scope the method is implied
aoqi@0 274 nmethod* nm = code();
aoqi@0 275 assert(nm->is_native_method(), "must be native");
aoqi@0 276 return nm->method();
aoqi@0 277 }
aoqi@0 278 return scope()->method();
aoqi@0 279 }
aoqi@0 280
aoqi@0 281
aoqi@0 282 int compiledVFrame::bci() const {
aoqi@0 283 int raw = raw_bci();
aoqi@0 284 return raw == SynchronizationEntryBCI ? 0 : raw;
aoqi@0 285 }
aoqi@0 286
aoqi@0 287
aoqi@0 288 int compiledVFrame::raw_bci() const {
aoqi@0 289 if (scope() == NULL) {
aoqi@0 290 // native nmethods have no scope the method/bci is implied
aoqi@0 291 nmethod* nm = code();
aoqi@0 292 assert(nm->is_native_method(), "must be native");
aoqi@0 293 return 0;
aoqi@0 294 }
aoqi@0 295 return scope()->bci();
aoqi@0 296 }
aoqi@0 297
aoqi@0 298 bool compiledVFrame::should_reexecute() const {
aoqi@0 299 if (scope() == NULL) {
aoqi@0 300 // native nmethods have no scope the method/bci is implied
aoqi@0 301 nmethod* nm = code();
aoqi@0 302 assert(nm->is_native_method(), "must be native");
aoqi@0 303 return false;
aoqi@0 304 }
aoqi@0 305 return scope()->should_reexecute();
aoqi@0 306 }
aoqi@0 307
aoqi@0 308 vframe* compiledVFrame::sender() const {
aoqi@0 309 const frame f = fr();
aoqi@0 310 if (scope() == NULL) {
aoqi@0 311 // native nmethods have no scope the method/bci is implied
aoqi@0 312 nmethod* nm = code();
aoqi@0 313 assert(nm->is_native_method(), "must be native");
aoqi@0 314 return vframe::sender();
aoqi@0 315 } else {
aoqi@0 316 return scope()->is_top()
aoqi@0 317 ? vframe::sender()
aoqi@0 318 : new compiledVFrame(&f, register_map(), thread(), scope()->sender());
aoqi@0 319 }
aoqi@0 320 }
aoqi@0 321
aoqi@0 322 jvmtiDeferredLocalVariableSet::jvmtiDeferredLocalVariableSet(Method* method, int bci, intptr_t* id) {
aoqi@0 323 _method = method;
aoqi@0 324 _bci = bci;
aoqi@0 325 _id = id;
aoqi@0 326 // Alway will need at least one, must be on C heap
aoqi@0 327 _locals = new(ResourceObj::C_HEAP, mtCompiler) GrowableArray<jvmtiDeferredLocalVariable*> (1, true);
aoqi@0 328 }
aoqi@0 329
aoqi@0 330 jvmtiDeferredLocalVariableSet::~jvmtiDeferredLocalVariableSet() {
aoqi@0 331 for (int i = 0; i < _locals->length() ; i++ ) {
aoqi@0 332 delete _locals->at(i);
aoqi@0 333 }
aoqi@0 334 // Free growableArray and c heap for elements
aoqi@0 335 delete _locals;
aoqi@0 336 }
aoqi@0 337
aoqi@0 338 bool jvmtiDeferredLocalVariableSet::matches(vframe* vf) {
aoqi@0 339 if (!vf->is_compiled_frame()) return false;
aoqi@0 340 compiledVFrame* cvf = (compiledVFrame*)vf;
aoqi@0 341 return cvf->fr().id() == id() && cvf->method() == method() && cvf->bci() == bci();
aoqi@0 342 }
aoqi@0 343
aoqi@0 344 void jvmtiDeferredLocalVariableSet::set_local_at(int idx, BasicType type, jvalue val) {
aoqi@0 345 int i;
aoqi@0 346 for ( i = 0 ; i < locals()->length() ; i++ ) {
aoqi@0 347 if ( locals()->at(i)->index() == idx) {
aoqi@0 348 assert(locals()->at(i)->type() == type, "Wrong type");
aoqi@0 349 locals()->at(i)->set_value(val);
aoqi@0 350 return;
aoqi@0 351 }
aoqi@0 352 }
aoqi@0 353 locals()->push(new jvmtiDeferredLocalVariable(idx, type, val));
aoqi@0 354 }
aoqi@0 355
aoqi@0 356 void jvmtiDeferredLocalVariableSet::oops_do(OopClosure* f) {
aoqi@0 357 // The Method* is on the stack so a live activation keeps it alive
aoqi@0 358 // either by mirror in interpreter or code in compiled code.
aoqi@0 359 for ( int i = 0; i < locals()->length(); i++ ) {
aoqi@0 360 if ( locals()->at(i)->type() == T_OBJECT) {
aoqi@0 361 f->do_oop(locals()->at(i)->oop_addr());
aoqi@0 362 }
aoqi@0 363 }
aoqi@0 364 }
aoqi@0 365
aoqi@0 366 jvmtiDeferredLocalVariable::jvmtiDeferredLocalVariable(int index, BasicType type, jvalue value) {
aoqi@0 367 _index = index;
aoqi@0 368 _type = type;
aoqi@0 369 _value = value;
aoqi@0 370 }
aoqi@0 371
aoqi@0 372
aoqi@0 373 #ifndef PRODUCT
aoqi@0 374 void compiledVFrame::verify() const {
aoqi@0 375 Unimplemented();
aoqi@0 376 }
aoqi@0 377 #endif // PRODUCT

mercurial