Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp @ 4059:44ce519bc3d1
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
Reviewed-by: kvn, jrose, twisti
author | never |
---|---|
date | Tue, 08 Nov 2011 10:31:53 -0800 |
parents | c2bf0120ee5d |
children | bca17e38de00 |
rev | line source |
---|---|
0 | 1 /* |
2426
1d1603768966
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
2177
diff
changeset
|
2 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1311
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1311
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1311
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" | |
27 #include "code/codeCache.hpp" | |
28 #include "gc_implementation/parallelScavenge/pcTasks.hpp" | |
29 #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" | |
30 #include "gc_interface/collectedHeap.hpp" | |
31 #include "memory/universe.hpp" | |
32 #include "oops/objArrayKlass.inline.hpp" | |
33 #include "oops/oop.inline.hpp" | |
34 #include "oops/oop.pcgc.inline.hpp" | |
35 #include "prims/jvmtiExport.hpp" | |
36 #include "runtime/fprofiler.hpp" | |
37 #include "runtime/jniHandles.hpp" | |
38 #include "runtime/thread.hpp" | |
39 #include "runtime/vmThread.hpp" | |
40 #include "services/management.hpp" | |
0 | 41 |
42 // | |
43 // ThreadRootsMarkingTask | |
44 // | |
45 | |
46 void ThreadRootsMarkingTask::do_it(GCTaskManager* manager, uint which) { | |
47 assert(Universe::heap()->is_gc_active(), "called outside gc"); | |
48 | |
49 ResourceMark rm; | |
50 | |
51 NOT_PRODUCT(TraceTime tm("ThreadRootsMarkingTask", | |
52 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); | |
53 ParCompactionManager* cm = | |
54 ParCompactionManager::gc_thread_compaction_manager(which); | |
55 PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
375
diff
changeset
|
56 CodeBlobToOopClosure mark_and_push_in_blobs(&mark_and_push_closure, /*do_marking=*/ true); |
0 | 57 |
58 if (_java_thread != NULL) | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
375
diff
changeset
|
59 _java_thread->oops_do(&mark_and_push_closure, &mark_and_push_in_blobs); |
0 | 60 |
61 if (_vm_thread != NULL) | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
375
diff
changeset
|
62 _vm_thread->oops_do(&mark_and_push_closure, &mark_and_push_in_blobs); |
0 | 63 |
64 // Do the real work | |
1311
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
1000
diff
changeset
|
65 cm->follow_marking_stacks(); |
0 | 66 } |
67 | |
68 | |
69 void MarkFromRootsTask::do_it(GCTaskManager* manager, uint which) { | |
70 assert(Universe::heap()->is_gc_active(), "called outside gc"); | |
71 | |
72 NOT_PRODUCT(TraceTime tm("MarkFromRootsTask", | |
73 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); | |
74 ParCompactionManager* cm = | |
75 ParCompactionManager::gc_thread_compaction_manager(which); | |
76 PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); | |
77 | |
78 switch (_root_type) { | |
79 case universe: | |
80 Universe::oops_do(&mark_and_push_closure); | |
81 break; | |
82 | |
83 case jni_handles: | |
84 JNIHandles::oops_do(&mark_and_push_closure); | |
85 break; | |
86 | |
87 case threads: | |
88 { | |
89 ResourceMark rm; | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
375
diff
changeset
|
90 CodeBlobToOopClosure each_active_code_blob(&mark_and_push_closure, /*do_marking=*/ true); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
375
diff
changeset
|
91 Threads::oops_do(&mark_and_push_closure, &each_active_code_blob); |
0 | 92 } |
93 break; | |
94 | |
95 case object_synchronizer: | |
96 ObjectSynchronizer::oops_do(&mark_and_push_closure); | |
97 break; | |
98 | |
99 case flat_profiler: | |
100 FlatProfiler::oops_do(&mark_and_push_closure); | |
101 break; | |
102 | |
103 case management: | |
104 Management::oops_do(&mark_and_push_closure); | |
105 break; | |
106 | |
107 case jvmti: | |
108 JvmtiExport::oops_do(&mark_and_push_closure); | |
109 break; | |
110 | |
111 case system_dictionary: | |
112 SystemDictionary::always_strong_oops_do(&mark_and_push_closure); | |
113 break; | |
114 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
375
diff
changeset
|
115 case code_cache: |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
375
diff
changeset
|
116 // Do not treat nmethods as strong roots for mark/sweep, since we can unload them. |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
375
diff
changeset
|
117 //CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure(&mark_and_push_closure)); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
375
diff
changeset
|
118 break; |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
375
diff
changeset
|
119 |
0 | 120 default: |
121 fatal("Unknown root type"); | |
122 } | |
123 | |
124 // Do the real work | |
1311
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
1000
diff
changeset
|
125 cm->follow_marking_stacks(); |
0 | 126 } |
127 | |
128 | |
129 // | |
130 // RefProcTaskProxy | |
131 // | |
132 | |
133 void RefProcTaskProxy::do_it(GCTaskManager* manager, uint which) | |
134 { | |
135 assert(Universe::heap()->is_gc_active(), "called outside gc"); | |
136 | |
137 NOT_PRODUCT(TraceTime tm("RefProcTask", | |
138 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); | |
139 ParCompactionManager* cm = | |
140 ParCompactionManager::gc_thread_compaction_manager(which); | |
141 PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); | |
142 PSParallelCompact::FollowStackClosure follow_stack_closure(cm); | |
143 _rp_task.work(_work_id, *PSParallelCompact::is_alive_closure(), | |
144 mark_and_push_closure, follow_stack_closure); | |
145 } | |
146 | |
147 // | |
148 // RefProcTaskExecutor | |
149 // | |
150 | |
151 void RefProcTaskExecutor::execute(ProcessTask& task) | |
152 { | |
153 ParallelScavengeHeap* heap = PSParallelCompact::gc_heap(); | |
154 uint parallel_gc_threads = heap->gc_task_manager()->workers(); | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
155 RegionTaskQueueSet* qset = ParCompactionManager::region_array(); |
0 | 156 ParallelTaskTerminator terminator(parallel_gc_threads, qset); |
157 GCTaskQueue* q = GCTaskQueue::create(); | |
158 for(uint i=0; i<parallel_gc_threads; i++) { | |
159 q->enqueue(new RefProcTaskProxy(task, i)); | |
160 } | |
161 if (task.marks_oops_alive()) { | |
162 if (parallel_gc_threads>1) { | |
163 for (uint j=0; j<parallel_gc_threads; j++) { | |
164 q->enqueue(new StealMarkingTask(&terminator)); | |
165 } | |
166 } | |
167 } | |
168 PSParallelCompact::gc_task_manager()->execute_and_wait(q); | |
169 } | |
170 | |
171 void RefProcTaskExecutor::execute(EnqueueTask& task) | |
172 { | |
173 ParallelScavengeHeap* heap = PSParallelCompact::gc_heap(); | |
174 uint parallel_gc_threads = heap->gc_task_manager()->workers(); | |
175 GCTaskQueue* q = GCTaskQueue::create(); | |
176 for(uint i=0; i<parallel_gc_threads; i++) { | |
177 q->enqueue(new RefEnqueueTaskProxy(task, i)); | |
178 } | |
179 PSParallelCompact::gc_task_manager()->execute_and_wait(q); | |
180 } | |
181 | |
182 // | |
183 // StealMarkingTask | |
184 // | |
185 | |
186 StealMarkingTask::StealMarkingTask(ParallelTaskTerminator* t) : | |
187 _terminator(t) {} | |
188 | |
189 void StealMarkingTask::do_it(GCTaskManager* manager, uint which) { | |
190 assert(Universe::heap()->is_gc_active(), "called outside gc"); | |
191 | |
192 NOT_PRODUCT(TraceTime tm("StealMarkingTask", | |
193 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); | |
194 | |
195 ParCompactionManager* cm = | |
196 ParCompactionManager::gc_thread_compaction_manager(which); | |
197 PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); | |
198 | |
199 oop obj = NULL; | |
1311
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
1000
diff
changeset
|
200 ObjArrayTask task; |
0 | 201 int random_seed = 17; |
1311
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
1000
diff
changeset
|
202 do { |
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
1000
diff
changeset
|
203 while (ParCompactionManager::steal_objarray(which, &random_seed, task)) { |
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
1000
diff
changeset
|
204 objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint(); |
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
1000
diff
changeset
|
205 k->oop_follow_contents(cm, task.obj(), task.index()); |
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
1000
diff
changeset
|
206 cm->follow_marking_stacks(); |
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
1000
diff
changeset
|
207 } |
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
1000
diff
changeset
|
208 while (ParCompactionManager::steal(which, &random_seed, obj)) { |
0 | 209 obj->follow_contents(cm); |
1311
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
1000
diff
changeset
|
210 cm->follow_marking_stacks(); |
0 | 211 } |
1311
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
1000
diff
changeset
|
212 } while (!terminator()->offer_termination()); |
0 | 213 } |
214 | |
215 // | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
216 // StealRegionCompactionTask |
0 | 217 // |
218 | |
219 | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
220 StealRegionCompactionTask::StealRegionCompactionTask(ParallelTaskTerminator* t): |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
221 _terminator(t) {} |
0 | 222 |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
223 void StealRegionCompactionTask::do_it(GCTaskManager* manager, uint which) { |
0 | 224 assert(Universe::heap()->is_gc_active(), "called outside gc"); |
225 | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
226 NOT_PRODUCT(TraceTime tm("StealRegionCompactionTask", |
0 | 227 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); |
228 | |
229 ParCompactionManager* cm = | |
230 ParCompactionManager::gc_thread_compaction_manager(which); | |
231 | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
232 // Has to drain stacks first because there may be regions on |
0 | 233 // preloaded onto the stack and this thread may never have |
234 // done a draining task. Are the draining tasks needed? | |
235 | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
236 cm->drain_region_stacks(); |
0 | 237 |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
238 size_t region_index = 0; |
0 | 239 int random_seed = 17; |
240 | |
241 // If we're the termination task, try 10 rounds of stealing before | |
242 // setting the termination flag | |
243 | |
244 while(true) { | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
245 if (ParCompactionManager::steal(which, &random_seed, region_index)) { |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
246 PSParallelCompact::fill_and_update_region(cm, region_index); |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
247 cm->drain_region_stacks(); |
0 | 248 } else { |
249 if (terminator()->offer_termination()) { | |
250 break; | |
251 } | |
252 // Go around again. | |
253 } | |
254 } | |
255 return; | |
256 } | |
257 | |
258 UpdateDensePrefixTask::UpdateDensePrefixTask( | |
259 PSParallelCompact::SpaceId space_id, | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
260 size_t region_index_start, |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
261 size_t region_index_end) : |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
262 _space_id(space_id), _region_index_start(region_index_start), |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
263 _region_index_end(region_index_end) {} |
0 | 264 |
265 void UpdateDensePrefixTask::do_it(GCTaskManager* manager, uint which) { | |
266 | |
267 NOT_PRODUCT(TraceTime tm("UpdateDensePrefixTask", | |
268 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); | |
269 | |
270 ParCompactionManager* cm = | |
271 ParCompactionManager::gc_thread_compaction_manager(which); | |
272 | |
273 PSParallelCompact::update_and_deadwood_in_dense_prefix(cm, | |
274 _space_id, | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
275 _region_index_start, |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
276 _region_index_end); |
0 | 277 } |
278 | |
279 void DrainStacksCompactionTask::do_it(GCTaskManager* manager, uint which) { | |
280 assert(Universe::heap()->is_gc_active(), "called outside gc"); | |
281 | |
282 NOT_PRODUCT(TraceTime tm("DrainStacksCompactionTask", | |
283 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); | |
284 | |
285 ParCompactionManager* cm = | |
286 ParCompactionManager::gc_thread_compaction_manager(which); | |
287 | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
288 // Process any regions already in the compaction managers stacks. |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
196
diff
changeset
|
289 cm->drain_region_stacks(); |
0 | 290 } |