1 /*
2 * Copyright (c) 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 */
104 markWord mark = obj->mark();
105 markWord biased_mark = markWord::encode((JavaThread*) THREAD, mark.age(), prototype_header.bias_epoch());
106 obj->set_mark(biased_mark);
107 // Look for the biased_locker in markWord, not prototype_header.
108 #ifdef _LP64
109 assert_not_test_pattern(h_obj, "mark(is_biased biased_locker=0x0000000000000000");
110 #else
111 assert_not_test_pattern(h_obj, "mark(is_biased biased_locker=0x00000000");
112 #endif
113 }
114
115 // Same thread tries to lock it again.
116 {
117 ObjectLocker ol(h_obj, THREAD);
118 assert_test_pattern(h_obj, "locked");
119 }
120
121 // This is no longer biased, because ObjectLocker revokes the bias.
122 assert_test_pattern(h_obj, "is_neutral no_hash");
123
124 // Wait gets the lock inflated.
125 {
126 ObjectLocker ol(h_obj, THREAD);
127
128 Semaphore done(0);
129 LockerThread* st;
130 st = new LockerThread(&done, h_obj());
131 st->doit();
132
133 ol.wait(THREAD);
134 assert_test_pattern(h_obj, "monitor");
135 done.wait_with_safepoint_check(THREAD); // wait till the thread is done.
136 }
137
138 // Make the object older. Not all GCs use this field.
139 Universe::heap()->collect(GCCause::_java_lang_system_gc);
140 if (UseParallelGC) {
141 assert_test_pattern(h_obj, "is_neutral no_hash age 1");
142 }
143
144 // Hash the object then print it.
145 intx hash = h_obj->identity_hash();
146 assert_test_pattern(h_obj, "is_neutral hash=0x");
147 }
148 #endif // PRODUCT
|
1 /*
2 * Copyright (c) 2019, 2020, 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 */
104 markWord mark = obj->mark();
105 markWord biased_mark = markWord::encode((JavaThread*) THREAD, mark.age(), prototype_header.bias_epoch());
106 obj->set_mark(biased_mark);
107 // Look for the biased_locker in markWord, not prototype_header.
108 #ifdef _LP64
109 assert_not_test_pattern(h_obj, "mark(is_biased biased_locker=0x0000000000000000");
110 #else
111 assert_not_test_pattern(h_obj, "mark(is_biased biased_locker=0x00000000");
112 #endif
113 }
114
115 // Same thread tries to lock it again.
116 {
117 ObjectLocker ol(h_obj, THREAD);
118 assert_test_pattern(h_obj, "locked");
119 }
120
121 // This is no longer biased, because ObjectLocker revokes the bias.
122 assert_test_pattern(h_obj, "is_neutral no_hash");
123
124 // Hash the object then print it.
125 intx hash = h_obj->identity_hash();
126 assert_test_pattern(h_obj, "is_neutral hash=0x");
127
128 // Wait gets the lock inflated.
129 {
130 ObjectLocker ol(h_obj, THREAD);
131
132 Semaphore done(0);
133 LockerThread* st;
134 st = new LockerThread(&done, h_obj());
135 st->doit();
136
137 ol.wait(THREAD);
138 assert_test_pattern(h_obj, "monitor");
139 done.wait_with_safepoint_check(THREAD); // wait till the thread is done.
140 }
141
142 if (!AsyncDeflateIdleMonitors) {
143 // With AsyncDeflateIdleMonitors, the collect() call below
144 // does not guarantee monitor deflation.
145 // Make the object older. Not all GCs use this field.
146 Universe::heap()->collect(GCCause::_java_lang_system_gc);
147 if (UseParallelGC) {
148 assert_test_pattern(h_obj, "is_neutral no_hash age 1");
149 }
150
151 // Hash the object then print it.
152 intx hash = h_obj->identity_hash();
153 assert_test_pattern(h_obj, "is_neutral hash=0x");
154 }
155 }
156 #endif // PRODUCT
|