Path: blob/master/test/hotspot/gtest/runtime/test_synchronizer.cpp
41145 views
/*1* Copyright (c) 2018, 2019, 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*/2223#include "precompiled.hpp"24#include "memory/allocation.hpp"25#include "runtime/synchronizer.hpp"26#include "runtime/vm_version.hpp"27#include "unittest.hpp"2829class SynchronizerTest : public ::testing::Test {30public:31static u_char* get_gvars_addr() { return ObjectSynchronizer::get_gvars_addr(); }32static u_char* get_gvars_hc_sequence_addr() { return ObjectSynchronizer::get_gvars_hc_sequence_addr(); }33static size_t get_gvars_size() { return ObjectSynchronizer::get_gvars_size(); }34static u_char* get_gvars_stw_random_addr() { return ObjectSynchronizer::get_gvars_stw_random_addr(); }35};3637TEST_VM(SynchronizerTest, sanity) {38uint cache_line_size = VM_Version::L1_data_cache_line_size();39if (cache_line_size != 0) {40// We were able to determine the L1 data cache line size so41// do some cache line specific sanity checks4243u_char *addr_begin = SynchronizerTest::get_gvars_addr();44u_char *addr_stw_random = SynchronizerTest::get_gvars_stw_random_addr();45u_char *addr_hc_sequence = SynchronizerTest::get_gvars_hc_sequence_addr();46size_t gvars_size = SynchronizerTest::get_gvars_size();4748uint offset_stw_random = (uint) (addr_stw_random - addr_begin);49uint offset_hc_sequence = (uint) (addr_hc_sequence - addr_begin);50uint offset_hc_sequence_stw_random = offset_hc_sequence - offset_stw_random;51uint offset_hc_sequence_struct_end = (uint) gvars_size - offset_hc_sequence;5253EXPECT_GE(offset_stw_random, cache_line_size)54<< "the SharedGlobals.stw_random field is closer "55<< "to the struct beginning than a cache line which permits "56<< "false sharing.";5758EXPECT_GE(offset_hc_sequence_stw_random, cache_line_size)59<< "the SharedGlobals.stw_random and "60<< "SharedGlobals.hc_sequence fields are closer than a cache "61<< "line which permits false sharing.";6263EXPECT_GE(offset_hc_sequence_struct_end, cache_line_size)64<< "the SharedGlobals.hc_sequence field is closer "65<< "to the struct end than a cache line which permits false "66<< "sharing.";67}68}697071