Path: blob/master/test/hotspot/gtest/code/test_dependencyContext.cpp
41145 views
/*1* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "code/dependencyContext.hpp"26#include "code/nmethod.hpp"27#include "unittest.hpp"2829class TestDependencyContext {30public:31nmethod _nmethods[3];3233nmethodBucket* volatile _dependency_context;34volatile uint64_t _last_cleanup;3536DependencyContext dependencies() {37DependencyContext depContext(&_dependency_context, &_last_cleanup);38return depContext;39}4041TestDependencyContext()42: _dependency_context(NULL),43_last_cleanup(0) {44CodeCache_lock->lock_without_safepoint_check();4546_nmethods[0].clear_unloading_state();47_nmethods[1].clear_unloading_state();48_nmethods[2].clear_unloading_state();4950dependencies().add_dependent_nmethod(&_nmethods[2]);51dependencies().add_dependent_nmethod(&_nmethods[1]);52dependencies().add_dependent_nmethod(&_nmethods[0]);53}5455~TestDependencyContext() {56wipe();57CodeCache_lock->unlock();58}5960void wipe() {61DependencyContext ctx(&_dependency_context, &_last_cleanup);62nmethodBucket* b = ctx.dependencies();63ctx.set_dependencies(NULL);64while (b != NULL) {65nmethodBucket* next = b->next();66delete b;67b = next;68}69}70};7172static void test_remove_dependent_nmethod(int id) {73TestDependencyContext c;74DependencyContext depContext = c.dependencies();7576nmethod* nm = &c._nmethods[id];77depContext.remove_dependent_nmethod(nm);7879ASSERT_FALSE(depContext.is_dependent_nmethod(nm));80}8182TEST_VM(code, dependency_context) {83test_remove_dependent_nmethod(0);84test_remove_dependent_nmethod(1);85test_remove_dependent_nmethod(2);86}878889