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); |
35 | EXPECT_EQ(pmem0.segment(0).size(), 100u); |
36 | |
37 | ZPhysicalMemory pmem1; |
38 | pmem1.add_segment(seg0); |
39 | pmem1.add_segment(seg1); |
40 | EXPECT_EQ(pmem1.nsegments(), 2u); |
41 | EXPECT_EQ(pmem1.segment(0).size(), 100u); |
42 | EXPECT_EQ(pmem1.segment(1).size(), 100u); |
43 | |
44 | ZPhysicalMemory pmem2(pmem0); |
45 | EXPECT_EQ(pmem2.nsegments(), 1u); |
46 | EXPECT_EQ(pmem2.segment(0).size(), 100u); |
47 | |
48 | pmem2 = pmem1; |
49 | EXPECT_EQ(pmem2.nsegments(), 2u); |
50 | EXPECT_EQ(pmem2.segment(0).size(), 100u); |
51 | EXPECT_EQ(pmem2.segment(1).size(), 100u); |
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); |
65 | EXPECT_EQ(pmem0.is_null(), true); |
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); |
76 | EXPECT_EQ(pmem1.segment(0).size(), 7u); |
77 | EXPECT_EQ(pmem1.is_null(), false); |
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); |
87 | EXPECT_EQ(pmem2.segment(0).size(), 3u); |
88 | EXPECT_EQ(pmem2.segment(1).size(), 3u); |
89 | EXPECT_EQ(pmem2.is_null(), false); |
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); |
98 | EXPECT_EQ(pmem3.segment(0).size(), 1u); |
99 | EXPECT_EQ(pmem3.segment(1).size(), 3u); |
100 | EXPECT_EQ(pmem3.segment(2).size(), 1u); |
101 | EXPECT_EQ(pmem3.is_null(), false); |
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); |
109 | EXPECT_EQ(pmem4.segment(0).size(), 1u); |
110 | EXPECT_EQ(pmem4.segment(1).size(), 1u); |
111 | EXPECT_EQ(pmem4.segment(2).size(), 1u); |
112 | EXPECT_EQ(pmem4.segment(3).size(), 1u); |
113 | EXPECT_EQ(pmem4.is_null(), false); |
114 | } |
115 | |
116 | TEST(ZPhysicalMemoryTest, split) { |
117 | ZPhysicalMemory pmem; |
118 | |
119 | pmem.add_segment(ZPhysicalMemorySegment(0, 10)); |
120 | pmem.add_segment(ZPhysicalMemorySegment(10, 10)); |
121 | pmem.add_segment(ZPhysicalMemorySegment(30, 10)); |
122 | EXPECT_EQ(pmem.nsegments(), 2u); |
123 | EXPECT_EQ(pmem.size(), 30u); |
124 | |
125 | ZPhysicalMemory pmem0 = pmem.split(1); |
126 | EXPECT_EQ(pmem0.nsegments(), 1u); |
127 | EXPECT_EQ(pmem0.size(), 1u); |
128 | EXPECT_EQ(pmem.nsegments(), 2u); |
129 | EXPECT_EQ(pmem.size(), 29u); |
130 | |
131 | ZPhysicalMemory pmem1 = pmem.split(25); |
132 | EXPECT_EQ(pmem1.nsegments(), 2u); |
133 | EXPECT_EQ(pmem1.size(), 25u); |
134 | EXPECT_EQ(pmem.nsegments(), 1u); |
135 | EXPECT_EQ(pmem.size(), 4u); |
136 | |
137 | ZPhysicalMemory pmem2 = pmem.split(4); |
138 | EXPECT_EQ(pmem2.nsegments(), 1u); |
139 | EXPECT_EQ(pmem2.size(), 4u); |
140 | EXPECT_EQ(pmem.nsegments(), 0u); |
141 | EXPECT_EQ(pmem.size(), 0u); |
142 | } |
143 | |