author | herrick |
Mon, 17 Jun 2019 15:18:52 -0400 | |
branch | JDK-8200758-branch |
changeset 57412 | 02034583f4dc |
parent 54623 | 1126f0607c70 |
permissions | -rw-r--r-- |
54437
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
1 |
/* |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, 2018 Oracle and/or its affiliates. All rights reserved. |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
4 |
* |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
8 |
* |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
13 |
* accompanied this code). |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
14 |
* |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
18 |
* |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
21 |
* questions. |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
22 |
*/ |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
23 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
24 |
#include "precompiled.hpp" |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
25 |
#include "memory/allocation.inline.hpp" |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
26 |
#include "memory/metaspace.hpp" |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
27 |
#include "memory/metaspace/virtualSpaceList.hpp" |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
28 |
#include "runtime/mutex.hpp" |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
29 |
#include "runtime/mutexLocker.hpp" |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
30 |
#include "runtime/os.hpp" |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
31 |
#include "unittest.hpp" |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
32 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
33 |
using namespace metaspace; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
34 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
35 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
36 |
// Test the cheerful multitude of metaspace-contains-functions. |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
37 |
class MetaspaceIsMetaspaceObjTest : public ::testing::Test { |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
38 |
Mutex* _lock; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
39 |
ClassLoaderMetaspace* _ms; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
40 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
41 |
public: |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
42 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
43 |
MetaspaceIsMetaspaceObjTest() : _lock(NULL), _ms(NULL) {} |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
44 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
45 |
virtual void SetUp() { |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
46 |
} |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
47 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
48 |
virtual void TearDown() { |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
49 |
delete _ms; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
50 |
delete _lock; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
51 |
} |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
52 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
53 |
void do_test(Metaspace::MetadataType mdType) { |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
54 |
_lock = new Mutex(Monitor::native, "gtest-IsMetaspaceObjTest-lock", false, Monitor::_safepoint_check_never); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
55 |
{ |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54437
diff
changeset
|
56 |
MutexLocker ml(_lock, Mutex::_no_safepoint_check_flag); |
54437
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
57 |
_ms = new ClassLoaderMetaspace(_lock, Metaspace::StandardMetaspaceType); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
58 |
} |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
59 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
60 |
const MetaspaceObj* p = (MetaspaceObj*) _ms->allocate(42, mdType); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
61 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
62 |
// Test MetaspaceObj::is_metaspace_object |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
63 |
ASSERT_TRUE(MetaspaceObj::is_valid(p)); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
64 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
65 |
// A misaligned object shall not be recognized |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
66 |
const MetaspaceObj* p_misaligned = (MetaspaceObj*)((address)p) + 1; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
67 |
ASSERT_FALSE(MetaspaceObj::is_valid(p_misaligned)); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
68 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
69 |
// Test VirtualSpaceList::contains and find_enclosing_space |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
70 |
VirtualSpaceList* list = Metaspace::space_list(); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
71 |
if (mdType == Metaspace::ClassType && Metaspace::using_class_space()) { |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
72 |
list = Metaspace::class_space_list(); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
73 |
} |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
74 |
ASSERT_TRUE(list->contains(p)); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
75 |
VirtualSpaceNode* const n = list->find_enclosing_space(p); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
76 |
ASSERT_TRUE(n != NULL); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
77 |
ASSERT_TRUE(n->contains(p)); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
78 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
79 |
// A misaligned pointer shall be recognized by list::contains |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
80 |
ASSERT_TRUE(list->contains((address)p) + 1); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
81 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
82 |
// Now for some bogus values |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
83 |
ASSERT_FALSE(MetaspaceObj::is_valid((MetaspaceObj*)NULL)); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
84 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
85 |
// Should exercise various paths in MetaspaceObj::is_valid() |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
86 |
ASSERT_FALSE(MetaspaceObj::is_valid((MetaspaceObj*)1024)); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
87 |
ASSERT_FALSE(MetaspaceObj::is_valid((MetaspaceObj*)8192)); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
88 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
89 |
MetaspaceObj* p_stack = (MetaspaceObj*) &_lock; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
90 |
ASSERT_FALSE(MetaspaceObj::is_valid(p_stack)); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
91 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
92 |
MetaspaceObj* p_heap = (MetaspaceObj*) os::malloc(41, mtInternal); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
93 |
ASSERT_FALSE(MetaspaceObj::is_valid(p_heap)); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
94 |
os::free(p_heap); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
95 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
96 |
// Test Metaspace::contains_xxx |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
97 |
ASSERT_TRUE(Metaspace::contains(p)); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
98 |
ASSERT_TRUE(Metaspace::contains_non_shared(p)); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
99 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
100 |
delete _ms; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
101 |
_ms = NULL; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
102 |
delete _lock; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
103 |
_lock = NULL; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
104 |
} |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
105 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
106 |
}; |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
107 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
108 |
TEST_VM_F(MetaspaceIsMetaspaceObjTest, non_class_space) { |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
109 |
do_test(Metaspace::NonClassType); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
110 |
} |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
111 |
|
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
112 |
TEST_VM_F(MetaspaceIsMetaspaceObjTest, class_space) { |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
113 |
do_test(Metaspace::ClassType); |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
114 |
} |
2ae93028bef3
8221539: [metaspace] Improve MetaspaceObj::is_metaspace_obj() and friends
stuefe
parents:
diff
changeset
|
115 |