< prev index next >

src/hotspot/share/runtime/vframe_hp.cpp

Print this page

217   return result;
218 }
219 
220 
221 // The implementation of the following two methods was factorized into the
222 // class StackValue because it is also used from within deoptimization.cpp for
223 // rematerialization and relocking of non-escaping objects.
224 
225 StackValue *compiledVFrame::create_stack_value(ScopeValue *sv) const {
226   stackChunkOop c = _reg_map.stack_chunk()();
227   int index = _reg_map.stack_chunk_index();
228   const_cast<RegisterMap*>(&_reg_map)->set_stack_chunk(_chunk());
229 
230   StackValue* res = StackValue::create_stack_value(&_fr, register_map(), sv);
231 
232   const_cast<RegisterMap*>(&_reg_map)->set_stack_chunk(c);
233   const_cast<RegisterMap*>(&_reg_map)->set_stack_chunk_index(index);
234   return res;
235 }
236 
237 BasicLock* compiledVFrame::resolve_monitor_lock(Location location) const {
238   return StackValue::resolve_monitor_lock(&_fr, location);
239 }
240 
241 
242 GrowableArray<MonitorInfo*>* compiledVFrame::monitors() const {
243   // Natives has no scope
244   if (scope() == NULL) {
245     CompiledMethod* nm = code();
246     Method* method = nm->method();
247     assert(method->is_native(), "Expect a native method");
248     if (!method->is_synchronized()) {
249       return new GrowableArray<MonitorInfo*>(0);
250     }
251     // This monitor is not really needed but return it for now as it might be
252     // useful for stack traces and tools
253     GrowableArray<MonitorInfo*> *monitors = new GrowableArray<MonitorInfo*>(1);
254     // Casting away const
255     frame& fr = (frame&) _fr;
256     MonitorInfo* info = new MonitorInfo(
257         fr.get_native_receiver(), fr.get_native_monitor(), false, false);
258     monitors->push(info);
259     return monitors;
260   }
261   GrowableArray<MonitorValue*>* monitors = scope()->monitors();
262   if (monitors == NULL) {
263     return new GrowableArray<MonitorInfo*>(0);
264   }
265   GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(monitors->length());
266   for (int index = 0; index < monitors->length(); index++) {
267     MonitorValue* mv = monitors->at(index);
268     ScopeValue*   ov = mv->owner();
269     StackValue *owner_sv = create_stack_value(ov); // it is an oop
270     if (ov->is_object() && owner_sv->obj_is_scalar_replaced()) { // The owner object was scalar replaced
271       assert(mv->eliminated(), "monitor should be eliminated for scalar replaced object");
272       // Put klass for scalar replaced object.
273       ScopeValue* kv = ((ObjectValue *)ov)->klass();
274       assert(kv->is_constant_oop(), "klass should be oop constant for scalar replaced object");
275       Handle k(Thread::current(), ((ConstantOopReadValue*)kv)->value()());
276       assert(java_lang_Class::is_instance(k()), "must be");
277       result->push(new MonitorInfo(k(), resolve_monitor_lock(mv->basic_lock()),
278                                    mv->eliminated(), true));
279     } else {
280       result->push(new MonitorInfo(owner_sv->get_obj()(), resolve_monitor_lock(mv->basic_lock()),
281                                    mv->eliminated(), false));
282     }
283   }
284 
285   // Replace the original values with any stores that have been
286   // performed through compiledVFrame::update_monitors.
287   GrowableArray<jvmtiDeferredLocalVariableSet*>* list = JvmtiDeferredUpdates::deferred_locals(thread());
288   if (list != NULL ) {
289     // In real life this never happens or is typically a single element search
290     for (int i = 0; i < list->length(); i++) {
291       if (list->at(i)->matches(this)) {
292         list->at(i)->update_monitors(result);
293         break;
294       }
295     }
296   }
297 
298   return result;
299 }
300 
301 

495 
496 void jvmtiDeferredLocalVariableSet::update_stack(StackValueCollection* expressions) {
497   for (int l = 0; l < _locals->length(); l ++) {
498     jvmtiDeferredLocalVariable* val = _locals->at(l);
499     if (val->index() >= method()->max_locals() && val->index() < method()->max_locals() + method()->max_stack()) {
500       update_value(expressions, val->type(), val->index() - method()->max_locals(), val->value());
501     }
502   }
503 }
504 
505 
506 void jvmtiDeferredLocalVariableSet::update_monitors(GrowableArray<MonitorInfo*>* monitors) {
507   for (int l = 0; l < _locals->length(); l ++) {
508     jvmtiDeferredLocalVariable* val = _locals->at(l);
509     if (val->index() >= method()->max_locals() + method()->max_stack()) {
510       int lock_index = val->index() - (method()->max_locals() + method()->max_stack());
511       MonitorInfo* info = monitors->at(lock_index);
512       // Originally the owner may have been scalar replaced but as an update
513       // exists it must have been deoptimized, i.e. reallocated to the heap, and
514       // now it is considered not to be scalar replaced.
515       MonitorInfo* new_info = new MonitorInfo((oopDesc*)val->value().l, info->lock(),
516                                               info->eliminated(), false);
517       monitors->at_put(lock_index, new_info);
518     }
519   }
520 }
521 
522 
523 void jvmtiDeferredLocalVariableSet::oops_do(OopClosure* f) {
524   // The Method* is on the stack so a live activation keeps it alive
525   // either by mirror in interpreter or code in compiled code.
526   for (int i = 0; i < _locals->length(); i++) {
527     if (_locals->at(i)->type() == T_OBJECT) {
528       f->do_oop(_locals->at(i)->oop_addr());
529     }
530   }
531 }
532 
533 jvmtiDeferredLocalVariable::jvmtiDeferredLocalVariable(int index, BasicType type, jvalue value) {
534   _index = index;
535   _type = type;
536   _value = value;

217   return result;
218 }
219 
220 
221 // The implementation of the following two methods was factorized into the
222 // class StackValue because it is also used from within deoptimization.cpp for
223 // rematerialization and relocking of non-escaping objects.
224 
225 StackValue *compiledVFrame::create_stack_value(ScopeValue *sv) const {
226   stackChunkOop c = _reg_map.stack_chunk()();
227   int index = _reg_map.stack_chunk_index();
228   const_cast<RegisterMap*>(&_reg_map)->set_stack_chunk(_chunk());
229 
230   StackValue* res = StackValue::create_stack_value(&_fr, register_map(), sv);
231 
232   const_cast<RegisterMap*>(&_reg_map)->set_stack_chunk(c);
233   const_cast<RegisterMap*>(&_reg_map)->set_stack_chunk_index(index);
234   return res;
235 }
236 




237 
238 GrowableArray<MonitorInfo*>* compiledVFrame::monitors() const {
239   // Natives has no scope
240   if (scope() == NULL) {
241     CompiledMethod* nm = code();
242     Method* method = nm->method();
243     assert(method->is_native(), "Expect a native method");
244     if (!method->is_synchronized()) {
245       return new GrowableArray<MonitorInfo*>(0);
246     }
247     // This monitor is not really needed but return it for now as it might be
248     // useful for stack traces and tools
249     GrowableArray<MonitorInfo*> *monitors = new GrowableArray<MonitorInfo*>(1);
250     // Casting away const
251     frame& fr = (frame&) _fr;
252     MonitorInfo* info = new MonitorInfo(
253         fr.get_native_receiver(), false, false);
254     monitors->push(info);
255     return monitors;
256   }
257   GrowableArray<MonitorValue*>* monitors = scope()->monitors();
258   if (monitors == NULL) {
259     return new GrowableArray<MonitorInfo*>(0);
260   }
261   GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(monitors->length());
262   for (int index = 0; index < monitors->length(); index++) {
263     MonitorValue* mv = monitors->at(index);
264     ScopeValue*   ov = mv->owner();
265     StackValue *owner_sv = create_stack_value(ov); // it is an oop
266     if (ov->is_object() && owner_sv->obj_is_scalar_replaced()) { // The owner object was scalar replaced
267       assert(mv->eliminated(), "monitor should be eliminated for scalar replaced object");
268       // Put klass for scalar replaced object.
269       ScopeValue* kv = ((ObjectValue *)ov)->klass();
270       assert(kv->is_constant_oop(), "klass should be oop constant for scalar replaced object");
271       Handle k(Thread::current(), ((ConstantOopReadValue*)kv)->value()());
272       assert(java_lang_Class::is_instance(k()), "must be");
273       result->push(new MonitorInfo(k(), mv->eliminated(), true));

274     } else {
275       result->push(new MonitorInfo(owner_sv->get_obj()(), mv->eliminated(), false));

276     }
277   }
278 
279   // Replace the original values with any stores that have been
280   // performed through compiledVFrame::update_monitors.
281   GrowableArray<jvmtiDeferredLocalVariableSet*>* list = JvmtiDeferredUpdates::deferred_locals(thread());
282   if (list != NULL ) {
283     // In real life this never happens or is typically a single element search
284     for (int i = 0; i < list->length(); i++) {
285       if (list->at(i)->matches(this)) {
286         list->at(i)->update_monitors(result);
287         break;
288       }
289     }
290   }
291 
292   return result;
293 }
294 
295 

489 
490 void jvmtiDeferredLocalVariableSet::update_stack(StackValueCollection* expressions) {
491   for (int l = 0; l < _locals->length(); l ++) {
492     jvmtiDeferredLocalVariable* val = _locals->at(l);
493     if (val->index() >= method()->max_locals() && val->index() < method()->max_locals() + method()->max_stack()) {
494       update_value(expressions, val->type(), val->index() - method()->max_locals(), val->value());
495     }
496   }
497 }
498 
499 
500 void jvmtiDeferredLocalVariableSet::update_monitors(GrowableArray<MonitorInfo*>* monitors) {
501   for (int l = 0; l < _locals->length(); l ++) {
502     jvmtiDeferredLocalVariable* val = _locals->at(l);
503     if (val->index() >= method()->max_locals() + method()->max_stack()) {
504       int lock_index = val->index() - (method()->max_locals() + method()->max_stack());
505       MonitorInfo* info = monitors->at(lock_index);
506       // Originally the owner may have been scalar replaced but as an update
507       // exists it must have been deoptimized, i.e. reallocated to the heap, and
508       // now it is considered not to be scalar replaced.
509       MonitorInfo* new_info = new MonitorInfo((oopDesc*)val->value().l, info->eliminated(), false);

510       monitors->at_put(lock_index, new_info);
511     }
512   }
513 }
514 
515 
516 void jvmtiDeferredLocalVariableSet::oops_do(OopClosure* f) {
517   // The Method* is on the stack so a live activation keeps it alive
518   // either by mirror in interpreter or code in compiled code.
519   for (int i = 0; i < _locals->length(); i++) {
520     if (_locals->at(i)->type() == T_OBJECT) {
521       f->do_oop(_locals->at(i)->oop_addr());
522     }
523   }
524 }
525 
526 jvmtiDeferredLocalVariable::jvmtiDeferredLocalVariable(int index, BasicType type, jvalue value) {
527   _index = index;
528   _type = type;
529   _value = value;
< prev index next >