test/hotspot/gtest/gc/g1/test_heapRegion.cpp
changeset 51027 01316e7ac1d1
parent 47885 5caa1d5f74c1
child 52877 9e041366c764
equal deleted inserted replaced
51026:510ac4c08610 51027:01316e7ac1d1
     1 /*
     1 /*
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2017, 2018, 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.
    25 #include "gc/g1/g1BlockOffsetTable.hpp"
    25 #include "gc/g1/g1BlockOffsetTable.hpp"
    26 #include "gc/g1/g1CollectedHeap.hpp"
    26 #include "gc/g1/g1CollectedHeap.hpp"
    27 #include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
    27 #include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
    28 #include "gc/g1/heapRegion.inline.hpp"
    28 #include "gc/g1/heapRegion.inline.hpp"
    29 #include "gc/shared/referenceProcessor.hpp"
    29 #include "gc/shared/referenceProcessor.hpp"
       
    30 #include "runtime/interfaceSupport.inline.hpp"
       
    31 #include "runtime/vm_operations.hpp"
       
    32 #include "runtime/vmThread.hpp"
    30 #include "unittest.hpp"
    33 #include "unittest.hpp"
    31 
    34 
    32 class VerifyAndCountMarkClosure : public StackObj {
    35 class VerifyAndCountMarkClosure : public StackObj {
    33   int _count;
    36   int _count;
    34   G1CMBitMap* _bm;
    37   G1CMBitMap* _bm;
    58 
    61 
    59 #define MARK_OFFSET_1 ( 17 * MinObjAlignment)
    62 #define MARK_OFFSET_1 ( 17 * MinObjAlignment)
    60 #define MARK_OFFSET_2 ( 99 * MinObjAlignment)
    63 #define MARK_OFFSET_2 ( 99 * MinObjAlignment)
    61 #define MARK_OFFSET_3 (337 * MinObjAlignment)
    64 #define MARK_OFFSET_3 (337 * MinObjAlignment)
    62 
    65 
    63 TEST_OTHER_VM(HeapRegion, apply_to_marked_objects) {
    66 class VM_HeapRegionApplyToMarkedObjectsTest : public VM_GTestExecuteAtSafepoint {
    64   if (!UseG1GC) {
    67 public:
    65     return;
    68   void doit();
    66   }
    69 };
    67 
    70 
       
    71 void VM_HeapRegionApplyToMarkedObjectsTest::doit() {
    68   G1CollectedHeap* heap = G1CollectedHeap::heap();
    72   G1CollectedHeap* heap = G1CollectedHeap::heap();
    69 
    73 
    70   // Using region 0 for testing.
    74   // Using region 0 for testing.
    71   HeapRegion* region = heap->heap_region_containing(heap->bottom_addr_for_region(0));
    75   HeapRegion* region = heap->heap_region_containing(heap->bottom_addr_for_region(0));
    72 
    76 
    77   bitmap->mark(region->bottom() + MARK_OFFSET_2);
    81   bitmap->mark(region->bottom() + MARK_OFFSET_2);
    78   bitmap->mark(region->bottom() + MARK_OFFSET_3);
    82   bitmap->mark(region->bottom() + MARK_OFFSET_3);
    79   bitmap->mark(region->end());
    83   bitmap->mark(region->end());
    80 
    84 
    81   VerifyAndCountMarkClosure cl(bitmap);
    85   VerifyAndCountMarkClosure cl(bitmap);
       
    86 
       
    87   HeapWord* old_top = region->top();
    82 
    88 
    83   // When top is equal to bottom the closure should not be
    89   // When top is equal to bottom the closure should not be
    84   // applied to any object because apply_to_marked_objects
    90   // applied to any object because apply_to_marked_objects
    85   // will stop at HeapRegion::scan_limit which is equal to top.
    91   // will stop at HeapRegion::scan_limit which is equal to top.
    86   region->set_top(region->bottom());
    92   region->set_top(region->bottom());
   110   // Setting top to end should render 4 entries.
   116   // Setting top to end should render 4 entries.
   111   region->set_top(region->end());
   117   region->set_top(region->end());
   112   region->apply_to_marked_objects(bitmap, &cl);
   118   region->apply_to_marked_objects(bitmap, &cl);
   113   EXPECT_EQ(4, cl.count());
   119   EXPECT_EQ(4, cl.count());
   114   cl.reset();
   120   cl.reset();
       
   121 
       
   122   region->set_top(old_top);
   115 }
   123 }
   116 
   124 
       
   125 TEST_VM(HeapRegion, apply_to_marked_object) {
       
   126   if (!UseG1GC) {
       
   127     return;
       
   128   }
       
   129 
       
   130   // Run the test in our very own safepoint, because otherwise it
       
   131   // modifies a region behind the back of a possibly using allocation
       
   132   // or running GC.
       
   133   VM_HeapRegionApplyToMarkedObjectsTest op;
       
   134   ThreadInVMfromNative invm(JavaThread::current());
       
   135   VMThread::execute(&op);
       
   136 }