comparison src/share/vm/runtime/sweeper.cpp @ 6948:e522a00b91aa

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/ after NPG - C++ build works
author Doug Simon <doug.simon@oracle.com>
date Mon, 12 Nov 2012 23:14:12 +0100
parents 957c266d8bc5 da91efe96a93
children 836a62f43af9
comparison
equal deleted inserted replaced
6711:ae13cc658b80 6948:e522a00b91aa
1 /* 1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
22 * 22 *
23 */ 23 */
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "code/codeCache.hpp" 26 #include "code/codeCache.hpp"
27 #include "code/compiledIC.hpp"
28 #include "code/icBuffer.hpp"
27 #include "code/nmethod.hpp" 29 #include "code/nmethod.hpp"
28 #include "compiler/compileBroker.hpp" 30 #include "compiler/compileBroker.hpp"
29 #include "memory/resourceArea.hpp" 31 #include "memory/resourceArea.hpp"
30 #include "oops/methodOop.hpp" 32 #include "oops/method.hpp"
31 #include "runtime/atomic.hpp" 33 #include "runtime/atomic.hpp"
32 #include "runtime/compilationPolicy.hpp" 34 #include "runtime/compilationPolicy.hpp"
33 #include "runtime/mutexLocker.hpp" 35 #include "runtime/mutexLocker.hpp"
34 #include "runtime/os.hpp" 36 #include "runtime/os.hpp"
35 #include "runtime/sweeper.hpp" 37 #include "runtime/sweeper.hpp"
318 } 320 }
319 } 321 }
320 322
321 class NMethodMarker: public StackObj { 323 class NMethodMarker: public StackObj {
322 private: 324 private:
325 #ifdef GRAAL
323 JavaThread* _thread; 326 JavaThread* _thread;
327 #else
328 CompilerThread* _thread;
329 #endif
324 public: 330 public:
325 NMethodMarker(nmethod* nm) { 331 NMethodMarker(nmethod* nm) {
332 #ifdef GRAAL
326 _thread = JavaThread::current(); 333 _thread = JavaThread::current();
327 _thread->set_scanned_nmethod(nm); 334 #else
335 _thread = CompilerThread::current();
336 #endif
337 if (!nm->is_zombie() && !nm->is_unloaded()) {
338 // Only expose live nmethods for scanning
339 _thread->set_scanned_nmethod(nm);
340 }
328 } 341 }
329 ~NMethodMarker() { 342 ~NMethodMarker() {
330 _thread->set_scanned_nmethod(NULL); 343 _thread->set_scanned_nmethod(NULL);
331 } 344 }
332 }; 345 };
333 346
347 void NMethodSweeper::release_nmethod(nmethod *nm) {
348 // Clean up any CompiledICHolders
349 {
350 ResourceMark rm;
351 MutexLocker ml_patch(CompiledIC_lock);
352 RelocIterator iter(nm);
353 while (iter.next()) {
354 if (iter.type() == relocInfo::virtual_call_type) {
355 CompiledIC::cleanup_call_site(iter.virtual_call_reloc());
356 }
357 }
358 }
359
360 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
361 nm->flush();
362 }
334 363
335 void NMethodSweeper::process_nmethod(nmethod *nm) { 364 void NMethodSweeper::process_nmethod(nmethod *nm) {
336 assert(!CodeCache_lock->owned_by_self(), "just checking"); 365 assert(!CodeCache_lock->owned_by_self(), "just checking");
337 366
338 // Make sure this nmethod doesn't get unloaded during the scan, 367 // Make sure this nmethod doesn't get unloaded during the scan,
363 if (nm->is_marked_for_reclamation()) { 392 if (nm->is_marked_for_reclamation()) {
364 assert(!nm->is_locked_by_vm(), "must not flush locked nmethods"); 393 assert(!nm->is_locked_by_vm(), "must not flush locked nmethods");
365 if (PrintMethodFlushing && Verbose) { 394 if (PrintMethodFlushing && Verbose) {
366 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (marked for reclamation) being flushed", nm->compile_id(), nm); 395 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (marked for reclamation) being flushed", nm->compile_id(), nm);
367 } 396 }
368 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 397 release_nmethod(nm);
369 nm->flush();
370 } else { 398 } else {
371 if (PrintMethodFlushing && Verbose) { 399 if (PrintMethodFlushing && Verbose) {
372 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (zombie) being marked for reclamation", nm->compile_id(), nm); 400 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (zombie) being marked for reclamation", nm->compile_id(), nm);
373 } 401 }
374 nm->mark_for_reclamation(); 402 nm->mark_for_reclamation();
398 } else if (nm->is_unloaded()) { 426 } else if (nm->is_unloaded()) {
399 // Unloaded code, just make it a zombie 427 // Unloaded code, just make it a zombie
400 if (PrintMethodFlushing && Verbose) 428 if (PrintMethodFlushing && Verbose)
401 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (unloaded) being made zombie", nm->compile_id(), nm); 429 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (unloaded) being made zombie", nm->compile_id(), nm);
402 if (nm->is_osr_method()) { 430 if (nm->is_osr_method()) {
431 SWEEP(nm);
403 // No inline caches will ever point to osr methods, so we can just remove it 432 // No inline caches will ever point to osr methods, so we can just remove it
404 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 433 release_nmethod(nm);
405 SWEEP(nm);
406 nm->flush();
407 } else { 434 } else {
408 nm->make_zombie(); 435 nm->make_zombie();
409 _rescan = true; 436 _rescan = true;
410 SWEEP(nm); 437 SWEEP(nm);
411 } 438 }
432 // they will call a vm op that comes here. This code attempts to speculatively 459 // they will call a vm op that comes here. This code attempts to speculatively
433 // unload the oldest half of the nmethods (based on the compile job id) by 460 // unload the oldest half of the nmethods (based on the compile job id) by
434 // saving the old code in a list in the CodeCache. Then 461 // saving the old code in a list in the CodeCache. Then
435 // execution resumes. If a method so marked is not called by the second sweeper 462 // execution resumes. If a method so marked is not called by the second sweeper
436 // stack traversal after the current one, the nmethod will be marked non-entrant and 463 // stack traversal after the current one, the nmethod will be marked non-entrant and
437 // got rid of by normal sweeping. If the method is called, the methodOop's 464 // got rid of by normal sweeping. If the method is called, the Method*'s
438 // _code field is restored and the methodOop/nmethod 465 // _code field is restored and the Method*/nmethod
439 // go back to their normal state. 466 // go back to their normal state.
440 void NMethodSweeper::handle_full_code_cache(bool is_full) { 467 void NMethodSweeper::handle_full_code_cache(bool is_full) {
441 // Only the first one to notice can advise us to start early cleaning 468 // Only the first one to notice can advise us to start early cleaning
442 if (!is_full){ 469 if (!is_full){
443 jint old = Atomic::cmpxchg( 1, &_advise_to_sweep, 0 ); 470 jint old = Atomic::cmpxchg( 1, &_advise_to_sweep, 0 );