test/hotspot/gtest/oops/test_markOop.cpp
author shade
Wed, 08 May 2019 23:53:24 +0200
changeset 54771 d266d24b6a0e
parent 54765 cc6053cbd811
child 57384 4a296d9a76a0
child 57777 90ead0febf56
child 58678 9cf78a70fa4f
permissions -rw-r--r--
8223589: Build failures after JDK-8223534 (add back fixed test_markOop.cpp) Reviewed-by: coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54765
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
     1
/*
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
     4
 *
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
     8
 *
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    13
 * accompanied this code).
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    14
 *
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    18
 *
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    21
 * questions.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    22
 */
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    23
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    24
#include "precompiled.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    25
#include "classfile/systemDictionary.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    26
#include "memory/resourceArea.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    27
#include "memory/universe.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    28
#include "oops/oop.inline.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    29
#include "runtime/atomic.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    30
#include "runtime/interfaceSupport.inline.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    31
#include "runtime/orderAccess.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    32
#include "runtime/os.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    33
#include "runtime/synchronizer.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    34
#include "runtime/semaphore.inline.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    35
#include "threadHelper.inline.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    36
#include "unittest.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    37
#include "utilities/globalDefinitions.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    38
#include "utilities/ostream.hpp"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    39
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    40
// The test doesn't work for PRODUCT because it needs WizardMode
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    41
#ifndef PRODUCT
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    42
static bool test_pattern(stringStream* st, const char* pattern) {
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    43
  return (strstr(st->as_string(), pattern) != NULL);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    44
}
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    45
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    46
static void assert_test_pattern(Handle object, const char* pattern) {
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    47
  stringStream st;
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    48
  object->print_on(&st);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    49
  ASSERT_TRUE(test_pattern(&st, pattern)) << pattern << " not in " << st.as_string();
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    50
}
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    51
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    52
static void assert_not_test_pattern(Handle object, const char* pattern) {
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    53
  stringStream st;
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    54
  object->print_on(&st);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    55
  ASSERT_FALSE(test_pattern(&st, pattern)) << pattern << " found in " << st.as_string();
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    56
}
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    57
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    58
class LockerThread : public JavaTestThread {
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    59
  oop _obj;
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    60
  public:
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    61
  LockerThread(Semaphore* post, oop obj) : JavaTestThread(post), _obj(obj) {}
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    62
  virtual ~LockerThread() {}
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    63
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    64
  void main_run() {
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    65
    Thread* THREAD = Thread::current();
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    66
    HandleMark hm(THREAD);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    67
    Handle h_obj(THREAD, _obj);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    68
    ResourceMark rm(THREAD);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    69
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    70
    // Wait gets the lock inflated.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    71
    // The object will stay locked for the context of 'ol' so the lock will
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    72
    // still be inflated after the notify_all() call. Deflation can't happen
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    73
    // while an ObjectMonitor is "busy" and being locked is the most "busy"
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    74
    // state we have...
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    75
    ObjectLocker ol(h_obj, THREAD);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    76
    ol.notify_all(THREAD);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    77
    assert_test_pattern(h_obj, "monitor");
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    78
  }
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    79
};
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    80
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    81
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    82
TEST_VM(markOopDesc, printing) {
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    83
  JavaThread* THREAD = JavaThread::current();
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    84
  ThreadInVMfromNative invm(THREAD);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    85
  ResourceMark rm(THREAD);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    86
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    87
  oop obj = SystemDictionary::Byte_klass()->allocate_instance(THREAD);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    88
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    89
  FlagSetting fs(WizardMode, true);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    90
  FlagSetting bf(UseBiasedLocking, true);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    91
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    92
  HandleMark hm(THREAD);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    93
  Handle h_obj(THREAD, obj);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    94
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    95
  // Biased locking is initially enabled for this java.lang.Byte object.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    96
  assert_test_pattern(h_obj, "is_biased");
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    97
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    98
  // Lock using biased locking.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
    99
  BasicObjectLock lock;
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   100
  lock.set_obj(obj);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   101
  markOop mark = obj->mark()->incr_bias_epoch();
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   102
  obj->set_mark(mark);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   103
  ObjectSynchronizer::fast_enter(h_obj, lock.lock(), true, THREAD);
54771
d266d24b6a0e 8223589: Build failures after JDK-8223534 (add back fixed test_markOop.cpp)
shade
parents: 54765
diff changeset
   104
  // Look for the biased_locker in markOop, not prototype_header.
54765
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   105
#ifdef _LP64
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   106
  assert_not_test_pattern(h_obj, "mark(is_biased biased_locker=0x0000000000000000");
54771
d266d24b6a0e 8223589: Build failures after JDK-8223534 (add back fixed test_markOop.cpp)
shade
parents: 54765
diff changeset
   107
#else
d266d24b6a0e 8223589: Build failures after JDK-8223534 (add back fixed test_markOop.cpp)
shade
parents: 54765
diff changeset
   108
  assert_not_test_pattern(h_obj, "mark(is_biased biased_locker=0x00000000");
54765
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   109
#endif
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   110
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   111
  // Same thread tries to lock it again.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   112
  {
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   113
    ObjectLocker ol(h_obj, THREAD);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   114
    assert_test_pattern(h_obj, "locked");
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   115
  }
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   116
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   117
  // This is no longer biased, because ObjectLocker revokes the bias.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   118
  assert_test_pattern(h_obj, "is_neutral no_hash");
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   119
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   120
  // Wait gets the lock inflated.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   121
  {
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   122
    ObjectLocker ol(h_obj, THREAD);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   123
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   124
    Semaphore done(0);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   125
    LockerThread* st;
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   126
    st = new LockerThread(&done, h_obj());
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   127
    st->doit();
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   128
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   129
    ol.wait(THREAD);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   130
    assert_test_pattern(h_obj, "monitor");
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   131
    done.wait_with_safepoint_check(THREAD);  // wait till the thread is done.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   132
  }
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   133
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   134
  // Make the object older. Not all GCs use this field.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   135
  Universe::heap()->collect(GCCause::_java_lang_system_gc);
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   136
  if (UseParallelGC) {
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   137
    assert_test_pattern(h_obj, "is_neutral no_hash age 1");
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   138
  }
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   139
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   140
  // Hash the object then print it.
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   141
  intx hash = h_obj->identity_hash();
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   142
  assert_test_pattern(h_obj, "is_neutral hash=0x");
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   143
}
cc6053cbd811 8223534: add back fixed test_markOop.cpp
coleenp
parents:
diff changeset
   144
#endif // PRODUCT