< prev index next >

test/hotspot/gtest/gc/z/test_zPhysicalMemory.cpp

Print this page


   1 /*
   2  * Copyright (c) 2016, 2018, 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 #include "precompiled.hpp"
  25 #include "gc/z/zGlobals.hpp"
  26 #include "gc/z/zPhysicalMemory.inline.hpp"
  27 #include "utilities/debug.hpp"
  28 #include "unittest.hpp"
  29 
  30 #if defined(AMD64)
  31 
  32 TEST(ZPhysicalMemorySegmentTest, split) {
  33   ZPhysicalMemorySegment seg(0, 10 * ZGranuleSize);
  34 
  35   ZPhysicalMemorySegment seg_split0 = seg.split(0 * ZGranuleSize);
  36   EXPECT_EQ(seg_split0.size(),  0 * ZGranuleSize);
  37   EXPECT_EQ(       seg.size(), 10 * ZGranuleSize);
  38 
  39   ZPhysicalMemorySegment seg_split1 = seg.split(5 * ZGranuleSize);
  40   EXPECT_EQ(seg_split1.size(),  5 * ZGranuleSize);
  41   EXPECT_EQ(       seg.size(),  5 * ZGranuleSize);
  42 
  43   ZPhysicalMemorySegment seg_split2 = seg.split(5 * ZGranuleSize);
  44   EXPECT_EQ(seg_split2.size(),  5 * ZGranuleSize);
  45   EXPECT_EQ(       seg.size(),  0 * ZGranuleSize);
  46 
  47   ZPhysicalMemorySegment seg_split3 = seg.split(0 * ZGranuleSize);
  48   EXPECT_EQ(seg_split3.size(),  0 * ZGranuleSize);
  49   EXPECT_EQ(       seg.size(),  0 * ZGranuleSize);




  50 }
  51 
  52 TEST(ZPhysicalMemoryTest, split) {
  53   ZPhysicalMemoryManager pmem_manager(10 * ZGranuleSize);
  54 
  55   pmem_manager.try_ensure_unused_capacity(10 * ZGranuleSize);
  56   EXPECT_EQ(pmem_manager.unused_capacity(), 10 * ZGranuleSize);
  57 
  58   ZPhysicalMemory pmem = pmem_manager.alloc(8 * ZGranuleSize);
  59   EXPECT_EQ(pmem.nsegments(), 1u) << "wrong number of segments";
  60 
  61   ZPhysicalMemory split0_pmem = pmem.split(ZGranuleSize);
  62   EXPECT_EQ(split0_pmem.nsegments(), 1u);
  63   EXPECT_EQ(       pmem.nsegments(), 1u);
  64   EXPECT_EQ(split0_pmem.size(), 1 * ZGranuleSize);
  65   EXPECT_EQ(       pmem.size(), 7 * ZGranuleSize);
  66 
  67   ZPhysicalMemory split1_pmem = pmem.split(2 * ZGranuleSize);
  68   EXPECT_EQ(split1_pmem.nsegments(), 1u);
  69   EXPECT_EQ(       pmem.nsegments(), 1u);
  70   EXPECT_EQ(split1_pmem.size(), 2 * ZGranuleSize);
  71   EXPECT_EQ(       pmem.size(), 5 * ZGranuleSize);
  72 
  73   ZPhysicalMemory split2_pmem = pmem.split(5 * ZGranuleSize);
  74   EXPECT_EQ(split2_pmem.nsegments(), 1u);
  75   EXPECT_EQ(       pmem.nsegments(), 1u);
  76   EXPECT_EQ(split2_pmem.size(), 5 * ZGranuleSize);
  77   EXPECT_EQ(       pmem.size(), 0 * ZGranuleSize);


































  78 }
  79 
  80 #endif
   1 /*
   2  * Copyright (c) 2016, 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 #include "precompiled.hpp"

  25 #include "gc/z/zPhysicalMemory.inline.hpp"

  26 #include "unittest.hpp"
  27 
  28 TEST(ZPhysicalMemoryTest, copy) {
  29   const ZPhysicalMemorySegment seg0(0,   100);
  30   const ZPhysicalMemorySegment seg1(200, 100);
  31 
  32   ZPhysicalMemory pmem0;
  33   pmem0.add_segment(seg0);
  34   EXPECT_EQ(pmem0.nsegments(), 1u) << "wrong number of segments";
  35   EXPECT_EQ(pmem0.segment(0).size(), 100u) << "wrong segment size";
  36 
  37   ZPhysicalMemory pmem1;
  38   pmem1.add_segment(seg0);
  39   pmem1.add_segment(seg1);
  40   EXPECT_EQ(pmem1.nsegments(), 2u) << "wrong number of segments";
  41   EXPECT_EQ(pmem1.segment(0).size(), 100u) << "wrong segment size";
  42   EXPECT_EQ(pmem1.segment(1).size(), 100u) << "wrong segment size";
  43 
  44   ZPhysicalMemory pmem2(pmem0);
  45   EXPECT_EQ(pmem2.nsegments(), 1u) << "wrong number of segments";
  46   EXPECT_EQ(pmem2.segment(0).size(), 100u) << "wrong segment size";
  47 
  48   pmem2 = pmem1;
  49   EXPECT_EQ(pmem2.nsegments(), 2u) << "wrong number of segments";
  50   EXPECT_EQ(pmem2.segment(0).size(), 100u) << "wrong segment size";
  51   EXPECT_EQ(pmem2.segment(1).size(), 100u) << "wrong segment size";
  52 }
  53 
  54 TEST(ZPhysicalMemoryTest, segments) {
  55   const ZPhysicalMemorySegment seg0(0, 1);
  56   const ZPhysicalMemorySegment seg1(1, 1);
  57   const ZPhysicalMemorySegment seg2(2, 1);
  58   const ZPhysicalMemorySegment seg3(3, 1);
  59   const ZPhysicalMemorySegment seg4(4, 1);
  60   const ZPhysicalMemorySegment seg5(5, 1);
  61   const ZPhysicalMemorySegment seg6(6, 1);
  62 
  63   ZPhysicalMemory pmem0;
  64   EXPECT_EQ(pmem0.nsegments(), 0u) << "wrong number of segments";
  65   EXPECT_EQ(pmem0.is_null(), true) << "should be null";
  66 
  67   ZPhysicalMemory pmem1;
  68   pmem1.add_segment(seg0);
  69   pmem1.add_segment(seg1);
  70   pmem1.add_segment(seg2);
  71   pmem1.add_segment(seg3);
  72   pmem1.add_segment(seg4);
  73   pmem1.add_segment(seg5);
  74   pmem1.add_segment(seg6);
  75   EXPECT_EQ(pmem1.nsegments(), 1u) << "wrong number of segments";
  76   EXPECT_EQ(pmem1.segment(0).size(), 7u) << "wrong segment size";
  77   EXPECT_EQ(pmem1.is_null(), false) << "should not be null";
  78 
  79   ZPhysicalMemory pmem2;
  80   pmem2.add_segment(seg0);
  81   pmem2.add_segment(seg1);
  82   pmem2.add_segment(seg2);
  83   pmem2.add_segment(seg4);
  84   pmem2.add_segment(seg5);
  85   pmem2.add_segment(seg6);
  86   EXPECT_EQ(pmem2.nsegments(), 2u) << "wrong number of segments";
  87   EXPECT_EQ(pmem2.segment(0).size(), 3u) << "wrong segment size";
  88   EXPECT_EQ(pmem2.segment(1).size(), 3u) << "wrong segment size";
  89   EXPECT_EQ(pmem2.is_null(), false) << "should not be null";
  90 
  91   ZPhysicalMemory pmem3;
  92   pmem3.add_segment(seg0);
  93   pmem3.add_segment(seg2);
  94   pmem3.add_segment(seg3);
  95   pmem3.add_segment(seg4);
  96   pmem3.add_segment(seg6);
  97   EXPECT_EQ(pmem3.nsegments(), 3u) << "wrong number of segments";
  98   EXPECT_EQ(pmem3.segment(0).size(), 1u) << "wrong segment size";
  99   EXPECT_EQ(pmem3.segment(1).size(), 3u) << "wrong segment size";
 100   EXPECT_EQ(pmem3.segment(2).size(), 1u) << "wrong segment size";
 101   EXPECT_EQ(pmem3.is_null(), false) << "should not be null";
 102 
 103   ZPhysicalMemory pmem4;
 104   pmem4.add_segment(seg0);
 105   pmem4.add_segment(seg2);
 106   pmem4.add_segment(seg4);
 107   pmem4.add_segment(seg6);
 108   EXPECT_EQ(pmem4.nsegments(), 4u) << "wrong number of segments";
 109   EXPECT_EQ(pmem4.segment(0).size(), 1u) << "wrong segment size";
 110   EXPECT_EQ(pmem4.segment(1).size(), 1u) << "wrong segment size";
 111   EXPECT_EQ(pmem4.segment(2).size(), 1u) << "wrong segment size";
 112   EXPECT_EQ(pmem4.segment(3).size(), 1u) << "wrong segment size";
 113   EXPECT_EQ(pmem4.is_null(), false) << "should not be null";
 114 }


< prev index next >