< prev index next >

test/hotspot/gtest/oops/test_markWord.cpp

Print this page
rev 58110 : v2.09a with 8235795, 8235931 and 8236035 extracted; rebased to jdk-14+28; merge with 8236035.patch.cr1; merge with 8235795.patch.cr1; merge with 8236035.patch.cr2; merge with 8235795.patch.cr2; merge with 8235795.patch.cr3.
rev 58111 : See CR9-to-CR10-changes; merge with jdk-15+11.
   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  */


 106   markWord prototype_header = obj->klass()->prototype_header();
 107   markWord mark = obj->mark();
 108   markWord biased_mark = markWord::encode((JavaThread*) THREAD, mark.age(), prototype_header.bias_epoch());
 109   obj->set_mark(biased_mark);
 110   // Look for the biased_locker in markWord, not prototype_header.
 111 #ifdef _LP64
 112   assert_not_test_pattern(h_obj, "mark(is_biased biased_locker=0x0000000000000000");
 113 #else
 114   assert_not_test_pattern(h_obj, "mark(is_biased biased_locker=0x00000000");
 115 #endif
 116 
 117   // Same thread tries to lock it again.
 118   {
 119     ObjectLocker ol(h_obj, THREAD);
 120     assert_test_pattern(h_obj, "locked");
 121   }
 122 
 123   // This is no longer biased, because ObjectLocker revokes the bias.
 124   assert_test_pattern(h_obj, "is_neutral no_hash");
 125 




 126   // Wait gets the lock inflated.
 127   {
 128     ObjectLocker ol(h_obj, THREAD);
 129 
 130     Semaphore done(0);
 131     LockerThread* st;
 132     st = new LockerThread(&done, h_obj());
 133     st->doit();
 134 
 135     ol.wait(THREAD);
 136     assert_test_pattern(h_obj, "monitor");
 137     done.wait_with_safepoint_check(THREAD);  // wait till the thread is done.
 138   }
 139 



 140   // Make the object older. Not all GCs use this field.
 141   Universe::heap()->collect(GCCause::_java_lang_system_gc);
 142   if (UseParallelGC) {
 143     assert_test_pattern(h_obj, "is_neutral no_hash age 1");
 144   }
 145 
 146   // Hash the object then print it.
 147   intx hash = h_obj->identity_hash();
 148   assert_test_pattern(h_obj, "is_neutral hash=0x");

 149 }
 150 #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  */


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