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 #include "precompiled.hpp"
25 #include "gc/shared/gc_globals.hpp"
26 #include "gc/z/zAbort.inline.hpp"
27 #include "gc/z/zAddress.inline.hpp"
28 #include "gc/z/zBarrier.inline.hpp"
29 #include "gc/z/zForwarding.inline.hpp"
30 #include "gc/z/zHeap.inline.hpp"
31 #include "gc/z/zPage.inline.hpp"
32 #include "gc/z/zRelocate.hpp"
33 #include "gc/z/zRelocationSet.inline.hpp"
34 #include "gc/z/zStat.hpp"
35 #include "gc/z/zTask.hpp"
36 #include "gc/z/zThread.inline.hpp"
37 #include "gc/z/zWorkers.hpp"
38 #include "prims/jvmtiTagMap.hpp"
39 #include "runtime/atomic.hpp"
40 #include "utilities/debug.hpp"
41
42 ZRelocate::ZRelocate(ZWorkers* workers) :
43 _workers(workers) {}
44
45 static uintptr_t forwarding_index(ZForwarding* forwarding, uintptr_t from_addr) {
315 virtual void do_object(oop obj) {
316 const uintptr_t addr = ZOop::to_address(obj);
317 assert(ZHeap::heap()->is_object_live(addr), "Should be live");
318
319 while (!relocate_object(addr)) {
320 // Allocate a new target page, or if that fails, use the page being
321 // relocated as the new target, which will cause it to be relocated
322 // in-place.
323 _target = _allocator->alloc_target_page(_forwarding, _target);
324 if (_target != NULL) {
325 continue;
326 }
327
328 // Claim the page being relocated to block other threads from accessing
329 // it, or its forwarding table, until it has been released (relocation
330 // completed).
331 _target = _forwarding->claim_page();
332 _target->reset_for_in_place_relocation();
333 _forwarding->set_in_place();
334 }
335 }
336
337 public:
338 ZRelocateClosure(Allocator* allocator) :
339 _allocator(allocator),
340 _forwarding(NULL),
341 _target(NULL) {}
342
343 ~ZRelocateClosure() {
344 _allocator->free_target_page(_target);
345 }
346
347 void do_forwarding(ZForwarding* forwarding) {
348 _forwarding = forwarding;
349
350 // Check if we should abort
351 if (ZAbort::should_abort()) {
352 _forwarding->abort_page();
353 return;
354 }
386 static bool is_small(ZForwarding* forwarding) {
387 return forwarding->type() == ZPageTypeSmall;
388 }
389
390 public:
391 ZRelocateTask(ZRelocationSet* relocation_set) :
392 ZTask("ZRelocateTask"),
393 _iter(relocation_set),
394 _small_allocator(),
395 _medium_allocator() {}
396
397 ~ZRelocateTask() {
398 ZStatRelocation::set_at_relocate_end(_small_allocator.in_place_count(),
399 _medium_allocator.in_place_count());
400 }
401
402 virtual void work() {
403 ZRelocateClosure<ZRelocateSmallAllocator> small(&_small_allocator);
404 ZRelocateClosure<ZRelocateMediumAllocator> medium(&_medium_allocator);
405
406 for (ZForwarding* forwarding; _iter.next(&forwarding);) {
407 if (is_small(forwarding)) {
408 small.do_forwarding(forwarding);
409 } else {
410 medium.do_forwarding(forwarding);
411 }
412 }
413 }
414 };
415
416 void ZRelocate::relocate(ZRelocationSet* relocation_set) {
417 ZRelocateTask task(relocation_set);
418 _workers->run(&task);
419 }
|
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 #include "precompiled.hpp"
25 #include "gc/shared/gc_globals.hpp"
26 #include "gc/shared/suspendibleThreadSet.hpp"
27 #include "gc/z/zAbort.inline.hpp"
28 #include "gc/z/zAddress.inline.hpp"
29 #include "gc/z/zBarrier.inline.hpp"
30 #include "gc/z/zForwarding.inline.hpp"
31 #include "gc/z/zHeap.inline.hpp"
32 #include "gc/z/zPage.inline.hpp"
33 #include "gc/z/zRelocate.hpp"
34 #include "gc/z/zRelocationSet.inline.hpp"
35 #include "gc/z/zStat.hpp"
36 #include "gc/z/zTask.hpp"
37 #include "gc/z/zThread.inline.hpp"
38 #include "gc/z/zWorkers.hpp"
39 #include "prims/jvmtiTagMap.hpp"
40 #include "runtime/atomic.hpp"
41 #include "utilities/debug.hpp"
42
43 ZRelocate::ZRelocate(ZWorkers* workers) :
44 _workers(workers) {}
45
46 static uintptr_t forwarding_index(ZForwarding* forwarding, uintptr_t from_addr) {
316 virtual void do_object(oop obj) {
317 const uintptr_t addr = ZOop::to_address(obj);
318 assert(ZHeap::heap()->is_object_live(addr), "Should be live");
319
320 while (!relocate_object(addr)) {
321 // Allocate a new target page, or if that fails, use the page being
322 // relocated as the new target, which will cause it to be relocated
323 // in-place.
324 _target = _allocator->alloc_target_page(_forwarding, _target);
325 if (_target != NULL) {
326 continue;
327 }
328
329 // Claim the page being relocated to block other threads from accessing
330 // it, or its forwarding table, until it has been released (relocation
331 // completed).
332 _target = _forwarding->claim_page();
333 _target->reset_for_in_place_relocation();
334 _forwarding->set_in_place();
335 }
336
337 if (SuspendibleThreadSet::should_yield()) {
338 SuspendibleThreadSet::yield();
339 }
340 }
341
342 public:
343 ZRelocateClosure(Allocator* allocator) :
344 _allocator(allocator),
345 _forwarding(NULL),
346 _target(NULL) {}
347
348 ~ZRelocateClosure() {
349 _allocator->free_target_page(_target);
350 }
351
352 void do_forwarding(ZForwarding* forwarding) {
353 _forwarding = forwarding;
354
355 // Check if we should abort
356 if (ZAbort::should_abort()) {
357 _forwarding->abort_page();
358 return;
359 }
391 static bool is_small(ZForwarding* forwarding) {
392 return forwarding->type() == ZPageTypeSmall;
393 }
394
395 public:
396 ZRelocateTask(ZRelocationSet* relocation_set) :
397 ZTask("ZRelocateTask"),
398 _iter(relocation_set),
399 _small_allocator(),
400 _medium_allocator() {}
401
402 ~ZRelocateTask() {
403 ZStatRelocation::set_at_relocate_end(_small_allocator.in_place_count(),
404 _medium_allocator.in_place_count());
405 }
406
407 virtual void work() {
408 ZRelocateClosure<ZRelocateSmallAllocator> small(&_small_allocator);
409 ZRelocateClosure<ZRelocateMediumAllocator> medium(&_medium_allocator);
410
411 SuspendibleThreadSetJoiner sts_joiner;
412 for (ZForwarding* forwarding; _iter.next(&forwarding);) {
413 if (is_small(forwarding)) {
414 small.do_forwarding(forwarding);
415 } else {
416 medium.do_forwarding(forwarding);
417 }
418 }
419 }
420 };
421
422 void ZRelocate::relocate(ZRelocationSet* relocation_set) {
423 ZRelocateTask task(relocation_set);
424 _workers->run(&task);
425 }
|