1 /*
 2  * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 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
 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/systemDictionary.hpp"
27 #include "code/codeCache.hpp"
28 #include "gc/parallel/gcTaskManager.hpp"
29 #include "gc/parallel/parallelScavengeHeap.inline.hpp"
30 #include "gc/parallel/psCardTable.hpp"
31 #include "gc/parallel/psClosure.inline.hpp"
32 #include "gc/parallel/psPromotionManager.hpp"
33 #include "gc/parallel/psPromotionManager.inline.hpp"
34 #include "gc/parallel/psScavenge.inline.hpp"
35 #include "gc/parallel/psTasks.hpp"
36 #include "gc/shared/taskqueue.inline.hpp"
37 #include "memory/iterator.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "memory/universe.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "runtime/thread.hpp"
42 #include "runtime/vmThread.hpp"
43 #include "services/management.hpp"
44 
45 //
46 // StealTask
47 //
48 
49 StealTask::StealTask(ParallelTaskTerminator* t) :
50   _terminator(t) {}
51 
52 void StealTask::do_it(GCTaskManager* manager, uint which) {
53   assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
54 
55   PSPromotionManager* pm =
56     PSPromotionManager::gc_thread_promotion_manager(which);
57   pm->drain_stacks(true);
58   guarantee(pm->stacks_empty(),
59             "stacks should be empty at this point");
60 
61   while(true) {
62     StarTask p;
63     if (PSPromotionManager::steal_depth(which, p)) {
64       TASKQUEUE_STATS_ONLY(pm->record_steal(p));
65       pm->process_popped_location_depth(p);
66       pm->drain_stacks_depth(true);
67     } else {
68       if (terminator()->offer_termination()) {
69         break;
70       }
71     }
72   }
73   guarantee(pm->stacks_empty(), "stacks should be empty at this point");
74 }