test/hotspot/gtest/code/test_dependencyContext.cpp
author eosterlund
Fri, 30 Nov 2018 11:40:48 +0100
changeset 52781 436097b038a1
parent 51887 32161fbea3fe
permissions -rw-r--r--
8213565: Crash in DependencyContext::remove_dependent_nmethod Reviewed-by: rehn, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
     1
/*
51887
32161fbea3fe 8210856: Move InstanceKlass DependencyContext cleaning to SystemDictionary::do_unloading()
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
     4
 *
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
     8
 *
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    13
 * accompanied this code).
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    14
 *
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    18
 *
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    21
 * questions.
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    22
 *
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    23
 */
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    24
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    25
#include "precompiled.hpp"
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    26
#include "code/dependencyContext.hpp"
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    27
#include "code/nmethod.hpp"
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    28
#include "unittest.hpp"
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    29
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    30
class TestDependencyContext {
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    31
 public:
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    32
  nmethod _nmethods[3];
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    33
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    34
  nmethodBucket* volatile _dependency_context;
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    35
  volatile uint64_t _last_cleanup;
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    36
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    37
  DependencyContext dependencies() {
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    38
    DependencyContext depContext(&_dependency_context, &_last_cleanup);
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    39
    return depContext;
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    40
  }
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    41
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    42
  TestDependencyContext()
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    43
    : _dependency_context(NULL),
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    44
      _last_cleanup(0) {
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    45
    CodeCache_lock->lock_without_safepoint_check();
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    46
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    47
    _nmethods[0].clear_unloading_state();
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    48
    _nmethods[1].clear_unloading_state();
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    49
    _nmethods[2].clear_unloading_state();
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    50
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    51
    dependencies().add_dependent_nmethod(&_nmethods[2]);
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    52
    dependencies().add_dependent_nmethod(&_nmethods[1]);
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    53
    dependencies().add_dependent_nmethod(&_nmethods[0]);
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    54
  }
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    55
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    56
  ~TestDependencyContext() {
51887
32161fbea3fe 8210856: Move InstanceKlass DependencyContext cleaning to SystemDictionary::do_unloading()
coleenp
parents: 47216
diff changeset
    57
    wipe();
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    58
    CodeCache_lock->unlock();
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    59
  }
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    60
51887
32161fbea3fe 8210856: Move InstanceKlass DependencyContext cleaning to SystemDictionary::do_unloading()
coleenp
parents: 47216
diff changeset
    61
  void wipe() {
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    62
    DependencyContext ctx(&_dependency_context, &_last_cleanup);
51887
32161fbea3fe 8210856: Move InstanceKlass DependencyContext cleaning to SystemDictionary::do_unloading()
coleenp
parents: 47216
diff changeset
    63
    nmethodBucket* b = ctx.dependencies();
32161fbea3fe 8210856: Move InstanceKlass DependencyContext cleaning to SystemDictionary::do_unloading()
coleenp
parents: 47216
diff changeset
    64
    ctx.set_dependencies(NULL);
32161fbea3fe 8210856: Move InstanceKlass DependencyContext cleaning to SystemDictionary::do_unloading()
coleenp
parents: 47216
diff changeset
    65
    while (b != NULL) {
32161fbea3fe 8210856: Move InstanceKlass DependencyContext cleaning to SystemDictionary::do_unloading()
coleenp
parents: 47216
diff changeset
    66
      nmethodBucket* next = b->next();
32161fbea3fe 8210856: Move InstanceKlass DependencyContext cleaning to SystemDictionary::do_unloading()
coleenp
parents: 47216
diff changeset
    67
      delete b;
32161fbea3fe 8210856: Move InstanceKlass DependencyContext cleaning to SystemDictionary::do_unloading()
coleenp
parents: 47216
diff changeset
    68
      b = next;
32161fbea3fe 8210856: Move InstanceKlass DependencyContext cleaning to SystemDictionary::do_unloading()
coleenp
parents: 47216
diff changeset
    69
    }
32161fbea3fe 8210856: Move InstanceKlass DependencyContext cleaning to SystemDictionary::do_unloading()
coleenp
parents: 47216
diff changeset
    70
  }
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    71
};
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    72
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    73
static void test_remove_dependent_nmethod(int id) {
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    74
  TestDependencyContext c;
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    75
  DependencyContext depContext = c.dependencies();
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    76
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    77
  nmethod* nm = &c._nmethods[id];
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    78
  depContext.remove_dependent_nmethod(nm);
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    79
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    80
  NOT_PRODUCT(ASSERT_FALSE(depContext.is_dependent_nmethod(nm)));
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    81
}
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    82
43431
5ffa076f526d 8172098: A lot of gtests uses TEST instead of TEST_VM
kzhaldyb
parents: 42055
diff changeset
    83
TEST_VM(code, dependency_context) {
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    84
  test_remove_dependent_nmethod(0);
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    85
  test_remove_dependent_nmethod(1);
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 51887
diff changeset
    86
  test_remove_dependent_nmethod(2);
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    87
}