annotate src/hotspot/share/runtime/vframe_hp.cpp @ 52291:35a6956f4243

8209976: Improve iteration over non-JavaThreads Summary: Add NonJavaThread and move NamedThread iteration to new class. Reviewed-by: eosterlund, coleenp, rkennke
author kbarrett
date Tue, 28 Aug 2018 16:04:54 -0400
parents 7fc3d62481ba
children 6954394aa33a
rev   line source
duke@1 1 /*
coleenp@49945 2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
trims@5547 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@5547 20 * or visit www.oracle.com if you need additional information or have any
trims@5547 21 * questions.
duke@1 22 *
duke@1 23 */
duke@1 24
stefank@7397 25 #include "precompiled.hpp"
stefank@29081 26 #include "classfile/javaClasses.inline.hpp"
stefank@7397 27 #include "code/codeCache.hpp"
stefank@7397 28 #include "code/debugInfoRec.hpp"
stefank@7397 29 #include "code/nmethod.hpp"
stefank@7397 30 #include "code/pcDesc.hpp"
stefank@7397 31 #include "code/scopeDesc.hpp"
stefank@7397 32 #include "interpreter/interpreter.hpp"
stefank@7397 33 #include "interpreter/oopMapCache.hpp"
stefank@7397 34 #include "oops/instanceKlass.hpp"
stefank@7397 35 #include "oops/oop.inline.hpp"
stefank@7397 36 #include "runtime/basicLock.hpp"
coleenp@49945 37 #include "runtime/frame.inline.hpp"
stefank@7397 38 #include "runtime/handles.inline.hpp"
stefank@7397 39 #include "runtime/monitorChunk.hpp"
stefank@7397 40 #include "runtime/signature.hpp"
stefank@7397 41 #include "runtime/stubRoutines.hpp"
stefank@7397 42 #include "runtime/vframeArray.hpp"
stefank@7397 43 #include "runtime/vframe_hp.hpp"
stefank@7397 44 #ifdef COMPILER2
stefank@7397 45 #include "opto/matcher.hpp"
stefank@7397 46 #endif
duke@1 47
duke@1 48
duke@1 49 // ------------- compiledVFrame --------------
duke@1 50
duke@1 51 StackValueCollection* compiledVFrame::locals() const {
duke@1 52 // Natives has no scope
duke@1 53 if (scope() == NULL) return new StackValueCollection(0);
duke@1 54 GrowableArray<ScopeValue*>* scv_list = scope()->locals();
duke@1 55 if (scv_list == NULL) return new StackValueCollection(0);
duke@1 56
duke@1 57 // scv_list is the list of ScopeValues describing the JVM stack state.
duke@1 58 // There is one scv_list entry for every JVM stack state in use.
duke@1 59 int length = scv_list->length();
duke@1 60 StackValueCollection* result = new StackValueCollection(length);
never@48910 61 for (int i = 0; i < length; i++) {
never@48910 62 result->add(create_stack_value(scv_list->at(i)));
never@48910 63 }
never@48910 64
never@48910 65 // Replace the original values with any stores that have been
never@48910 66 // performed through compiledVFrame::update_locals.
duke@1 67 GrowableArray<jvmtiDeferredLocalVariableSet*>* list = thread()->deferred_locals();
duke@1 68 if (list != NULL ) {
duke@1 69 // In real life this never happens or is typically a single element search
duke@1 70 for (int i = 0; i < list->length(); i++) {
never@48910 71 if (list->at(i)->matches(this)) {
never@48910 72 list->at(i)->update_locals(result);
duke@1 73 break;
duke@1 74 }
duke@1 75 }
duke@1 76 }
duke@1 77
duke@1 78 return result;
duke@1 79 }
duke@1 80
duke@1 81
duke@1 82 void compiledVFrame::set_locals(StackValueCollection* values) const {
duke@1 83
duke@1 84 fatal("Should use update_local for each local update");
duke@1 85 }
duke@1 86
duke@1 87 void compiledVFrame::update_local(BasicType type, int index, jvalue value) {
never@48910 88 assert(index >= 0 && index < method()->max_locals(), "out of bounds");
never@48910 89 update_deferred_value(type, index, value);
never@48910 90 }
duke@1 91
never@48910 92 void compiledVFrame::update_stack(BasicType type, int index, jvalue value) {
never@48910 93 assert(index >= 0 && index < method()->max_stack(), "out of bounds");
never@48910 94 update_deferred_value(type, index + method()->max_locals(), value);
never@48910 95 }
duke@1 96
never@48910 97 void compiledVFrame::update_monitor(int index, MonitorInfo* val) {
never@48910 98 assert(index >= 0, "out of bounds");
never@48910 99 jvalue value;
never@48910 100 value.l = (jobject) val->owner();
never@48910 101 update_deferred_value(T_OBJECT, index + method()->max_locals() + method()->max_stack(), value);
never@48910 102 }
never@48910 103
never@48910 104 void compiledVFrame::update_deferred_value(BasicType type, int index, jvalue value) {
duke@1 105 assert(fr().is_deoptimized_frame(), "frame must be scheduled for deoptimization");
duke@1 106 GrowableArray<jvmtiDeferredLocalVariableSet*>* deferred = thread()->deferred_locals();
never@48910 107 jvmtiDeferredLocalVariableSet* locals = NULL;
duke@1 108 if (deferred != NULL ) {
duke@1 109 // See if this vframe has already had locals with deferred writes
never@48910 110 for (int f = 0; f < deferred->length(); f++ ) {
duke@1 111 if (deferred->at(f)->matches(this)) {
never@48910 112 locals = deferred->at(f);
never@48910 113 break;
duke@1 114 }
duke@1 115 }
duke@1 116 // No matching vframe must push a new vframe
duke@1 117 } else {
duke@1 118 // No deferred updates pending for this thread.
duke@1 119 // allocate in C heap
zgu@13195 120 deferred = new(ResourceObj::C_HEAP, mtCompiler) GrowableArray<jvmtiDeferredLocalVariableSet*> (1, true);
duke@1 121 thread()->set_deferred_locals(deferred);
duke@1 122 }
never@48910 123 if (locals == NULL) {
never@48910 124 locals = new jvmtiDeferredLocalVariableSet(method(), bci(), fr().id(), vframe_id());
never@48910 125 deferred->push(locals);
never@48910 126 assert(locals->id() == fr().id(), "Huh? Must match");
never@48910 127 }
never@48910 128 locals->set_value_at(index, type, value);
duke@1 129 }
duke@1 130
duke@1 131 StackValueCollection* compiledVFrame::expressions() const {
duke@1 132 // Natives has no scope
duke@1 133 if (scope() == NULL) return new StackValueCollection(0);
duke@1 134 GrowableArray<ScopeValue*>* scv_list = scope()->expressions();
duke@1 135 if (scv_list == NULL) return new StackValueCollection(0);
duke@1 136
duke@1 137 // scv_list is the list of ScopeValues describing the JVM stack state.
duke@1 138 // There is one scv_list entry for every JVM stack state in use.
duke@1 139 int length = scv_list->length();
duke@1 140 StackValueCollection* result = new StackValueCollection(length);
never@48910 141 for (int i = 0; i < length; i++) {
never@48910 142 result->add(create_stack_value(scv_list->at(i)));
never@48910 143 }
never@48910 144
never@48910 145 // Replace the original values with any stores that have been
never@48910 146 // performed through compiledVFrame::update_stack.
never@48910 147 GrowableArray<jvmtiDeferredLocalVariableSet*>* list = thread()->deferred_locals();
never@48910 148 if (list != NULL ) {
never@48910 149 // In real life this never happens or is typically a single element search
never@48910 150 for (int i = 0; i < list->length(); i++) {
never@48910 151 if (list->at(i)->matches(this)) {
never@48910 152 list->at(i)->update_stack(result);
never@48910 153 break;
never@48910 154 }
never@48910 155 }
never@48910 156 }
duke@1 157
duke@1 158 return result;
duke@1 159 }
duke@1 160
duke@1 161
duke@1 162 // The implementation of the following two methods was factorized into the
duke@1 163 // class StackValue because it is also used from within deoptimization.cpp for
duke@1 164 // rematerialization and relocking of non-escaping objects.
duke@1 165
duke@1 166 StackValue *compiledVFrame::create_stack_value(ScopeValue *sv) const {
duke@1 167 return StackValue::create_stack_value(&_fr, register_map(), sv);
duke@1 168 }
duke@1 169
duke@1 170 BasicLock* compiledVFrame::resolve_monitor_lock(Location location) const {
duke@1 171 return StackValue::resolve_monitor_lock(&_fr, location);
duke@1 172 }
duke@1 173
duke@1 174
duke@1 175 GrowableArray<MonitorInfo*>* compiledVFrame::monitors() const {
duke@1 176 // Natives has no scope
duke@1 177 if (scope() == NULL) {
rbackman@38133 178 CompiledMethod* nm = code();
coleenp@13728 179 Method* method = nm->method();
kvn@42650 180 assert(method->is_native() || nm->is_aot(), "Expect a native method or precompiled method");
duke@1 181 if (!method->is_synchronized()) {
duke@1 182 return new GrowableArray<MonitorInfo*>(0);
duke@1 183 }
duke@1 184 // This monitor is really only needed for UseBiasedLocking, but
duke@1 185 // return it in all cases for now as it might be useful for stack
duke@1 186 // traces and tools as well
duke@1 187 GrowableArray<MonitorInfo*> *monitors = new GrowableArray<MonitorInfo*>(1);
duke@1 188 // Casting away const
duke@1 189 frame& fr = (frame&) _fr;
kamg@7444 190 MonitorInfo* info = new MonitorInfo(
kamg@7444 191 fr.get_native_receiver(), fr.get_native_monitor(), false, false);
duke@1 192 monitors->push(info);
duke@1 193 return monitors;
duke@1 194 }
duke@1 195 GrowableArray<MonitorValue*>* monitors = scope()->monitors();
duke@1 196 if (monitors == NULL) {
duke@1 197 return new GrowableArray<MonitorInfo*>(0);
duke@1 198 }
duke@1 199 GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(monitors->length());
duke@1 200 for (int index = 0; index < monitors->length(); index++) {
duke@1 201 MonitorValue* mv = monitors->at(index);
kvn@3171 202 ScopeValue* ov = mv->owner();
kvn@3171 203 StackValue *owner_sv = create_stack_value(ov); // it is an oop
kvn@3171 204 if (ov->is_object() && owner_sv->obj_is_scalar_replaced()) { // The owner object was scalar replaced
kvn@3171 205 assert(mv->eliminated(), "monitor should be eliminated for scalar replaced object");
kvn@3171 206 // Put klass for scalar replaced object.
kvn@3171 207 ScopeValue* kv = ((ObjectValue *)ov)->klass();
kvn@3171 208 assert(kv->is_constant_oop(), "klass should be oop constant for scalar replaced object");
coleenp@46271 209 Handle k(Thread::current(), ((ConstantOopReadValue*)kv)->value()());
coleenp@13728 210 assert(java_lang_Class::is_instance(k()), "must be");
coleenp@13728 211 result->push(new MonitorInfo(k(), resolve_monitor_lock(mv->basic_lock()),
kvn@3171 212 mv->eliminated(), true));
kvn@3171 213 } else {
kvn@3171 214 result->push(new MonitorInfo(owner_sv->get_obj()(), resolve_monitor_lock(mv->basic_lock()),
kvn@3171 215 mv->eliminated(), false));
kvn@3171 216 }
duke@1 217 }
never@48910 218
never@48910 219 // Replace the original values with any stores that have been
never@48910 220 // performed through compiledVFrame::update_monitors.
never@48910 221 GrowableArray<jvmtiDeferredLocalVariableSet*>* list = thread()->deferred_locals();
never@48910 222 if (list != NULL ) {
never@48910 223 // In real life this never happens or is typically a single element search
never@48910 224 for (int i = 0; i < list->length(); i++) {
never@48910 225 if (list->at(i)->matches(this)) {
never@48910 226 list->at(i)->update_monitors(result);
never@48910 227 break;
never@48910 228 }
never@48910 229 }
never@48910 230 }
never@48910 231
duke@1 232 return result;
duke@1 233 }
duke@1 234
duke@1 235
rbackman@38133 236 compiledVFrame::compiledVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread, CompiledMethod* nm)
duke@1 237 : javaVFrame(fr, reg_map, thread) {
duke@1 238 _scope = NULL;
never@43484 239 _vframe_id = 0;
duke@1 240 // Compiled method (native stub or Java code)
duke@1 241 // native wrappers have no scope data, it is implied
rbackman@38133 242 if (!nm->is_compiled() || !nm->as_compiled_method()->is_native_method()) {
rbackman@38133 243 _scope = nm->scope_desc_at(_fr.pc());
duke@1 244 }
duke@1 245 }
duke@1 246
never@43484 247 compiledVFrame::compiledVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread, ScopeDesc* scope, int vframe_id)
duke@1 248 : javaVFrame(fr, reg_map, thread) {
duke@1 249 _scope = scope;
never@43484 250 _vframe_id = vframe_id;
duke@1 251 guarantee(_scope != NULL, "scope must be present");
duke@1 252 }
duke@1 253
duke@1 254
duke@1 255 bool compiledVFrame::is_top() const {
duke@1 256 // FIX IT: Remove this when new native stubs are in place
duke@1 257 if (scope() == NULL) return true;
duke@1 258 return scope()->is_top();
duke@1 259 }
duke@1 260
duke@1 261
rbackman@38133 262 CompiledMethod* compiledVFrame::code() const {
rbackman@38133 263 return CodeCache::find_compiled(_fr.pc());
duke@1 264 }
duke@1 265
duke@1 266
coleenp@13728 267 Method* compiledVFrame::method() const {
duke@1 268 if (scope() == NULL) {
duke@1 269 // native nmethods have no scope the method is implied
rbackman@38133 270 nmethod* nm = code()->as_nmethod();
duke@1 271 assert(nm->is_native_method(), "must be native");
duke@1 272 return nm->method();
duke@1 273 }
coleenp@13728 274 return scope()->method();
duke@1 275 }
duke@1 276
duke@1 277
duke@1 278 int compiledVFrame::bci() const {
duke@1 279 int raw = raw_bci();
duke@1 280 return raw == SynchronizationEntryBCI ? 0 : raw;
duke@1 281 }
duke@1 282
duke@1 283
duke@1 284 int compiledVFrame::raw_bci() const {
duke@1 285 if (scope() == NULL) {
duke@1 286 // native nmethods have no scope the method/bci is implied
rbackman@38133 287 nmethod* nm = code()->as_nmethod();
duke@1 288 assert(nm->is_native_method(), "must be native");
duke@1 289 return 0;
duke@1 290 }
duke@1 291 return scope()->bci();
duke@1 292 }
duke@1 293
cfang@3600 294 bool compiledVFrame::should_reexecute() const {
cfang@3600 295 if (scope() == NULL) {
cfang@3600 296 // native nmethods have no scope the method/bci is implied
rbackman@38133 297 nmethod* nm = code()->as_nmethod();
cfang@3600 298 assert(nm->is_native_method(), "must be native");
cfang@3600 299 return false;
cfang@3600 300 }
cfang@3600 301 return scope()->should_reexecute();
cfang@3600 302 }
duke@1 303
duke@1 304 vframe* compiledVFrame::sender() const {
duke@1 305 const frame f = fr();
duke@1 306 if (scope() == NULL) {
duke@1 307 // native nmethods have no scope the method/bci is implied
rbackman@38133 308 nmethod* nm = code()->as_nmethod();
duke@1 309 assert(nm->is_native_method(), "must be native");
duke@1 310 return vframe::sender();
duke@1 311 } else {
duke@1 312 return scope()->is_top()
duke@1 313 ? vframe::sender()
never@43484 314 : new compiledVFrame(&f, register_map(), thread(), scope()->sender(), vframe_id() + 1);
duke@1 315 }
duke@1 316 }
duke@1 317
never@43484 318 jvmtiDeferredLocalVariableSet::jvmtiDeferredLocalVariableSet(Method* method, int bci, intptr_t* id, int vframe_id) {
duke@1 319 _method = method;
duke@1 320 _bci = bci;
duke@1 321 _id = id;
never@43484 322 _vframe_id = vframe_id;
duke@1 323 // Alway will need at least one, must be on C heap
zgu@13195 324 _locals = new(ResourceObj::C_HEAP, mtCompiler) GrowableArray<jvmtiDeferredLocalVariable*> (1, true);
duke@1 325 }
duke@1 326
duke@1 327 jvmtiDeferredLocalVariableSet::~jvmtiDeferredLocalVariableSet() {
never@48910 328 for (int i = 0; i < _locals->length(); i++ ) {
duke@1 329 delete _locals->at(i);
duke@1 330 }
duke@1 331 // Free growableArray and c heap for elements
duke@1 332 delete _locals;
duke@1 333 }
duke@1 334
never@48910 335 bool jvmtiDeferredLocalVariableSet::matches(const vframe* vf) {
duke@1 336 if (!vf->is_compiled_frame()) return false;
duke@1 337 compiledVFrame* cvf = (compiledVFrame*)vf;
never@43484 338 if (cvf->fr().id() == id() && cvf->vframe_id() == vframe_id()) {
never@43484 339 assert(cvf->method() == method() && cvf->bci() == bci(), "must agree");
never@43484 340 return true;
never@43484 341 }
never@43484 342 return false;
duke@1 343 }
duke@1 344
never@48910 345 void jvmtiDeferredLocalVariableSet::set_value_at(int idx, BasicType type, jvalue val) {
never@48910 346 for (int i = 0; i < _locals->length(); i++) {
never@48910 347 if (_locals->at(i)->index() == idx) {
never@48910 348 assert(_locals->at(i)->type() == type, "Wrong type");
never@48910 349 _locals->at(i)->set_value(val);
duke@1 350 return;
duke@1 351 }
duke@1 352 }
never@48910 353 _locals->push(new jvmtiDeferredLocalVariable(idx, type, val));
duke@1 354 }
duke@1 355
never@48910 356 void jvmtiDeferredLocalVariableSet::update_value(StackValueCollection* locals, BasicType type, int index, jvalue value) {
never@48910 357 switch (type) {
never@48910 358 case T_BOOLEAN:
never@48910 359 locals->set_int_at(index, value.z);
never@48910 360 break;
never@48910 361 case T_CHAR:
never@48910 362 locals->set_int_at(index, value.c);
never@48910 363 break;
never@48910 364 case T_FLOAT:
never@48910 365 locals->set_float_at(index, value.f);
never@48910 366 break;
never@48910 367 case T_DOUBLE:
never@48910 368 locals->set_double_at(index, value.d);
never@48910 369 break;
never@48910 370 case T_BYTE:
never@48910 371 locals->set_int_at(index, value.b);
never@48910 372 break;
never@48910 373 case T_SHORT:
never@48910 374 locals->set_int_at(index, value.s);
never@48910 375 break;
never@48910 376 case T_INT:
never@48910 377 locals->set_int_at(index, value.i);
never@48910 378 break;
never@48910 379 case T_LONG:
never@48910 380 locals->set_long_at(index, value.j);
never@48910 381 break;
never@48910 382 case T_OBJECT:
never@48910 383 {
never@48910 384 Handle obj(Thread::current(), (oop)value.l);
never@48910 385 locals->set_obj_at(index, obj);
never@48910 386 }
never@48910 387 break;
never@48910 388 default:
never@48910 389 ShouldNotReachHere();
never@48910 390 }
never@48910 391 }
never@48910 392
never@48910 393 void jvmtiDeferredLocalVariableSet::update_locals(StackValueCollection* locals) {
never@48910 394 for (int l = 0; l < _locals->length(); l ++) {
never@48910 395 jvmtiDeferredLocalVariable* val = _locals->at(l);
never@48910 396 if (val->index() >= 0 && val->index() < method()->max_locals()) {
never@48910 397 update_value(locals, val->type(), val->index(), val->value());
never@48910 398 }
never@48910 399 }
never@48910 400 }
never@48910 401
never@48910 402
never@48910 403 void jvmtiDeferredLocalVariableSet::update_stack(StackValueCollection* expressions) {
never@48910 404 for (int l = 0; l < _locals->length(); l ++) {
never@48910 405 jvmtiDeferredLocalVariable* val = _locals->at(l);
never@48910 406 if (val->index() >= method()->max_locals() && val->index() < method()->max_locals() + method()->max_stack()) {
never@48910 407 update_value(expressions, val->type(), val->index() - method()->max_locals(), val->value());
never@48910 408 }
never@48910 409 }
never@48910 410 }
never@48910 411
never@48910 412
never@48910 413 void jvmtiDeferredLocalVariableSet::update_monitors(GrowableArray<MonitorInfo*>* monitors) {
never@48910 414 for (int l = 0; l < _locals->length(); l ++) {
never@48910 415 jvmtiDeferredLocalVariable* val = _locals->at(l);
never@48910 416 if (val->index() >= method()->max_locals() + method()->max_stack()) {
never@48910 417 int lock_index = val->index() - (method()->max_locals() + method()->max_stack());
never@48910 418 MonitorInfo* info = monitors->at(lock_index);
never@48910 419 MonitorInfo* new_info = new MonitorInfo((oopDesc*)val->value().l, info->lock(), info->eliminated(), info->owner_is_scalar_replaced());
never@48910 420 monitors->at_put(lock_index, new_info);
never@48910 421 }
never@48910 422 }
never@48910 423 }
never@48910 424
never@48910 425
duke@1 426 void jvmtiDeferredLocalVariableSet::oops_do(OopClosure* f) {
coleenp@13728 427 // The Method* is on the stack so a live activation keeps it alive
coleenp@13728 428 // either by mirror in interpreter or code in compiled code.
never@48910 429 for (int i = 0; i < _locals->length(); i++) {
never@48910 430 if (_locals->at(i)->type() == T_OBJECT) {
never@48910 431 f->do_oop(_locals->at(i)->oop_addr());
duke@1 432 }
duke@1 433 }
duke@1 434 }
duke@1 435
duke@1 436 jvmtiDeferredLocalVariable::jvmtiDeferredLocalVariable(int index, BasicType type, jvalue value) {
duke@1 437 _index = index;
duke@1 438 _type = type;
duke@1 439 _value = value;
duke@1 440 }
duke@1 441
duke@1 442
duke@1 443 #ifndef PRODUCT
duke@1 444 void compiledVFrame::verify() const {
duke@1 445 Unimplemented();
duke@1 446 }
duke@1 447 #endif // PRODUCT