1 /*
2 * Copyright (c) 2022, 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 "memory/allocation.hpp"
26 #include "utilities/objectBitSet.inline.hpp"
27 #include "unittest.hpp"
28
29 TEST_VM(ObjectBitSet, empty) {
30 ObjectBitSet<mtTracing> obs;
31 oopDesc obj1;
32 ASSERT_FALSE(obs.is_marked(&obj1));
33 }
34
35 // NOTE: This is a little weird. NULL is not treated any special: ObjectBitSet will happily
36 // allocate a fragement for the memory range starting at 0 and mark the first bit when passing NULL.
37 // In the absense of any error handling, I am not sure what would possibly be a reasonable better
38 // way to do it, though.
39 TEST_VM(ObjectBitSet, null) {
40 ObjectBitSet<mtTracing> obs;
41 ASSERT_FALSE(obs.is_marked((oop)NULL));
42 obs.mark_obj((oop) NULL);
43 ASSERT_TRUE(obs.is_marked((oop)NULL));
44 }
45
46 TEST_VM(ObjectBitSet, mark_single) {
47 ObjectBitSet<mtTracing> obs;
48 oopDesc obj1;
49 ASSERT_FALSE(obs.is_marked(&obj1));
50 obs.mark_obj(&obj1);
51 ASSERT_TRUE(obs.is_marked(&obj1));
52 }
53
54 TEST_VM(ObjectBitSet, mark_multi) {
55 ObjectBitSet<mtTracing> obs;
56 oopDesc obj1;
57 oopDesc obj2;
58 ASSERT_FALSE(obs.is_marked(&obj1));
59 ASSERT_FALSE(obs.is_marked(&obj2));
60 obs.mark_obj(&obj1);
61 ASSERT_TRUE(obs.is_marked(&obj1));
62 ASSERT_FALSE(obs.is_marked(&obj2));
63 obs.mark_obj(&obj2);
64 ASSERT_TRUE(obs.is_marked(&obj1));
65 ASSERT_TRUE(obs.is_marked(&obj2));
66 }