annotate src/share/vm/runtime/vframe_hp.cpp @ 0:a61af66fc99e

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children d3cd40645d0d
rev   line source
duke@0 1 /*
duke@0 2 * Copyright 1997-2006 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),
duke@0 193 fr.compiled_synchronized_native_monitor(nm));
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);
duke@0 204 StackValue *owner_sv = create_stack_value(mv->owner()); // it is an oop
duke@0 205 result->push(new MonitorInfo(owner_sv->get_obj()(), resolve_monitor_lock(mv->basic_lock())));
duke@0 206 }
duke@0 207 return result;
duke@0 208 }
duke@0 209
duke@0 210
duke@0 211 compiledVFrame::compiledVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread, nmethod* nm)
duke@0 212 : javaVFrame(fr, reg_map, thread) {
duke@0 213 _scope = NULL;
duke@0 214 // Compiled method (native stub or Java code)
duke@0 215 // native wrappers have no scope data, it is implied
duke@0 216 if (!nm->is_native_method()) {
duke@0 217 _scope = nm->scope_desc_at(_fr.pc());
duke@0 218 }
duke@0 219 }
duke@0 220
duke@0 221 compiledVFrame::compiledVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread, ScopeDesc* scope)
duke@0 222 : javaVFrame(fr, reg_map, thread) {
duke@0 223 _scope = scope;
duke@0 224 guarantee(_scope != NULL, "scope must be present");
duke@0 225 }
duke@0 226
duke@0 227
duke@0 228 bool compiledVFrame::is_top() const {
duke@0 229 // FIX IT: Remove this when new native stubs are in place
duke@0 230 if (scope() == NULL) return true;
duke@0 231 return scope()->is_top();
duke@0 232 }
duke@0 233
duke@0 234
duke@0 235 nmethod* compiledVFrame::code() const {
duke@0 236 return CodeCache::find_nmethod(_fr.pc());
duke@0 237 }
duke@0 238
duke@0 239
duke@0 240 methodOop compiledVFrame::method() const {
duke@0 241 if (scope() == NULL) {
duke@0 242 // native nmethods have no scope the method is implied
duke@0 243 nmethod* nm = code();
duke@0 244 assert(nm->is_native_method(), "must be native");
duke@0 245 return nm->method();
duke@0 246 }
duke@0 247 return scope()->method()();
duke@0 248 }
duke@0 249
duke@0 250
duke@0 251 int compiledVFrame::bci() const {
duke@0 252 int raw = raw_bci();
duke@0 253 return raw == SynchronizationEntryBCI ? 0 : raw;
duke@0 254 }
duke@0 255
duke@0 256
duke@0 257 int compiledVFrame::raw_bci() const {
duke@0 258 if (scope() == NULL) {
duke@0 259 // native nmethods have no scope the method/bci is implied
duke@0 260 nmethod* nm = code();
duke@0 261 assert(nm->is_native_method(), "must be native");
duke@0 262 return 0;
duke@0 263 }
duke@0 264 return scope()->bci();
duke@0 265 }
duke@0 266
duke@0 267
duke@0 268 vframe* compiledVFrame::sender() const {
duke@0 269 const frame f = fr();
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 vframe::sender();
duke@0 275 } else {
duke@0 276 return scope()->is_top()
duke@0 277 ? vframe::sender()
duke@0 278 : new compiledVFrame(&f, register_map(), thread(), scope()->sender());
duke@0 279 }
duke@0 280 }
duke@0 281
duke@0 282 jvmtiDeferredLocalVariableSet::jvmtiDeferredLocalVariableSet(methodOop method, int bci, intptr_t* id) {
duke@0 283 _method = method;
duke@0 284 _bci = bci;
duke@0 285 _id = id;
duke@0 286 // Alway will need at least one, must be on C heap
duke@0 287 _locals = new(ResourceObj::C_HEAP) GrowableArray<jvmtiDeferredLocalVariable*> (1, true);
duke@0 288 }
duke@0 289
duke@0 290 jvmtiDeferredLocalVariableSet::~jvmtiDeferredLocalVariableSet() {
duke@0 291 for (int i = 0; i < _locals->length() ; i++ ) {
duke@0 292 delete _locals->at(i);
duke@0 293 }
duke@0 294 // Free growableArray and c heap for elements
duke@0 295 delete _locals;
duke@0 296 }
duke@0 297
duke@0 298 bool jvmtiDeferredLocalVariableSet::matches(vframe* vf) {
duke@0 299 if (!vf->is_compiled_frame()) return false;
duke@0 300 compiledVFrame* cvf = (compiledVFrame*)vf;
duke@0 301 return cvf->fr().id() == id() && cvf->method() == method() && cvf->bci() == bci();
duke@0 302 }
duke@0 303
duke@0 304 void jvmtiDeferredLocalVariableSet::set_local_at(int idx, BasicType type, jvalue val) {
duke@0 305 int i;
duke@0 306 for ( i = 0 ; i < locals()->length() ; i++ ) {
duke@0 307 if ( locals()->at(i)->index() == idx) {
duke@0 308 assert(locals()->at(i)->type() == type, "Wrong type");
duke@0 309 locals()->at(i)->set_value(val);
duke@0 310 return;
duke@0 311 }
duke@0 312 }
duke@0 313 locals()->push(new jvmtiDeferredLocalVariable(idx, type, val));
duke@0 314 }
duke@0 315
duke@0 316 void jvmtiDeferredLocalVariableSet::oops_do(OopClosure* f) {
duke@0 317
duke@0 318 f->do_oop((oop*) &_method);
duke@0 319 for ( int i = 0; i < locals()->length(); i++ ) {
duke@0 320 if ( locals()->at(i)->type() == T_OBJECT) {
duke@0 321 f->do_oop(locals()->at(i)->oop_addr());
duke@0 322 }
duke@0 323 }
duke@0 324 }
duke@0 325
duke@0 326 jvmtiDeferredLocalVariable::jvmtiDeferredLocalVariable(int index, BasicType type, jvalue value) {
duke@0 327 _index = index;
duke@0 328 _type = type;
duke@0 329 _value = value;
duke@0 330 }
duke@0 331
duke@0 332
duke@0 333 #ifndef PRODUCT
duke@0 334 void compiledVFrame::verify() const {
duke@0 335 Unimplemented();
duke@0 336 }
duke@0 337 #endif // PRODUCT