2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2016-01-30 11:02:29 -05:00
|
|
|
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
|
|
|
#include "runtime/os.hpp"
|
|
|
|
#include "utilities/globalDefinitions.hpp"
|
|
|
|
#include "utilities/top.hpp"
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Basic error support
|
|
|
|
|
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
2008-04-13 17:43:42 -04:00
|
|
|
// Info for oops within a java object. Defaults are zero so
|
|
|
|
// things will break badly if incorrectly initialized.
|
|
|
|
int heapOopSize = 0;
|
|
|
|
int LogBytesPerHeapOop = 0;
|
|
|
|
int LogBitsPerHeapOop = 0;
|
|
|
|
int BytesPerHeapOop = 0;
|
|
|
|
int BitsPerHeapOop = 0;
|
|
|
|
|
2010-05-27 18:01:56 -07:00
|
|
|
// Object alignment, in units of HeapWords.
|
|
|
|
// Defaults are -1 so things will break badly if incorrectly initialized.
|
|
|
|
int MinObjAlignment = -1;
|
|
|
|
int MinObjAlignmentInBytes = -1;
|
|
|
|
int MinObjAlignmentInBytesMask = 0;
|
|
|
|
|
|
|
|
int LogMinObjAlignment = -1;
|
|
|
|
int LogMinObjAlignmentInBytes = -1;
|
|
|
|
|
|
|
|
// Oop encoding heap max
|
|
|
|
uint64_t OopEncodingHeapMax = 0;
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
void basic_fatal(const char* msg) {
|
2015-09-29 11:02:08 +02:00
|
|
|
fatal("%s", msg);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Something to help porters sleep at night
|
|
|
|
|
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
2008-04-13 17:43:42 -04:00
|
|
|
void basic_types_init() {
|
2007-12-01 00:00:00 +00:00
|
|
|
#ifdef ASSERT
|
|
|
|
#ifdef _LP64
|
|
|
|
assert(min_intx == (intx)CONST64(0x8000000000000000), "correct constant");
|
|
|
|
assert(max_intx == CONST64(0x7FFFFFFFFFFFFFFF), "correct constant");
|
|
|
|
assert(max_uintx == CONST64(0xFFFFFFFFFFFFFFFF), "correct constant");
|
|
|
|
assert( 8 == sizeof( intx), "wrong size for basic type");
|
|
|
|
assert( 8 == sizeof( jobject), "wrong size for basic type");
|
|
|
|
#else
|
|
|
|
assert(min_intx == (intx)0x80000000, "correct constant");
|
|
|
|
assert(max_intx == 0x7FFFFFFF, "correct constant");
|
|
|
|
assert(max_uintx == 0xFFFFFFFF, "correct constant");
|
|
|
|
assert( 4 == sizeof( intx), "wrong size for basic type");
|
|
|
|
assert( 4 == sizeof( jobject), "wrong size for basic type");
|
|
|
|
#endif
|
|
|
|
assert( (~max_juint) == 0, "max_juint has all its bits");
|
|
|
|
assert( (~max_uintx) == 0, "max_uintx has all its bits");
|
|
|
|
assert( (~max_julong) == 0, "max_julong has all its bits");
|
|
|
|
assert( 1 == sizeof( jbyte), "wrong size for basic type");
|
|
|
|
assert( 2 == sizeof( jchar), "wrong size for basic type");
|
|
|
|
assert( 2 == sizeof( jshort), "wrong size for basic type");
|
|
|
|
assert( 4 == sizeof( juint), "wrong size for basic type");
|
|
|
|
assert( 4 == sizeof( jint), "wrong size for basic type");
|
|
|
|
assert( 1 == sizeof( jboolean), "wrong size for basic type");
|
|
|
|
assert( 8 == sizeof( jlong), "wrong size for basic type");
|
|
|
|
assert( 4 == sizeof( jfloat), "wrong size for basic type");
|
|
|
|
assert( 8 == sizeof( jdouble), "wrong size for basic type");
|
|
|
|
assert( 1 == sizeof( u1), "wrong size for basic type");
|
|
|
|
assert( 2 == sizeof( u2), "wrong size for basic type");
|
|
|
|
assert( 4 == sizeof( u4), "wrong size for basic type");
|
2016-01-30 11:02:29 -05:00
|
|
|
assert(wordSize == BytesPerWord, "should be the same since they're used interchangeably");
|
|
|
|
assert(wordSize == HeapWordSize, "should be the same since they're also used interchangeably");
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
int num_type_chars = 0;
|
|
|
|
for (int i = 0; i < 99; i++) {
|
|
|
|
if (type2char((BasicType)i) != 0) {
|
|
|
|
assert(char2type(type2char((BasicType)i)) == i, "proper inverses");
|
|
|
|
num_type_chars++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(num_type_chars == 11, "must have tested the right number of mappings");
|
|
|
|
assert(char2type(0) == T_ILLEGAL, "correct illegality");
|
|
|
|
|
|
|
|
{
|
|
|
|
for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
|
|
|
|
BasicType vt = (BasicType)i;
|
|
|
|
BasicType ft = type2field[vt];
|
|
|
|
switch (vt) {
|
|
|
|
// the following types might plausibly show up in memory layouts:
|
|
|
|
case T_BOOLEAN:
|
|
|
|
case T_BYTE:
|
|
|
|
case T_CHAR:
|
|
|
|
case T_SHORT:
|
|
|
|
case T_INT:
|
|
|
|
case T_FLOAT:
|
|
|
|
case T_DOUBLE:
|
|
|
|
case T_LONG:
|
|
|
|
case T_OBJECT:
|
2012-10-09 10:11:38 +02:00
|
|
|
case T_ADDRESS: // random raw pointer
|
|
|
|
case T_METADATA: // metadata pointer
|
|
|
|
case T_NARROWOOP: // compressed pointer
|
|
|
|
case T_NARROWKLASS: // compressed klass pointer
|
|
|
|
case T_CONFLICT: // might as well support a bottom type
|
|
|
|
case T_VOID: // padding or other unaddressed word
|
2007-12-01 00:00:00 +00:00
|
|
|
// layout type must map to itself
|
|
|
|
assert(vt == ft, "");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// non-layout type must map to a (different) layout type
|
|
|
|
assert(vt != ft, "");
|
|
|
|
assert(ft == type2field[ft], "");
|
|
|
|
}
|
|
|
|
// every type must map to same-sized layout type:
|
|
|
|
assert(type2size[vt] == type2size[ft], "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// These are assumed, e.g., when filling HeapWords with juints.
|
|
|
|
assert(is_power_of_2(sizeof(juint)), "juint must be power of 2");
|
|
|
|
assert(is_power_of_2(HeapWordSize), "HeapWordSize must be power of 2");
|
|
|
|
assert((size_t)HeapWordSize >= sizeof(juint),
|
|
|
|
"HeapWord should be at least as large as juint");
|
|
|
|
assert(sizeof(NULL) == sizeof(char*), "NULL must be same size as pointer");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if( JavaPriority1_To_OSPriority != -1 )
|
|
|
|
os::java_to_os_priority[1] = JavaPriority1_To_OSPriority;
|
|
|
|
if( JavaPriority2_To_OSPriority != -1 )
|
|
|
|
os::java_to_os_priority[2] = JavaPriority2_To_OSPriority;
|
|
|
|
if( JavaPriority3_To_OSPriority != -1 )
|
|
|
|
os::java_to_os_priority[3] = JavaPriority3_To_OSPriority;
|
|
|
|
if( JavaPriority4_To_OSPriority != -1 )
|
|
|
|
os::java_to_os_priority[4] = JavaPriority4_To_OSPriority;
|
|
|
|
if( JavaPriority5_To_OSPriority != -1 )
|
|
|
|
os::java_to_os_priority[5] = JavaPriority5_To_OSPriority;
|
|
|
|
if( JavaPriority6_To_OSPriority != -1 )
|
|
|
|
os::java_to_os_priority[6] = JavaPriority6_To_OSPriority;
|
|
|
|
if( JavaPriority7_To_OSPriority != -1 )
|
|
|
|
os::java_to_os_priority[7] = JavaPriority7_To_OSPriority;
|
|
|
|
if( JavaPriority8_To_OSPriority != -1 )
|
|
|
|
os::java_to_os_priority[8] = JavaPriority8_To_OSPriority;
|
|
|
|
if( JavaPriority9_To_OSPriority != -1 )
|
|
|
|
os::java_to_os_priority[9] = JavaPriority9_To_OSPriority;
|
|
|
|
if(JavaPriority10_To_OSPriority != -1 )
|
|
|
|
os::java_to_os_priority[10] = JavaPriority10_To_OSPriority;
|
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
2008-04-13 17:43:42 -04:00
|
|
|
|
|
|
|
// Set the size of basic types here (after argument parsing but before
|
|
|
|
// stub generation).
|
|
|
|
if (UseCompressedOops) {
|
|
|
|
// Size info for oops within java objects is fixed
|
|
|
|
heapOopSize = jintSize;
|
|
|
|
LogBytesPerHeapOop = LogBytesPerInt;
|
|
|
|
LogBitsPerHeapOop = LogBitsPerInt;
|
|
|
|
BytesPerHeapOop = BytesPerInt;
|
|
|
|
BitsPerHeapOop = BitsPerInt;
|
|
|
|
} else {
|
|
|
|
heapOopSize = oopSize;
|
|
|
|
LogBytesPerHeapOop = LogBytesPerWord;
|
|
|
|
LogBitsPerHeapOop = LogBitsPerWord;
|
|
|
|
BytesPerHeapOop = BytesPerWord;
|
|
|
|
BitsPerHeapOop = BitsPerWord;
|
|
|
|
}
|
|
|
|
_type2aelembytes[T_OBJECT] = heapOopSize;
|
|
|
|
_type2aelembytes[T_ARRAY] = heapOopSize;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Map BasicType to signature character
|
2012-10-09 10:11:38 +02:00
|
|
|
char type2char_tab[T_CONFLICT+1]={ 0, 0, 0, 0, 'Z', 'C', 'F', 'D', 'B', 'S', 'I', 'J', 'L', '[', 'V', 0, 0, 0, 0, 0};
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Map BasicType to Java type name
|
|
|
|
const char* type2name_tab[T_CONFLICT+1] = {
|
|
|
|
NULL, NULL, NULL, NULL,
|
|
|
|
"boolean",
|
|
|
|
"char",
|
|
|
|
"float",
|
|
|
|
"double",
|
|
|
|
"byte",
|
|
|
|
"short",
|
|
|
|
"int",
|
|
|
|
"long",
|
|
|
|
"object",
|
|
|
|
"array",
|
|
|
|
"void",
|
|
|
|
"*address*",
|
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
2008-04-13 17:43:42 -04:00
|
|
|
"*narrowoop*",
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
"*metadata*",
|
2012-10-09 10:11:38 +02:00
|
|
|
"*narrowklass*",
|
2007-12-01 00:00:00 +00:00
|
|
|
"*conflict*"
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
BasicType name2type(const char* name) {
|
|
|
|
for (int i = T_BOOLEAN; i <= T_VOID; i++) {
|
|
|
|
BasicType t = (BasicType)i;
|
|
|
|
if (type2name_tab[t] != NULL && 0 == strcmp(type2name_tab[t], name))
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
return T_ILLEGAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Map BasicType to size in words
|
2012-10-09 10:11:38 +02:00
|
|
|
int type2size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 0, 1, 1, 1, 1, -1};
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
BasicType type2field[T_CONFLICT+1] = {
|
|
|
|
(BasicType)0, // 0,
|
|
|
|
(BasicType)0, // 1,
|
|
|
|
(BasicType)0, // 2,
|
|
|
|
(BasicType)0, // 3,
|
|
|
|
T_BOOLEAN, // T_BOOLEAN = 4,
|
|
|
|
T_CHAR, // T_CHAR = 5,
|
|
|
|
T_FLOAT, // T_FLOAT = 6,
|
|
|
|
T_DOUBLE, // T_DOUBLE = 7,
|
|
|
|
T_BYTE, // T_BYTE = 8,
|
|
|
|
T_SHORT, // T_SHORT = 9,
|
|
|
|
T_INT, // T_INT = 10,
|
|
|
|
T_LONG, // T_LONG = 11,
|
|
|
|
T_OBJECT, // T_OBJECT = 12,
|
|
|
|
T_OBJECT, // T_ARRAY = 13,
|
|
|
|
T_VOID, // T_VOID = 14,
|
|
|
|
T_ADDRESS, // T_ADDRESS = 15,
|
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
2008-04-13 17:43:42 -04:00
|
|
|
T_NARROWOOP, // T_NARROWOOP= 16,
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
T_METADATA, // T_METADATA = 17,
|
2012-10-09 10:11:38 +02:00
|
|
|
T_NARROWKLASS, // T_NARROWKLASS = 18,
|
|
|
|
T_CONFLICT // T_CONFLICT = 19,
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
BasicType type2wfield[T_CONFLICT+1] = {
|
|
|
|
(BasicType)0, // 0,
|
|
|
|
(BasicType)0, // 1,
|
|
|
|
(BasicType)0, // 2,
|
|
|
|
(BasicType)0, // 3,
|
|
|
|
T_INT, // T_BOOLEAN = 4,
|
|
|
|
T_INT, // T_CHAR = 5,
|
|
|
|
T_FLOAT, // T_FLOAT = 6,
|
|
|
|
T_DOUBLE, // T_DOUBLE = 7,
|
|
|
|
T_INT, // T_BYTE = 8,
|
|
|
|
T_INT, // T_SHORT = 9,
|
|
|
|
T_INT, // T_INT = 10,
|
|
|
|
T_LONG, // T_LONG = 11,
|
|
|
|
T_OBJECT, // T_OBJECT = 12,
|
|
|
|
T_OBJECT, // T_ARRAY = 13,
|
|
|
|
T_VOID, // T_VOID = 14,
|
|
|
|
T_ADDRESS, // T_ADDRESS = 15,
|
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
2008-04-13 17:43:42 -04:00
|
|
|
T_NARROWOOP, // T_NARROWOOP = 16,
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
T_METADATA, // T_METADATA = 17,
|
2012-10-09 10:11:38 +02:00
|
|
|
T_NARROWKLASS, // T_NARROWKLASS = 18,
|
|
|
|
T_CONFLICT // T_CONFLICT = 19,
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-02-25 15:05:44 -08:00
|
|
|
int _type2aelembytes[T_CONFLICT+1] = {
|
2012-10-09 10:11:38 +02:00
|
|
|
0, // 0
|
|
|
|
0, // 1
|
|
|
|
0, // 2
|
|
|
|
0, // 3
|
|
|
|
T_BOOLEAN_aelem_bytes, // T_BOOLEAN = 4,
|
|
|
|
T_CHAR_aelem_bytes, // T_CHAR = 5,
|
|
|
|
T_FLOAT_aelem_bytes, // T_FLOAT = 6,
|
|
|
|
T_DOUBLE_aelem_bytes, // T_DOUBLE = 7,
|
|
|
|
T_BYTE_aelem_bytes, // T_BYTE = 8,
|
|
|
|
T_SHORT_aelem_bytes, // T_SHORT = 9,
|
|
|
|
T_INT_aelem_bytes, // T_INT = 10,
|
|
|
|
T_LONG_aelem_bytes, // T_LONG = 11,
|
|
|
|
T_OBJECT_aelem_bytes, // T_OBJECT = 12,
|
|
|
|
T_ARRAY_aelem_bytes, // T_ARRAY = 13,
|
|
|
|
0, // T_VOID = 14,
|
|
|
|
T_OBJECT_aelem_bytes, // T_ADDRESS = 15,
|
|
|
|
T_NARROWOOP_aelem_bytes, // T_NARROWOOP= 16,
|
|
|
|
T_OBJECT_aelem_bytes, // T_METADATA = 17,
|
|
|
|
T_NARROWKLASS_aelem_bytes, // T_NARROWKLASS= 18,
|
|
|
|
0 // T_CONFLICT = 19,
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
2008-02-25 15:05:44 -08:00
|
|
|
#ifdef ASSERT
|
|
|
|
int type2aelembytes(BasicType t, bool allow_address) {
|
|
|
|
assert(allow_address || t != T_ADDRESS, " ");
|
|
|
|
return _type2aelembytes[t];
|
|
|
|
}
|
|
|
|
#endif
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Support for 64-bit integer arithmetic
|
|
|
|
|
|
|
|
// The following code is mostly taken from JVM typedefs_md.h and system_md.c
|
|
|
|
|
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
2008-04-13 17:43:42 -04:00
|
|
|
static const jlong high_bit = (jlong)1 << (jlong)63;
|
2007-12-01 00:00:00 +00:00
|
|
|
static const jlong other_bits = ~high_bit;
|
|
|
|
|
|
|
|
jlong float2long(jfloat f) {
|
|
|
|
jlong tmp = (jlong) f;
|
|
|
|
if (tmp != high_bit) {
|
|
|
|
return tmp;
|
|
|
|
} else {
|
|
|
|
if (g_isnan((jdouble)f)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (f < 0) {
|
|
|
|
return high_bit;
|
|
|
|
} else {
|
|
|
|
return other_bits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
jlong double2long(jdouble f) {
|
|
|
|
jlong tmp = (jlong) f;
|
|
|
|
if (tmp != high_bit) {
|
|
|
|
return tmp;
|
|
|
|
} else {
|
|
|
|
if (g_isnan(f)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (f < 0) {
|
|
|
|
return high_bit;
|
|
|
|
} else {
|
|
|
|
return other_bits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// least common multiple
|
|
|
|
size_t lcm(size_t a, size_t b) {
|
|
|
|
size_t cur, div, next;
|
|
|
|
|
|
|
|
cur = MAX2(a, b);
|
|
|
|
div = MIN2(a, b);
|
|
|
|
|
|
|
|
assert(div != 0, "lcm requires positive arguments");
|
|
|
|
|
|
|
|
|
|
|
|
while ((next = cur % div) != 0) {
|
|
|
|
cur = div; div = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
julong result = julong(a) * b / div;
|
|
|
|
assert(result <= (size_t)max_uintx, "Integer overflow in lcm");
|
|
|
|
|
|
|
|
return size_t(result);
|
|
|
|
}
|
2013-04-04 10:01:26 -07:00
|
|
|
|
|
|
|
#ifndef PRODUCT
|
2016-01-19 11:00:29 +01:00
|
|
|
// For unit testing only
|
|
|
|
class GlobalDefinitions {
|
|
|
|
public:
|
|
|
|
static void test_globals();
|
|
|
|
};
|
2013-04-04 10:01:26 -07:00
|
|
|
|
|
|
|
void GlobalDefinitions::test_globals() {
|
|
|
|
intptr_t page_sizes[] = { os::vm_page_size(), 4096, 8192, 65536, 2*1024*1024 };
|
|
|
|
const int num_page_sizes = sizeof(page_sizes) / sizeof(page_sizes[0]);
|
|
|
|
|
|
|
|
for (int i = 0; i < num_page_sizes; i++) {
|
|
|
|
intptr_t page_size = page_sizes[i];
|
|
|
|
|
|
|
|
address a_page = (address)(10*page_size);
|
|
|
|
|
|
|
|
// Check that address within page is returned as is
|
|
|
|
assert(clamp_address_in_page(a_page, a_page, page_size) == a_page, "incorrect");
|
|
|
|
assert(clamp_address_in_page(a_page + 128, a_page, page_size) == a_page + 128, "incorrect");
|
|
|
|
assert(clamp_address_in_page(a_page + page_size - 1, a_page, page_size) == a_page + page_size - 1, "incorrect");
|
|
|
|
|
|
|
|
// Check that address above page returns start of next page
|
|
|
|
assert(clamp_address_in_page(a_page + page_size, a_page, page_size) == a_page + page_size, "incorrect");
|
|
|
|
assert(clamp_address_in_page(a_page + page_size + 1, a_page, page_size) == a_page + page_size, "incorrect");
|
|
|
|
assert(clamp_address_in_page(a_page + page_size*5 + 1, a_page, page_size) == a_page + page_size, "incorrect");
|
|
|
|
|
|
|
|
// Check that address below page returns start of page
|
|
|
|
assert(clamp_address_in_page(a_page - 1, a_page, page_size) == a_page, "incorrect");
|
|
|
|
assert(clamp_address_in_page(a_page - 2*page_size - 1, a_page, page_size) == a_page, "incorrect");
|
|
|
|
assert(clamp_address_in_page(a_page - 5*page_size - 1, a_page, page_size) == a_page, "incorrect");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 11:00:29 +01:00
|
|
|
void GlobalDefinitions_test() {
|
|
|
|
GlobalDefinitions::test_globals();
|
|
|
|
}
|
|
|
|
|
2013-04-04 10:01:26 -07:00
|
|
|
#endif // PRODUCT
|