Path: blob/master/test/hotspot/gtest/oops/test_oop.cpp
41144 views
/*1* Copyright (c) 2018, 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*/2223#include "precompiled.hpp"24#include "oops/oop.inline.hpp"25#include "unittest.hpp"26#include "utilities/globalDefinitions.hpp"2728static unsigned char memory[32];2930oop fake_object() {31return cast_to_oop(memory);32}3334template <typename T>35T* fake_field_addr() {36return reinterpret_cast<T*>(&memory[16]);37}3839TEST_VM(oopDesc, field_offset_oop) {40// Fake object41oop obj = fake_object();4243// Fake oop field44oop* oop_field_addr = fake_field_addr<oop>();4546// Check offset47size_t oop_offset = obj->field_offset(oop_field_addr);48ASSERT_EQ(16u, oop_offset);49}5051TEST_VM(oopDesc, field_offset_narrowOop) {52// Fake object53oop obj = fake_object();5455// Fake narrowOop field56narrowOop* narrowOop_field_addr = fake_field_addr<narrowOop>();5758size_t narrowOop_offset = obj->field_offset(narrowOop_field_addr);59ASSERT_EQ(16u, narrowOop_offset);60}6162TEST_VM(oopDesc, field_offset_primitive) {63// Fake object64oop obj = fake_object();6566// Fake primitive field67char* char_field_addr = fake_field_addr<char>();6869size_t char_offset = obj->field_offset(char_field_addr);70ASSERT_EQ(16u, char_offset);71}727374