Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/globalDefinitions.cpp
32285 views
/*1* Copyright (c) 1997, 2013, 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 "runtime/os.hpp"26#include "utilities/globalDefinitions.hpp"27#include "utilities/top.hpp"2829// Basic error support3031// Info for oops within a java object. Defaults are zero so32// things will break badly if incorrectly initialized.33int heapOopSize = 0;34int LogBytesPerHeapOop = 0;35int LogBitsPerHeapOop = 0;36int BytesPerHeapOop = 0;37int BitsPerHeapOop = 0;3839// Object alignment, in units of HeapWords.40// Defaults are -1 so things will break badly if incorrectly initialized.41int MinObjAlignment = -1;42int MinObjAlignmentInBytes = -1;43int MinObjAlignmentInBytesMask = 0;4445int LogMinObjAlignment = -1;46int LogMinObjAlignmentInBytes = -1;4748// Oop encoding heap max49uint64_t OopEncodingHeapMax = 0;5051void basic_fatal(const char* msg) {52fatal(msg);53}5455// Something to help porters sleep at night5657void basic_types_init() {58#ifdef ASSERT59#ifdef _LP6460assert(min_intx == (intx)CONST64(0x8000000000000000), "correct constant");61assert(max_intx == CONST64(0x7FFFFFFFFFFFFFFF), "correct constant");62assert(max_uintx == CONST64(0xFFFFFFFFFFFFFFFF), "correct constant");63assert( 8 == sizeof( intx), "wrong size for basic type");64assert( 8 == sizeof( jobject), "wrong size for basic type");65#else66assert(min_intx == (intx)0x80000000, "correct constant");67assert(max_intx == 0x7FFFFFFF, "correct constant");68assert(max_uintx == 0xFFFFFFFF, "correct constant");69assert( 4 == sizeof( intx), "wrong size for basic type");70assert( 4 == sizeof( jobject), "wrong size for basic type");71#endif72assert( (~max_juint) == 0, "max_juint has all its bits");73assert( (~max_uintx) == 0, "max_uintx has all its bits");74assert( (~max_julong) == 0, "max_julong has all its bits");75assert( 1 == sizeof( jbyte), "wrong size for basic type");76assert( 2 == sizeof( jchar), "wrong size for basic type");77assert( 2 == sizeof( jshort), "wrong size for basic type");78assert( 4 == sizeof( juint), "wrong size for basic type");79assert( 4 == sizeof( jint), "wrong size for basic type");80assert( 1 == sizeof( jboolean), "wrong size for basic type");81assert( 8 == sizeof( jlong), "wrong size for basic type");82assert( 4 == sizeof( jfloat), "wrong size for basic type");83assert( 8 == sizeof( jdouble), "wrong size for basic type");84assert( 1 == sizeof( u1), "wrong size for basic type");85assert( 2 == sizeof( u2), "wrong size for basic type");86assert( 4 == sizeof( u4), "wrong size for basic type");8788int num_type_chars = 0;89for (int i = 0; i < 99; i++) {90if (type2char((BasicType)i) != 0) {91assert(char2type(type2char((BasicType)i)) == i, "proper inverses");92num_type_chars++;93}94}95assert(num_type_chars == 11, "must have tested the right number of mappings");96assert(char2type(0) == T_ILLEGAL, "correct illegality");9798{99for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {100BasicType vt = (BasicType)i;101BasicType ft = type2field[vt];102switch (vt) {103// the following types might plausibly show up in memory layouts:104case T_BOOLEAN:105case T_BYTE:106case T_CHAR:107case T_SHORT:108case T_INT:109case T_FLOAT:110case T_DOUBLE:111case T_LONG:112case T_OBJECT:113case T_ADDRESS: // random raw pointer114case T_METADATA: // metadata pointer115case T_NARROWOOP: // compressed pointer116case T_NARROWKLASS: // compressed klass pointer117case T_CONFLICT: // might as well support a bottom type118case T_VOID: // padding or other unaddressed word119// layout type must map to itself120assert(vt == ft, "");121break;122default:123// non-layout type must map to a (different) layout type124assert(vt != ft, "");125assert(ft == type2field[ft], "");126}127// every type must map to same-sized layout type:128assert(type2size[vt] == type2size[ft], "");129}130}131// These are assumed, e.g., when filling HeapWords with juints.132assert(is_power_of_2(sizeof(juint)), "juint must be power of 2");133assert(is_power_of_2(HeapWordSize), "HeapWordSize must be power of 2");134assert((size_t)HeapWordSize >= sizeof(juint),135"HeapWord should be at least as large as juint");136assert(sizeof(NULL) == sizeof(char*), "NULL must be same size as pointer");137#endif138139if( JavaPriority1_To_OSPriority != -1 )140os::java_to_os_priority[1] = JavaPriority1_To_OSPriority;141if( JavaPriority2_To_OSPriority != -1 )142os::java_to_os_priority[2] = JavaPriority2_To_OSPriority;143if( JavaPriority3_To_OSPriority != -1 )144os::java_to_os_priority[3] = JavaPriority3_To_OSPriority;145if( JavaPriority4_To_OSPriority != -1 )146os::java_to_os_priority[4] = JavaPriority4_To_OSPriority;147if( JavaPriority5_To_OSPriority != -1 )148os::java_to_os_priority[5] = JavaPriority5_To_OSPriority;149if( JavaPriority6_To_OSPriority != -1 )150os::java_to_os_priority[6] = JavaPriority6_To_OSPriority;151if( JavaPriority7_To_OSPriority != -1 )152os::java_to_os_priority[7] = JavaPriority7_To_OSPriority;153if( JavaPriority8_To_OSPriority != -1 )154os::java_to_os_priority[8] = JavaPriority8_To_OSPriority;155if( JavaPriority9_To_OSPriority != -1 )156os::java_to_os_priority[9] = JavaPriority9_To_OSPriority;157if(JavaPriority10_To_OSPriority != -1 )158os::java_to_os_priority[10] = JavaPriority10_To_OSPriority;159160// Set the size of basic types here (after argument parsing but before161// stub generation).162if (UseCompressedOops) {163// Size info for oops within java objects is fixed164heapOopSize = jintSize;165LogBytesPerHeapOop = LogBytesPerInt;166LogBitsPerHeapOop = LogBitsPerInt;167BytesPerHeapOop = BytesPerInt;168BitsPerHeapOop = BitsPerInt;169} else {170heapOopSize = oopSize;171LogBytesPerHeapOop = LogBytesPerWord;172LogBitsPerHeapOop = LogBitsPerWord;173BytesPerHeapOop = BytesPerWord;174BitsPerHeapOop = BitsPerWord;175}176_type2aelembytes[T_OBJECT] = heapOopSize;177_type2aelembytes[T_ARRAY] = heapOopSize;178}179180181// Map BasicType to signature character182char type2char_tab[T_CONFLICT+1]={ 0, 0, 0, 0, 'Z', 'C', 'F', 'D', 'B', 'S', 'I', 'J', 'L', '[', 'V', 0, 0, 0, 0, 0};183184// Map BasicType to Java type name185const char* type2name_tab[T_CONFLICT+1] = {186NULL, NULL, NULL, NULL,187"boolean",188"char",189"float",190"double",191"byte",192"short",193"int",194"long",195"object",196"array",197"void",198"*address*",199"*narrowoop*",200"*metadata*",201"*narrowklass*",202"*conflict*"203};204205206BasicType name2type(const char* name) {207for (int i = T_BOOLEAN; i <= T_VOID; i++) {208BasicType t = (BasicType)i;209if (type2name_tab[t] != NULL && 0 == strcmp(type2name_tab[t], name))210return t;211}212return T_ILLEGAL;213}214215216// Map BasicType to size in words217int type2size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 0, 1, 1, 1, 1, -1};218219BasicType type2field[T_CONFLICT+1] = {220(BasicType)0, // 0,221(BasicType)0, // 1,222(BasicType)0, // 2,223(BasicType)0, // 3,224T_BOOLEAN, // T_BOOLEAN = 4,225T_CHAR, // T_CHAR = 5,226T_FLOAT, // T_FLOAT = 6,227T_DOUBLE, // T_DOUBLE = 7,228T_BYTE, // T_BYTE = 8,229T_SHORT, // T_SHORT = 9,230T_INT, // T_INT = 10,231T_LONG, // T_LONG = 11,232T_OBJECT, // T_OBJECT = 12,233T_OBJECT, // T_ARRAY = 13,234T_VOID, // T_VOID = 14,235T_ADDRESS, // T_ADDRESS = 15,236T_NARROWOOP, // T_NARROWOOP= 16,237T_METADATA, // T_METADATA = 17,238T_NARROWKLASS, // T_NARROWKLASS = 18,239T_CONFLICT // T_CONFLICT = 19,240};241242243BasicType type2wfield[T_CONFLICT+1] = {244(BasicType)0, // 0,245(BasicType)0, // 1,246(BasicType)0, // 2,247(BasicType)0, // 3,248T_INT, // T_BOOLEAN = 4,249T_INT, // T_CHAR = 5,250T_FLOAT, // T_FLOAT = 6,251T_DOUBLE, // T_DOUBLE = 7,252T_INT, // T_BYTE = 8,253T_INT, // T_SHORT = 9,254T_INT, // T_INT = 10,255T_LONG, // T_LONG = 11,256T_OBJECT, // T_OBJECT = 12,257T_OBJECT, // T_ARRAY = 13,258T_VOID, // T_VOID = 14,259T_ADDRESS, // T_ADDRESS = 15,260T_NARROWOOP, // T_NARROWOOP = 16,261T_METADATA, // T_METADATA = 17,262T_NARROWKLASS, // T_NARROWKLASS = 18,263T_CONFLICT // T_CONFLICT = 19,264};265266267int _type2aelembytes[T_CONFLICT+1] = {2680, // 02690, // 12700, // 22710, // 3272T_BOOLEAN_aelem_bytes, // T_BOOLEAN = 4,273T_CHAR_aelem_bytes, // T_CHAR = 5,274T_FLOAT_aelem_bytes, // T_FLOAT = 6,275T_DOUBLE_aelem_bytes, // T_DOUBLE = 7,276T_BYTE_aelem_bytes, // T_BYTE = 8,277T_SHORT_aelem_bytes, // T_SHORT = 9,278T_INT_aelem_bytes, // T_INT = 10,279T_LONG_aelem_bytes, // T_LONG = 11,280T_OBJECT_aelem_bytes, // T_OBJECT = 12,281T_ARRAY_aelem_bytes, // T_ARRAY = 13,2820, // T_VOID = 14,283T_OBJECT_aelem_bytes, // T_ADDRESS = 15,284T_NARROWOOP_aelem_bytes, // T_NARROWOOP= 16,285T_OBJECT_aelem_bytes, // T_METADATA = 17,286T_NARROWKLASS_aelem_bytes, // T_NARROWKLASS= 18,2870 // T_CONFLICT = 19,288};289290#ifdef ASSERT291int type2aelembytes(BasicType t, bool allow_address) {292assert(allow_address || t != T_ADDRESS, " ");293return _type2aelembytes[t];294}295#endif296297// Support for 64-bit integer arithmetic298299// The following code is mostly taken from JVM typedefs_md.h and system_md.c300301static const jlong high_bit = (jlong)1 << (jlong)63;302static const jlong other_bits = ~high_bit;303304jlong float2long(jfloat f) {305jlong tmp = (jlong) f;306if (tmp != high_bit) {307return tmp;308} else {309if (g_isnan((jdouble)f)) {310return 0;311}312if (f < 0) {313return high_bit;314} else {315return other_bits;316}317}318}319320321jlong double2long(jdouble f) {322jlong tmp = (jlong) f;323if (tmp != high_bit) {324return tmp;325} else {326if (g_isnan(f)) {327return 0;328}329if (f < 0) {330return high_bit;331} else {332return other_bits;333}334}335}336337// least common multiple338size_t lcm(size_t a, size_t b) {339size_t cur, div, next;340341cur = MAX2(a, b);342div = MIN2(a, b);343344assert(div != 0, "lcm requires positive arguments");345346347while ((next = cur % div) != 0) {348cur = div; div = next;349}350351352julong result = julong(a) * b / div;353assert(result <= (size_t)max_uintx, "Integer overflow in lcm");354355return size_t(result);356}357358#ifndef PRODUCT359360void GlobalDefinitions::test_globals() {361intptr_t page_sizes[] = { os::vm_page_size(), 4096, 8192, 65536, 2*1024*1024 };362const int num_page_sizes = sizeof(page_sizes) / sizeof(page_sizes[0]);363364for (int i = 0; i < num_page_sizes; i++) {365intptr_t page_size = page_sizes[i];366367address a_page = (address)(10*page_size);368369// Check that address within page is returned as is370assert(clamp_address_in_page(a_page, a_page, page_size) == a_page, "incorrect");371assert(clamp_address_in_page(a_page + 128, a_page, page_size) == a_page + 128, "incorrect");372assert(clamp_address_in_page(a_page + page_size - 1, a_page, page_size) == a_page + page_size - 1, "incorrect");373374// Check that address above page returns start of next page375assert(clamp_address_in_page(a_page + page_size, a_page, page_size) == a_page + page_size, "incorrect");376assert(clamp_address_in_page(a_page + page_size + 1, a_page, page_size) == a_page + page_size, "incorrect");377assert(clamp_address_in_page(a_page + page_size*5 + 1, a_page, page_size) == a_page + page_size, "incorrect");378379// Check that address below page returns start of page380assert(clamp_address_in_page(a_page - 1, a_page, page_size) == a_page, "incorrect");381assert(clamp_address_in_page(a_page - 2*page_size - 1, a_page, page_size) == a_page, "incorrect");382assert(clamp_address_in_page(a_page - 5*page_size - 1, a_page, page_size) == a_page, "incorrect");383}384}385386#define EXPECT_EQ(expected, actual) \387assert(expected == actual, "Test failed");388#define EXPECT_STREQ(expected, actual) \389assert(strcmp(expected, actual) == 0, "Test failed");390391void GlobalDefinitions::test_proper_unit() {392EXPECT_EQ(0u, byte_size_in_proper_unit(0u));393EXPECT_STREQ("B", proper_unit_for_byte_size(0u));394395EXPECT_EQ(1u, byte_size_in_proper_unit(1u));396EXPECT_STREQ("B", proper_unit_for_byte_size(1u));397398EXPECT_EQ(1023u, byte_size_in_proper_unit(K - 1));399EXPECT_STREQ("B", proper_unit_for_byte_size(K - 1));400401EXPECT_EQ(1024u, byte_size_in_proper_unit(K));402EXPECT_STREQ("B", proper_unit_for_byte_size(K));403404EXPECT_EQ(1025u, byte_size_in_proper_unit(K + 1));405EXPECT_STREQ("B", proper_unit_for_byte_size(K + 1));406407EXPECT_EQ(51200u, byte_size_in_proper_unit(50*K));408EXPECT_STREQ("B", proper_unit_for_byte_size(50*K));409410EXPECT_EQ(1023u, byte_size_in_proper_unit(M - 1));411EXPECT_STREQ("K", proper_unit_for_byte_size(M - 1));412413EXPECT_EQ(1024u, byte_size_in_proper_unit(M));414EXPECT_STREQ("K", proper_unit_for_byte_size(M));415416EXPECT_EQ(1024u, byte_size_in_proper_unit(M + 1));417EXPECT_STREQ("K", proper_unit_for_byte_size(M + 1));418419EXPECT_EQ(1025u, byte_size_in_proper_unit(M + K));420EXPECT_STREQ("K", proper_unit_for_byte_size(M + K));421422EXPECT_EQ(51200u, byte_size_in_proper_unit(50*M));423EXPECT_STREQ("K", proper_unit_for_byte_size(50*M));424425#ifdef _LP64426EXPECT_EQ(1023u, byte_size_in_proper_unit(G - 1));427EXPECT_STREQ("M", proper_unit_for_byte_size(G - 1));428429EXPECT_EQ(1024u, byte_size_in_proper_unit(G));430EXPECT_STREQ("M", proper_unit_for_byte_size(G));431432EXPECT_EQ(1024u, byte_size_in_proper_unit(G + 1));433EXPECT_STREQ("M", proper_unit_for_byte_size(G + 1));434435EXPECT_EQ(1024u, byte_size_in_proper_unit(G + K));436EXPECT_STREQ("M", proper_unit_for_byte_size(G + K));437438EXPECT_EQ(1025u, byte_size_in_proper_unit(G + M));439EXPECT_STREQ("M", proper_unit_for_byte_size(G + M));440441EXPECT_EQ(51200u, byte_size_in_proper_unit(50*G));442EXPECT_STREQ("M", proper_unit_for_byte_size(50*G));443#endif444}445446#undef EXPECT_EQ447#undef EXPECT_STREQ448449#endif // PRODUCT450451452