< prev index next >

src/hotspot/share/runtime/sharedRuntime.cpp

Print this page

2171     // Shouldn't happen, but don't cause even more problems if it does
2172     message = const_cast<char*>(caster_klass->external_name());
2173   } else {
2174     jio_snprintf(message,
2175                  msglen,
2176                  "class %s cannot be cast to class %s (%s%s%s)",
2177                  caster_name,
2178                  target_name,
2179                  caster_klass_description,
2180                  klass_separator,
2181                  target_klass_description
2182                  );
2183   }
2184   return message;
2185 }
2186 
2187 JRT_LEAF(void, SharedRuntime::reguard_yellow_pages())
2188   (void) JavaThread::current()->stack_overflow_state()->reguard_stack();
2189 JRT_END
2190 
2191 void SharedRuntime::monitor_enter_helper(oopDesc* obj, BasicLock* lock, JavaThread* current) {
2192   if (!SafepointSynchronize::is_synchronizing()) {
2193     // Only try quick_enter() if we're not trying to reach a safepoint
2194     // so that the calling thread reaches the safepoint more quickly.
2195     if (ObjectSynchronizer::quick_enter(obj, current, lock)) {
2196       return;
2197     }
2198   }
2199   // NO_ASYNC required because an async exception on the state transition destructor
2200   // would leave you with the lock held and it would never be released.
2201   // The normal monitorenter NullPointerException is thrown without acquiring a lock
2202   // and the model is that an exception implies the method failed.
2203   JRT_BLOCK_NO_ASYNC
2204   Handle h_obj(THREAD, obj);
2205   ObjectSynchronizer::enter(h_obj, lock, current);
2206   assert(!HAS_PENDING_EXCEPTION, "Should have no exception here");
2207   JRT_BLOCK_END
2208 }
2209 
2210 // Handles the uncommon case in locking, i.e., contention or an inflated lock.
2211 JRT_BLOCK_ENTRY(void, SharedRuntime::complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current))
2212   SharedRuntime::monitor_enter_helper(obj, lock, current);
2213 JRT_END
2214 
2215 void SharedRuntime::monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* current) {
2216   assert(JavaThread::current() == current, "invariant");
2217   // Exit must be non-blocking, and therefore no exceptions can be thrown.
2218   ExceptionMark em(current);
2219   // The object could become unlocked through a JNI call, which we have no other checks for.
2220   // Give a fatal message if CheckJNICalls. Otherwise we ignore it.
2221   if (obj->is_unlocked()) {
2222     if (CheckJNICalls) {
2223       fatal("Object has been unlocked by JNI");
2224     }
2225     return;
2226   }
2227   ObjectSynchronizer::exit(obj, lock, current);
2228 }
2229 
2230 // Handles the uncommon cases of monitor unlocking in compiled code
2231 JRT_LEAF(void, SharedRuntime::complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock, JavaThread* current))
2232   SharedRuntime::monitor_exit_helper(obj, lock, current);
2233 JRT_END
2234 
2235 #ifndef PRODUCT
2236 
2237 void SharedRuntime::print_statistics() {
2238   ttyLocker ttyl;
2239   if (xtty != NULL)  xtty->head("statistics type='SharedRuntime'");
2240 
2241   SharedRuntime::print_ic_miss_histogram();
2242 
2243   // Dump the JRT_ENTRY counters
2244   if (_new_instance_ctr) tty->print_cr("%5d new instance requires GC", _new_instance_ctr);
2245   if (_new_array_ctr) tty->print_cr("%5d new array requires GC", _new_array_ctr);
2246   if (_multi2_ctr) tty->print_cr("%5d multianewarray 2 dim", _multi2_ctr);
2247   if (_multi3_ctr) tty->print_cr("%5d multianewarray 3 dim", _multi3_ctr);
2248   if (_multi4_ctr) tty->print_cr("%5d multianewarray 4 dim", _multi4_ctr);
2249   if (_multi5_ctr) tty->print_cr("%5d multianewarray 5 dim", _multi5_ctr);
2250 
2251   tty->print_cr("%5d inline cache miss in compiled", _ic_miss_ctr);
2252   tty->print_cr("%5d wrong method", _wrong_method_ctr);

3209 
3210   Method* moop = fr.interpreter_frame_method();
3211   int max_locals = moop->max_locals();
3212   // Allocate temp buffer, 1 word per local & 2 per active monitor
3213   int buf_size_words = max_locals + active_monitor_count * BasicObjectLock::size();
3214   intptr_t *buf = NEW_C_HEAP_ARRAY(intptr_t,buf_size_words, mtCode);
3215 
3216   // Copy the locals.  Order is preserved so that loading of longs works.
3217   // Since there's no GC I can copy the oops blindly.
3218   assert(sizeof(HeapWord)==sizeof(intptr_t), "fix this code");
3219   Copy::disjoint_words((HeapWord*)fr.interpreter_frame_local_at(max_locals-1),
3220                        (HeapWord*)&buf[0],
3221                        max_locals);
3222 
3223   // Inflate locks.  Copy the displaced headers.  Be careful, there can be holes.
3224   int i = max_locals;
3225   for (BasicObjectLock *kptr2 = fr.interpreter_frame_monitor_end();
3226        kptr2 < fr.interpreter_frame_monitor_begin();
3227        kptr2 = fr.next_monitor_in_interpreter_frame(kptr2) ) {
3228     if (kptr2->obj() != NULL) {         // Avoid 'holes' in the monitor array
3229       BasicLock *lock = kptr2->lock();
3230       // Inflate so the object's header no longer refers to the BasicLock.
3231       if (lock->displaced_header().is_unlocked()) {
3232         // The object is locked and the resulting ObjectMonitor* will also be
3233         // locked so it can't be async deflated until ownership is dropped.
3234         // See the big comment in basicLock.cpp: BasicLock::move_to().
3235         ObjectSynchronizer::inflate_helper(kptr2->obj());
3236       }
3237       // Now the displaced header is free to move because the
3238       // object's header no longer refers to it.
3239       buf[i++] = (intptr_t)lock->displaced_header().value();
3240       buf[i++] = cast_from_oop<intptr_t>(kptr2->obj());
3241     }
3242   }
3243   assert(i - max_locals == active_monitor_count*2, "found the expected number of monitors");
3244 
3245   RegisterMap map(current,
3246                   RegisterMap::UpdateMap::skip,
3247                   RegisterMap::ProcessFrames::include,
3248                   RegisterMap::WalkContinuation::skip);
3249   frame sender = fr.sender(&map);
3250   if (sender.is_interpreted_frame()) {
3251     current->push_cont_fastpath(sender.sp());
3252   }
3253 
3254   return buf;
3255 JRT_END
3256 
3257 JRT_LEAF(void, SharedRuntime::OSR_migration_end( intptr_t* buf) )
3258   FREE_C_HEAP_ARRAY(intptr_t, buf);
3259 JRT_END
3260 
3261 bool AdapterHandlerLibrary::contains(const CodeBlob* b) {
3262   bool found = false;
3263   auto findblob = [&] (AdapterFingerPrint* key, AdapterHandlerEntry* a) {

2171     // Shouldn't happen, but don't cause even more problems if it does
2172     message = const_cast<char*>(caster_klass->external_name());
2173   } else {
2174     jio_snprintf(message,
2175                  msglen,
2176                  "class %s cannot be cast to class %s (%s%s%s)",
2177                  caster_name,
2178                  target_name,
2179                  caster_klass_description,
2180                  klass_separator,
2181                  target_klass_description
2182                  );
2183   }
2184   return message;
2185 }
2186 
2187 JRT_LEAF(void, SharedRuntime::reguard_yellow_pages())
2188   (void) JavaThread::current()->stack_overflow_state()->reguard_stack();
2189 JRT_END
2190 
2191 void SharedRuntime::monitor_enter_helper(oopDesc* obj, JavaThread* current) {
2192   if (!SafepointSynchronize::is_synchronizing()) {
2193     // Only try quick_enter() if we're not trying to reach a safepoint
2194     // so that the calling thread reaches the safepoint more quickly.
2195     if (ObjectSynchronizer::quick_enter(obj, current)) {
2196       return;
2197     }
2198   }
2199   // NO_ASYNC required because an async exception on the state transition destructor
2200   // would leave you with the lock held and it would never be released.
2201   // The normal monitorenter NullPointerException is thrown without acquiring a lock
2202   // and the model is that an exception implies the method failed.
2203   JRT_BLOCK_NO_ASYNC
2204   Handle h_obj(THREAD, obj);
2205   ObjectSynchronizer::enter(h_obj, current);
2206   assert(!HAS_PENDING_EXCEPTION, "Should have no exception here");
2207   JRT_BLOCK_END
2208 }
2209 
2210 // Handles the uncommon case in locking, i.e., contention or an inflated lock.
2211 JRT_BLOCK_ENTRY(void, SharedRuntime::complete_monitor_locking_C(oopDesc* obj, JavaThread* current))
2212   SharedRuntime::monitor_enter_helper(obj, current);
2213 JRT_END
2214 
2215 void SharedRuntime::monitor_exit_helper(oopDesc* obj, JavaThread* current) {
2216   assert(JavaThread::current() == current, "invariant");
2217   // Exit must be non-blocking, and therefore no exceptions can be thrown.
2218   ExceptionMark em(current);
2219   // The object could become unlocked through a JNI call, which we have no other checks for.
2220   // Give a fatal message if CheckJNICalls. Otherwise we ignore it.
2221   if (obj->is_unlocked()) {
2222     if (CheckJNICalls) {
2223       fatal("Object has been unlocked by JNI");
2224     }
2225     return;
2226   }
2227   ObjectSynchronizer::exit(obj, current);
2228 }
2229 
2230 // Handles the uncommon cases of monitor unlocking in compiled code
2231 JRT_LEAF(void, SharedRuntime::complete_monitor_unlocking_C(oopDesc* obj, JavaThread* current))
2232   SharedRuntime::monitor_exit_helper(obj, current);
2233 JRT_END
2234 
2235 #ifndef PRODUCT
2236 
2237 void SharedRuntime::print_statistics() {
2238   ttyLocker ttyl;
2239   if (xtty != NULL)  xtty->head("statistics type='SharedRuntime'");
2240 
2241   SharedRuntime::print_ic_miss_histogram();
2242 
2243   // Dump the JRT_ENTRY counters
2244   if (_new_instance_ctr) tty->print_cr("%5d new instance requires GC", _new_instance_ctr);
2245   if (_new_array_ctr) tty->print_cr("%5d new array requires GC", _new_array_ctr);
2246   if (_multi2_ctr) tty->print_cr("%5d multianewarray 2 dim", _multi2_ctr);
2247   if (_multi3_ctr) tty->print_cr("%5d multianewarray 3 dim", _multi3_ctr);
2248   if (_multi4_ctr) tty->print_cr("%5d multianewarray 4 dim", _multi4_ctr);
2249   if (_multi5_ctr) tty->print_cr("%5d multianewarray 5 dim", _multi5_ctr);
2250 
2251   tty->print_cr("%5d inline cache miss in compiled", _ic_miss_ctr);
2252   tty->print_cr("%5d wrong method", _wrong_method_ctr);

3209 
3210   Method* moop = fr.interpreter_frame_method();
3211   int max_locals = moop->max_locals();
3212   // Allocate temp buffer, 1 word per local & 2 per active monitor
3213   int buf_size_words = max_locals + active_monitor_count * BasicObjectLock::size();
3214   intptr_t *buf = NEW_C_HEAP_ARRAY(intptr_t,buf_size_words, mtCode);
3215 
3216   // Copy the locals.  Order is preserved so that loading of longs works.
3217   // Since there's no GC I can copy the oops blindly.
3218   assert(sizeof(HeapWord)==sizeof(intptr_t), "fix this code");
3219   Copy::disjoint_words((HeapWord*)fr.interpreter_frame_local_at(max_locals-1),
3220                        (HeapWord*)&buf[0],
3221                        max_locals);
3222 
3223   // Inflate locks.  Copy the displaced headers.  Be careful, there can be holes.
3224   int i = max_locals;
3225   for (BasicObjectLock *kptr2 = fr.interpreter_frame_monitor_end();
3226        kptr2 < fr.interpreter_frame_monitor_begin();
3227        kptr2 = fr.next_monitor_in_interpreter_frame(kptr2) ) {
3228     if (kptr2->obj() != NULL) {         // Avoid 'holes' in the monitor array











3229       buf[i++] = cast_from_oop<intptr_t>(kptr2->obj());
3230     }
3231   }
3232   assert(i - max_locals == active_monitor_count, "found the expected number of monitors");
3233 
3234   RegisterMap map(current,
3235                   RegisterMap::UpdateMap::skip,
3236                   RegisterMap::ProcessFrames::include,
3237                   RegisterMap::WalkContinuation::skip);
3238   frame sender = fr.sender(&map);
3239   if (sender.is_interpreted_frame()) {
3240     current->push_cont_fastpath(sender.sp());
3241   }
3242 
3243   return buf;
3244 JRT_END
3245 
3246 JRT_LEAF(void, SharedRuntime::OSR_migration_end( intptr_t* buf) )
3247   FREE_C_HEAP_ARRAY(intptr_t, buf);
3248 JRT_END
3249 
3250 bool AdapterHandlerLibrary::contains(const CodeBlob* b) {
3251   bool found = false;
3252   auto findblob = [&] (AdapterFingerPrint* key, AdapterHandlerEntry* a) {
< prev index next >