hotspot/test/native/code/test_dependencyContext.cpp
author lana
Sat, 22 Apr 2017 00:22:47 +0000
changeset 44716 60901aefa352
parent 43431 5ffa076f526d
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
     1
/*
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
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"
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    27
#include "unittest.hpp"
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    28
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    29
class TestDependencyContext {
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    30
 public:
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    31
  nmethod* _nmethods[3];
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    32
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    33
  intptr_t _dependency_context;
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    34
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    35
  DependencyContext dependencies() {
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    36
    DependencyContext depContext(&_dependency_context);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    37
    return depContext;
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    38
  }
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    39
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    40
  TestDependencyContext() : _dependency_context(DependencyContext::EMPTY) {
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    41
    CodeCache_lock->lock_without_safepoint_check();
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    42
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    43
    _nmethods[0] = reinterpret_cast<nmethod*>(0x8 * 0);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    44
    _nmethods[1] = reinterpret_cast<nmethod*>(0x8 * 1);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    45
    _nmethods[2] = reinterpret_cast<nmethod*>(0x8 * 2);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    46
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    47
    dependencies().add_dependent_nmethod(_nmethods[2]);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    48
    dependencies().add_dependent_nmethod(_nmethods[1]);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    49
    dependencies().add_dependent_nmethod(_nmethods[0]);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    50
  }
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    51
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    52
  ~TestDependencyContext() {
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    53
    dependencies().wipe();
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    54
    CodeCache_lock->unlock();
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    55
  }
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    56
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    57
  static bool has_stale_entries(DependencyContext ctx) {
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    58
    return ctx.has_stale_entries();
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    59
  }
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    60
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    61
#ifndef PRODUCT
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    62
  static bool find_stale_entries(DependencyContext ctx) {
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    63
    return ctx.find_stale_entries();
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    64
  }
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    65
#endif
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    66
};
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    67
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    68
static void test_remove_dependent_nmethod(int id, bool delete_immediately) {
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    69
  TestDependencyContext c;
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    70
  DependencyContext depContext = c.dependencies();
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    71
  NOT_PRODUCT(ASSERT_FALSE(TestDependencyContext::find_stale_entries(depContext)));
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    72
  ASSERT_FALSE(TestDependencyContext::has_stale_entries(depContext));
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    73
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    74
  nmethod* nm = c._nmethods[id];
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    75
  depContext.remove_dependent_nmethod(nm, delete_immediately);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    76
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    77
  if (!delete_immediately) {
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    78
    NOT_PRODUCT(ASSERT_TRUE(TestDependencyContext::find_stale_entries(depContext)));
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    79
    ASSERT_TRUE(TestDependencyContext::has_stale_entries(depContext));
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    80
    NOT_PRODUCT(ASSERT_TRUE(depContext.is_dependent_nmethod(nm)));
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    81
    depContext.expunge_stale_entries();
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    82
  }
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    83
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    84
  NOT_PRODUCT(ASSERT_FALSE(TestDependencyContext::find_stale_entries(depContext)));
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    85
  ASSERT_FALSE(TestDependencyContext::has_stale_entries(depContext));
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    86
  NOT_PRODUCT(ASSERT_FALSE(depContext.is_dependent_nmethod(nm)));
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    87
}
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    88
43431
5ffa076f526d 8172098: A lot of gtests uses TEST instead of TEST_VM
kzhaldyb
parents: 42055
diff changeset
    89
TEST_VM(code, dependency_context) {
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    90
  test_remove_dependent_nmethod(0, false);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    91
  test_remove_dependent_nmethod(1, false);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    92
  test_remove_dependent_nmethod(2, false);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    93
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    94
  test_remove_dependent_nmethod(0, true);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    95
  test_remove_dependent_nmethod(1, true);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    96
  test_remove_dependent_nmethod(2, true);
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents:
diff changeset
    97
}