6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/parallel/gcTaskManager.hpp"
27 #include "gc/parallel/mutableSpace.hpp"
28 #include "gc/parallel/parallelScavengeHeap.hpp"
29 #include "gc/parallel/psOldGen.hpp"
30 #include "gc/parallel/psPromotionManager.inline.hpp"
31 #include "gc/parallel/psScavenge.inline.hpp"
32 #include "gc/shared/gcTrace.hpp"
33 #include "gc/shared/preservedMarks.inline.hpp"
34 #include "gc/shared/taskqueue.inline.hpp"
35 #include "logging/log.hpp"
36 #include "logging/logStream.hpp"
37 #include "memory/allocation.inline.hpp"
38 #include "memory/memRegion.hpp"
39 #include "memory/padded.inline.hpp"
40 #include "memory/resourceArea.hpp"
41 #include "oops/access.inline.hpp"
42 #include "oops/arrayOop.inline.hpp"
43 #include "oops/compressedOops.inline.hpp"
44 #include "oops/instanceKlass.inline.hpp"
45 #include "oops/instanceMirrorKlass.inline.hpp"
46 #include "oops/objArrayKlass.inline.hpp"
47 #include "oops/objArrayOop.inline.hpp"
48 #include "oops/oop.inline.hpp"
49
50 PaddedEnd<PSPromotionManager>* PSPromotionManager::_manager_array = NULL;
51 OopStarTaskQueueSet* PSPromotionManager::_stack_array_depth = NULL;
52 PreservedMarksSet* PSPromotionManager::_preserved_marks_set = NULL;
53 PSOldGen* PSPromotionManager::_old_gen = NULL;
54 MutableSpace* PSPromotionManager::_young_space = NULL;
55
56 void PSPromotionManager::initialize() {
57 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
58
59 _old_gen = heap->old_gen();
60 _young_space = heap->young_gen()->to_space();
61
62 const uint promotion_manager_num = ParallelGCThreads + 1;
63
377 // we'll chunk more
378 start = end - _array_chunk_size;
379 assert(start > 0, "invariant");
380 arrayOop(old)->set_length(start);
381 push_depth(mask_chunked_array_oop(old));
382 TASKQUEUE_STATS_ONLY(++_masked_pushes);
383 } else {
384 // this is the final chunk for this array
385 start = 0;
386 int const actual_length = arrayOop(obj)->length();
387 arrayOop(old)->set_length(actual_length);
388 }
389
390 if (UseCompressedOops) {
391 process_array_chunk_work<narrowOop>(obj, start, end);
392 } else {
393 process_array_chunk_work<oop>(obj, start, end);
394 }
395 }
396
397 class PushContentsClosure : public ExtendedOopClosure {
398 PSPromotionManager* _pm;
399 public:
400 PushContentsClosure(PSPromotionManager* pm) : _pm(pm) {}
401
402 template <typename T> void do_oop_nv(T* p) {
403 if (PSScavenge::should_scavenge(p)) {
404 _pm->claim_or_forward_depth(p);
405 }
406 }
407
408 virtual void do_oop(oop* p) { do_oop_nv(p); }
409 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
410
411 // Don't use the oop verification code in the oop_oop_iterate framework.
412 debug_only(virtual bool should_verify_oops() { return false; })
413 };
414
415 void InstanceKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
416 PushContentsClosure cl(pm);
417 oop_oop_iterate_oop_maps_reverse<true>(obj, &cl);
418 }
419
420 void InstanceMirrorKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
421 // Note that we don't have to follow the mirror -> klass pointer, since all
422 // klasses that are dirty will be scavenged when we iterate over the
423 // ClassLoaderData objects.
424
425 InstanceKlass::oop_ps_push_contents(obj, pm);
426
427 PushContentsClosure cl(pm);
428 oop_oop_iterate_statics<true>(obj, &cl);
429 }
430
431 void InstanceClassLoaderKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
432 InstanceKlass::oop_ps_push_contents(obj, pm);
433
434 // This is called by the young collector. It will already have taken care of
435 // all class loader data. So, we don't have to follow the class loader ->
436 // class loader data link.
437 }
438
439 template <class T>
440 static void oop_ps_push_contents_specialized(oop obj, InstanceRefKlass *klass, PSPromotionManager* pm) {
441 T* referent_addr = (T*)java_lang_ref_Reference::referent_addr_raw(obj);
442 if (PSScavenge::should_scavenge(referent_addr)) {
443 ReferenceProcessor* rp = PSScavenge::reference_processor();
444 if (rp->discover_reference(obj, klass->reference_type())) {
445 // reference discovered, referent will be traversed later.
446 klass->InstanceKlass::oop_ps_push_contents(obj, pm);
447 return;
448 } else {
452 }
453 // Treat discovered as normal oop
454 T* discovered_addr = (T*)java_lang_ref_Reference::discovered_addr_raw(obj);
455 if (PSScavenge::should_scavenge(discovered_addr)) {
456 pm->claim_or_forward_depth(discovered_addr);
457 }
458 klass->InstanceKlass::oop_ps_push_contents(obj, pm);
459 }
460
461 void InstanceRefKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
462 if (UseCompressedOops) {
463 oop_ps_push_contents_specialized<narrowOop>(obj, this, pm);
464 } else {
465 oop_ps_push_contents_specialized<oop>(obj, this, pm);
466 }
467 }
468
469 void ObjArrayKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
470 assert(obj->is_objArray(), "obj must be obj array");
471 PushContentsClosure cl(pm);
472 oop_oop_iterate_elements<true>(objArrayOop(obj), &cl);
473 }
474
475 void TypeArrayKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
476 assert(obj->is_typeArray(),"must be a type array");
477 ShouldNotReachHere();
478 }
479
480 oop PSPromotionManager::oop_promotion_failed(oop obj, markOop obj_mark) {
481 assert(_old_gen_is_full || PromotionFailureALot, "Sanity");
482
483 // Attempt to CAS in the header.
484 // This tests if the header is still the same as when
485 // this started. If it is the same (i.e., no forwarding
486 // pointer has been installed), then this thread owns
487 // it.
488 if (obj->cas_forward_to(obj, obj_mark)) {
489 // We won any races, we "own" this object.
490 assert(obj == obj->forwardee(), "Sanity");
491
492 _promotion_failed_info.register_copy_failure(obj->size());
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/javaClasses.inline.hpp"
27 #include "gc/parallel/gcTaskManager.hpp"
28 #include "gc/parallel/mutableSpace.hpp"
29 #include "gc/parallel/parallelScavengeHeap.hpp"
30 #include "gc/parallel/psOldGen.hpp"
31 #include "gc/parallel/psPromotionManager.inline.hpp"
32 #include "gc/parallel/psScavenge.inline.hpp"
33 #include "gc/shared/gcTrace.hpp"
34 #include "gc/shared/preservedMarks.inline.hpp"
35 #include "gc/shared/taskqueue.inline.hpp"
36 #include "logging/log.hpp"
37 #include "logging/logStream.hpp"
38 #include "memory/allocation.inline.hpp"
39 #include "memory/iterator.inline.hpp"
40 #include "memory/memRegion.hpp"
41 #include "memory/padded.inline.hpp"
42 #include "memory/resourceArea.hpp"
43 #include "oops/access.inline.hpp"
44 #include "oops/arrayOop.inline.hpp"
45 #include "oops/compressedOops.inline.hpp"
46 #include "oops/instanceClassLoaderKlass.inline.hpp"
47 #include "oops/instanceKlass.inline.hpp"
48 #include "oops/instanceMirrorKlass.inline.hpp"
49 #include "oops/objArrayKlass.inline.hpp"
50 #include "oops/objArrayOop.inline.hpp"
51 #include "oops/oop.inline.hpp"
52
53 PaddedEnd<PSPromotionManager>* PSPromotionManager::_manager_array = NULL;
54 OopStarTaskQueueSet* PSPromotionManager::_stack_array_depth = NULL;
55 PreservedMarksSet* PSPromotionManager::_preserved_marks_set = NULL;
56 PSOldGen* PSPromotionManager::_old_gen = NULL;
57 MutableSpace* PSPromotionManager::_young_space = NULL;
58
59 void PSPromotionManager::initialize() {
60 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
61
62 _old_gen = heap->old_gen();
63 _young_space = heap->young_gen()->to_space();
64
65 const uint promotion_manager_num = ParallelGCThreads + 1;
66
380 // we'll chunk more
381 start = end - _array_chunk_size;
382 assert(start > 0, "invariant");
383 arrayOop(old)->set_length(start);
384 push_depth(mask_chunked_array_oop(old));
385 TASKQUEUE_STATS_ONLY(++_masked_pushes);
386 } else {
387 // this is the final chunk for this array
388 start = 0;
389 int const actual_length = arrayOop(obj)->length();
390 arrayOop(old)->set_length(actual_length);
391 }
392
393 if (UseCompressedOops) {
394 process_array_chunk_work<narrowOop>(obj, start, end);
395 } else {
396 process_array_chunk_work<oop>(obj, start, end);
397 }
398 }
399
400 class PushContentsClosure : public BasicOopIterateClosure {
401 PSPromotionManager* _pm;
402 public:
403 PushContentsClosure(PSPromotionManager* pm) : _pm(pm) {}
404
405 template <typename T> void do_oop_work(T* p) {
406 if (PSScavenge::should_scavenge(p)) {
407 _pm->claim_or_forward_depth(p);
408 }
409 }
410
411 virtual void do_oop(oop* p) { do_oop_work(p); }
412 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
413
414 // Don't use the oop verification code in the oop_oop_iterate framework.
415 debug_only(virtual bool should_verify_oops() { return false; })
416 };
417
418 void InstanceKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
419 PushContentsClosure cl(pm);
420 if (UseCompressedOops) {
421 oop_oop_iterate_oop_maps_reverse<narrowOop>(obj, &cl);
422 } else {
423 oop_oop_iterate_oop_maps_reverse<oop>(obj, &cl);
424 }
425 }
426
427 void InstanceMirrorKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
428 // Note that we don't have to follow the mirror -> klass pointer, since all
429 // klasses that are dirty will be scavenged when we iterate over the
430 // ClassLoaderData objects.
431
432 InstanceKlass::oop_ps_push_contents(obj, pm);
433
434 PushContentsClosure cl(pm);
435 if (UseCompressedOops) {
436 oop_oop_iterate_statics<narrowOop>(obj, &cl);
437 } else {
438 oop_oop_iterate_statics<oop>(obj, &cl);
439 }
440 }
441
442 void InstanceClassLoaderKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
443 InstanceKlass::oop_ps_push_contents(obj, pm);
444
445 // This is called by the young collector. It will already have taken care of
446 // all class loader data. So, we don't have to follow the class loader ->
447 // class loader data link.
448 }
449
450 template <class T>
451 static void oop_ps_push_contents_specialized(oop obj, InstanceRefKlass *klass, PSPromotionManager* pm) {
452 T* referent_addr = (T*)java_lang_ref_Reference::referent_addr_raw(obj);
453 if (PSScavenge::should_scavenge(referent_addr)) {
454 ReferenceProcessor* rp = PSScavenge::reference_processor();
455 if (rp->discover_reference(obj, klass->reference_type())) {
456 // reference discovered, referent will be traversed later.
457 klass->InstanceKlass::oop_ps_push_contents(obj, pm);
458 return;
459 } else {
463 }
464 // Treat discovered as normal oop
465 T* discovered_addr = (T*)java_lang_ref_Reference::discovered_addr_raw(obj);
466 if (PSScavenge::should_scavenge(discovered_addr)) {
467 pm->claim_or_forward_depth(discovered_addr);
468 }
469 klass->InstanceKlass::oop_ps_push_contents(obj, pm);
470 }
471
472 void InstanceRefKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
473 if (UseCompressedOops) {
474 oop_ps_push_contents_specialized<narrowOop>(obj, this, pm);
475 } else {
476 oop_ps_push_contents_specialized<oop>(obj, this, pm);
477 }
478 }
479
480 void ObjArrayKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
481 assert(obj->is_objArray(), "obj must be obj array");
482 PushContentsClosure cl(pm);
483 if (UseCompressedOops) {
484 oop_oop_iterate_elements<narrowOop>(objArrayOop(obj), &cl);
485 } else {
486 oop_oop_iterate_elements<oop>(objArrayOop(obj), &cl);
487 }
488 }
489
490 void TypeArrayKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
491 assert(obj->is_typeArray(),"must be a type array");
492 ShouldNotReachHere();
493 }
494
495 oop PSPromotionManager::oop_promotion_failed(oop obj, markOop obj_mark) {
496 assert(_old_gen_is_full || PromotionFailureALot, "Sanity");
497
498 // Attempt to CAS in the header.
499 // This tests if the header is still the same as when
500 // this started. If it is the same (i.e., no forwarding
501 // pointer has been installed), then this thread owns
502 // it.
503 if (obj->cas_forward_to(obj, obj_mark)) {
504 // We won any races, we "own" this object.
505 assert(obj == obj->forwardee(), "Sanity");
506
507 _promotion_failed_info.register_copy_failure(obj->size());
|