src/share/vm/runtime/vframe_hp.cpp

Thu, 24 Nov 2016 11:27:57 +0100

author
tschatzl
date
Thu, 24 Nov 2016 11:27:57 +0100
changeset 9982
72053ed6f8d4
parent 4037
da91efe96a93
child 6876
710a3c8b516e
permissions
-rw-r--r--

8057003: Large reference arrays cause extremely long synchronization times
Summary: Slice large object arrays into parts so that the synchronization of marking threads with an STW pause request does not take long.
Reviewed-by: ehelin, pliden
Contributed-by: maoliang.ml@alibaba-inc.com

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

mercurial