src/share/vm/runtime/vframe_hp.cpp

Thu, 10 Apr 2008 15:49:16 -0400

author
sbohne
date
Thu, 10 Apr 2008 15:49:16 -0400
changeset 528
c6ff24ceec1c
parent 518
d3cd40645d0d
child 631
d1605aabd0a1
permissions
-rw-r--r--

6686407: Fix for 6666698 broke -XX:BiasedLockingStartupDelay=0
Summary: Stack allocated VM_EnableBiasedLocking op must be marked as such
Reviewed-by: xlu, acorn, never, dholmes

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

mercurial