annotate src/share/vm/runtime/vframe_hp.cpp @ 900:9987d9d5eb0e

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