Fri, 05 Oct 2012 18:57:10 -0700
7177003: C1: LogCompilation support
Summary: add LogCompilation support in C1 - both client and tiered mode.
Reviewed-by: twisti, kvn
duke@435 | 1 | /* |
coleenp@4037 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "runtime/os.hpp" |
stefank@2314 | 27 | #include "utilities/globalDefinitions.hpp" |
stefank@2314 | 28 | #include "utilities/top.hpp" |
stefank@2314 | 29 | |
coleenp@548 | 30 | // Basic error support |
duke@435 | 31 | |
coleenp@548 | 32 | // Info for oops within a java object. Defaults are zero so |
coleenp@548 | 33 | // things will break badly if incorrectly initialized. |
coleenp@548 | 34 | int heapOopSize = 0; |
coleenp@548 | 35 | int LogBytesPerHeapOop = 0; |
coleenp@548 | 36 | int LogBitsPerHeapOop = 0; |
coleenp@548 | 37 | int BytesPerHeapOop = 0; |
coleenp@548 | 38 | int BitsPerHeapOop = 0; |
duke@435 | 39 | |
kvn@1926 | 40 | // Object alignment, in units of HeapWords. |
kvn@1926 | 41 | // Defaults are -1 so things will break badly if incorrectly initialized. |
kvn@1926 | 42 | int MinObjAlignment = -1; |
kvn@1926 | 43 | int MinObjAlignmentInBytes = -1; |
kvn@1926 | 44 | int MinObjAlignmentInBytesMask = 0; |
kvn@1926 | 45 | |
kvn@1926 | 46 | int LogMinObjAlignment = -1; |
kvn@1926 | 47 | int LogMinObjAlignmentInBytes = -1; |
kvn@1926 | 48 | |
kvn@1926 | 49 | // Oop encoding heap max |
kvn@1926 | 50 | uint64_t OopEncodingHeapMax = 0; |
kvn@1926 | 51 | |
duke@435 | 52 | void basic_fatal(const char* msg) { |
duke@435 | 53 | fatal(msg); |
duke@435 | 54 | } |
duke@435 | 55 | |
duke@435 | 56 | // Something to help porters sleep at night |
duke@435 | 57 | |
coleenp@548 | 58 | void basic_types_init() { |
duke@435 | 59 | #ifdef ASSERT |
duke@435 | 60 | #ifdef _LP64 |
duke@435 | 61 | assert(min_intx == (intx)CONST64(0x8000000000000000), "correct constant"); |
duke@435 | 62 | assert(max_intx == CONST64(0x7FFFFFFFFFFFFFFF), "correct constant"); |
duke@435 | 63 | assert(max_uintx == CONST64(0xFFFFFFFFFFFFFFFF), "correct constant"); |
duke@435 | 64 | assert( 8 == sizeof( intx), "wrong size for basic type"); |
duke@435 | 65 | assert( 8 == sizeof( jobject), "wrong size for basic type"); |
duke@435 | 66 | #else |
duke@435 | 67 | assert(min_intx == (intx)0x80000000, "correct constant"); |
duke@435 | 68 | assert(max_intx == 0x7FFFFFFF, "correct constant"); |
duke@435 | 69 | assert(max_uintx == 0xFFFFFFFF, "correct constant"); |
duke@435 | 70 | assert( 4 == sizeof( intx), "wrong size for basic type"); |
duke@435 | 71 | assert( 4 == sizeof( jobject), "wrong size for basic type"); |
duke@435 | 72 | #endif |
duke@435 | 73 | assert( (~max_juint) == 0, "max_juint has all its bits"); |
duke@435 | 74 | assert( (~max_uintx) == 0, "max_uintx has all its bits"); |
duke@435 | 75 | assert( (~max_julong) == 0, "max_julong has all its bits"); |
duke@435 | 76 | assert( 1 == sizeof( jbyte), "wrong size for basic type"); |
duke@435 | 77 | assert( 2 == sizeof( jchar), "wrong size for basic type"); |
duke@435 | 78 | assert( 2 == sizeof( jshort), "wrong size for basic type"); |
duke@435 | 79 | assert( 4 == sizeof( juint), "wrong size for basic type"); |
duke@435 | 80 | assert( 4 == sizeof( jint), "wrong size for basic type"); |
duke@435 | 81 | assert( 1 == sizeof( jboolean), "wrong size for basic type"); |
duke@435 | 82 | assert( 8 == sizeof( jlong), "wrong size for basic type"); |
duke@435 | 83 | assert( 4 == sizeof( jfloat), "wrong size for basic type"); |
duke@435 | 84 | assert( 8 == sizeof( jdouble), "wrong size for basic type"); |
duke@435 | 85 | assert( 1 == sizeof( u1), "wrong size for basic type"); |
duke@435 | 86 | assert( 2 == sizeof( u2), "wrong size for basic type"); |
duke@435 | 87 | assert( 4 == sizeof( u4), "wrong size for basic type"); |
duke@435 | 88 | |
duke@435 | 89 | int num_type_chars = 0; |
duke@435 | 90 | for (int i = 0; i < 99; i++) { |
duke@435 | 91 | if (type2char((BasicType)i) != 0) { |
duke@435 | 92 | assert(char2type(type2char((BasicType)i)) == i, "proper inverses"); |
duke@435 | 93 | num_type_chars++; |
duke@435 | 94 | } |
duke@435 | 95 | } |
duke@435 | 96 | assert(num_type_chars == 11, "must have tested the right number of mappings"); |
duke@435 | 97 | assert(char2type(0) == T_ILLEGAL, "correct illegality"); |
duke@435 | 98 | |
duke@435 | 99 | { |
duke@435 | 100 | for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) { |
duke@435 | 101 | BasicType vt = (BasicType)i; |
duke@435 | 102 | BasicType ft = type2field[vt]; |
duke@435 | 103 | switch (vt) { |
duke@435 | 104 | // the following types might plausibly show up in memory layouts: |
duke@435 | 105 | case T_BOOLEAN: |
duke@435 | 106 | case T_BYTE: |
duke@435 | 107 | case T_CHAR: |
duke@435 | 108 | case T_SHORT: |
duke@435 | 109 | case T_INT: |
duke@435 | 110 | case T_FLOAT: |
duke@435 | 111 | case T_DOUBLE: |
duke@435 | 112 | case T_LONG: |
duke@435 | 113 | case T_OBJECT: |
duke@435 | 114 | case T_ADDRESS: // random raw pointer |
coleenp@4037 | 115 | case T_METADATA: // metadata pointer |
coleenp@548 | 116 | case T_NARROWOOP: // compressed pointer |
duke@435 | 117 | case T_CONFLICT: // might as well support a bottom type |
duke@435 | 118 | case T_VOID: // padding or other unaddressed word |
duke@435 | 119 | // layout type must map to itself |
duke@435 | 120 | assert(vt == ft, ""); |
duke@435 | 121 | break; |
duke@435 | 122 | default: |
duke@435 | 123 | // non-layout type must map to a (different) layout type |
duke@435 | 124 | assert(vt != ft, ""); |
duke@435 | 125 | assert(ft == type2field[ft], ""); |
duke@435 | 126 | } |
duke@435 | 127 | // every type must map to same-sized layout type: |
duke@435 | 128 | assert(type2size[vt] == type2size[ft], ""); |
duke@435 | 129 | } |
duke@435 | 130 | } |
duke@435 | 131 | // These are assumed, e.g., when filling HeapWords with juints. |
duke@435 | 132 | assert(is_power_of_2(sizeof(juint)), "juint must be power of 2"); |
duke@435 | 133 | assert(is_power_of_2(HeapWordSize), "HeapWordSize must be power of 2"); |
duke@435 | 134 | assert((size_t)HeapWordSize >= sizeof(juint), |
duke@435 | 135 | "HeapWord should be at least as large as juint"); |
duke@435 | 136 | assert(sizeof(NULL) == sizeof(char*), "NULL must be same size as pointer"); |
duke@435 | 137 | #endif |
duke@435 | 138 | |
duke@435 | 139 | if( JavaPriority1_To_OSPriority != -1 ) |
duke@435 | 140 | os::java_to_os_priority[1] = JavaPriority1_To_OSPriority; |
duke@435 | 141 | if( JavaPriority2_To_OSPriority != -1 ) |
duke@435 | 142 | os::java_to_os_priority[2] = JavaPriority2_To_OSPriority; |
duke@435 | 143 | if( JavaPriority3_To_OSPriority != -1 ) |
duke@435 | 144 | os::java_to_os_priority[3] = JavaPriority3_To_OSPriority; |
duke@435 | 145 | if( JavaPriority4_To_OSPriority != -1 ) |
duke@435 | 146 | os::java_to_os_priority[4] = JavaPriority4_To_OSPriority; |
duke@435 | 147 | if( JavaPriority5_To_OSPriority != -1 ) |
duke@435 | 148 | os::java_to_os_priority[5] = JavaPriority5_To_OSPriority; |
duke@435 | 149 | if( JavaPriority6_To_OSPriority != -1 ) |
duke@435 | 150 | os::java_to_os_priority[6] = JavaPriority6_To_OSPriority; |
duke@435 | 151 | if( JavaPriority7_To_OSPriority != -1 ) |
duke@435 | 152 | os::java_to_os_priority[7] = JavaPriority7_To_OSPriority; |
duke@435 | 153 | if( JavaPriority8_To_OSPriority != -1 ) |
duke@435 | 154 | os::java_to_os_priority[8] = JavaPriority8_To_OSPriority; |
duke@435 | 155 | if( JavaPriority9_To_OSPriority != -1 ) |
duke@435 | 156 | os::java_to_os_priority[9] = JavaPriority9_To_OSPriority; |
duke@435 | 157 | if(JavaPriority10_To_OSPriority != -1 ) |
duke@435 | 158 | os::java_to_os_priority[10] = JavaPriority10_To_OSPriority; |
coleenp@548 | 159 | |
coleenp@548 | 160 | // Set the size of basic types here (after argument parsing but before |
coleenp@548 | 161 | // stub generation). |
coleenp@548 | 162 | if (UseCompressedOops) { |
coleenp@548 | 163 | // Size info for oops within java objects is fixed |
coleenp@548 | 164 | heapOopSize = jintSize; |
coleenp@548 | 165 | LogBytesPerHeapOop = LogBytesPerInt; |
coleenp@548 | 166 | LogBitsPerHeapOop = LogBitsPerInt; |
coleenp@548 | 167 | BytesPerHeapOop = BytesPerInt; |
coleenp@548 | 168 | BitsPerHeapOop = BitsPerInt; |
coleenp@548 | 169 | } else { |
coleenp@548 | 170 | heapOopSize = oopSize; |
coleenp@548 | 171 | LogBytesPerHeapOop = LogBytesPerWord; |
coleenp@548 | 172 | LogBitsPerHeapOop = LogBitsPerWord; |
coleenp@548 | 173 | BytesPerHeapOop = BytesPerWord; |
coleenp@548 | 174 | BitsPerHeapOop = BitsPerWord; |
coleenp@548 | 175 | } |
coleenp@548 | 176 | _type2aelembytes[T_OBJECT] = heapOopSize; |
coleenp@548 | 177 | _type2aelembytes[T_ARRAY] = heapOopSize; |
duke@435 | 178 | } |
duke@435 | 179 | |
duke@435 | 180 | |
duke@435 | 181 | // Map BasicType to signature character |
coleenp@4037 | 182 | char type2char_tab[T_CONFLICT+1]={ 0, 0, 0, 0, 'Z', 'C', 'F', 'D', 'B', 'S', 'I', 'J', 'L', '[', 'V', 0, 0, 0, 0}; |
duke@435 | 183 | |
duke@435 | 184 | // Map BasicType to Java type name |
duke@435 | 185 | const char* type2name_tab[T_CONFLICT+1] = { |
duke@435 | 186 | NULL, NULL, NULL, NULL, |
duke@435 | 187 | "boolean", |
duke@435 | 188 | "char", |
duke@435 | 189 | "float", |
duke@435 | 190 | "double", |
duke@435 | 191 | "byte", |
duke@435 | 192 | "short", |
duke@435 | 193 | "int", |
duke@435 | 194 | "long", |
duke@435 | 195 | "object", |
duke@435 | 196 | "array", |
duke@435 | 197 | "void", |
duke@435 | 198 | "*address*", |
coleenp@548 | 199 | "*narrowoop*", |
coleenp@4037 | 200 | "*metadata*", |
duke@435 | 201 | "*conflict*" |
duke@435 | 202 | }; |
duke@435 | 203 | |
duke@435 | 204 | |
duke@435 | 205 | BasicType name2type(const char* name) { |
duke@435 | 206 | for (int i = T_BOOLEAN; i <= T_VOID; i++) { |
duke@435 | 207 | BasicType t = (BasicType)i; |
duke@435 | 208 | if (type2name_tab[t] != NULL && 0 == strcmp(type2name_tab[t], name)) |
duke@435 | 209 | return t; |
duke@435 | 210 | } |
duke@435 | 211 | return T_ILLEGAL; |
duke@435 | 212 | } |
duke@435 | 213 | |
duke@435 | 214 | |
duke@435 | 215 | // Map BasicType to size in words |
roland@4051 | 216 | int type2size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 0, 1, 1, 1, -1}; |
duke@435 | 217 | |
duke@435 | 218 | BasicType type2field[T_CONFLICT+1] = { |
duke@435 | 219 | (BasicType)0, // 0, |
duke@435 | 220 | (BasicType)0, // 1, |
duke@435 | 221 | (BasicType)0, // 2, |
duke@435 | 222 | (BasicType)0, // 3, |
duke@435 | 223 | T_BOOLEAN, // T_BOOLEAN = 4, |
duke@435 | 224 | T_CHAR, // T_CHAR = 5, |
duke@435 | 225 | T_FLOAT, // T_FLOAT = 6, |
duke@435 | 226 | T_DOUBLE, // T_DOUBLE = 7, |
duke@435 | 227 | T_BYTE, // T_BYTE = 8, |
duke@435 | 228 | T_SHORT, // T_SHORT = 9, |
duke@435 | 229 | T_INT, // T_INT = 10, |
duke@435 | 230 | T_LONG, // T_LONG = 11, |
duke@435 | 231 | T_OBJECT, // T_OBJECT = 12, |
duke@435 | 232 | T_OBJECT, // T_ARRAY = 13, |
duke@435 | 233 | T_VOID, // T_VOID = 14, |
duke@435 | 234 | T_ADDRESS, // T_ADDRESS = 15, |
coleenp@548 | 235 | T_NARROWOOP, // T_NARROWOOP= 16, |
coleenp@4037 | 236 | T_METADATA, // T_METADATA = 17, |
coleenp@4037 | 237 | T_CONFLICT // T_CONFLICT = 18, |
duke@435 | 238 | }; |
duke@435 | 239 | |
duke@435 | 240 | |
duke@435 | 241 | BasicType type2wfield[T_CONFLICT+1] = { |
duke@435 | 242 | (BasicType)0, // 0, |
duke@435 | 243 | (BasicType)0, // 1, |
duke@435 | 244 | (BasicType)0, // 2, |
duke@435 | 245 | (BasicType)0, // 3, |
duke@435 | 246 | T_INT, // T_BOOLEAN = 4, |
duke@435 | 247 | T_INT, // T_CHAR = 5, |
duke@435 | 248 | T_FLOAT, // T_FLOAT = 6, |
duke@435 | 249 | T_DOUBLE, // T_DOUBLE = 7, |
duke@435 | 250 | T_INT, // T_BYTE = 8, |
duke@435 | 251 | T_INT, // T_SHORT = 9, |
duke@435 | 252 | T_INT, // T_INT = 10, |
duke@435 | 253 | T_LONG, // T_LONG = 11, |
duke@435 | 254 | T_OBJECT, // T_OBJECT = 12, |
duke@435 | 255 | T_OBJECT, // T_ARRAY = 13, |
duke@435 | 256 | T_VOID, // T_VOID = 14, |
duke@435 | 257 | T_ADDRESS, // T_ADDRESS = 15, |
coleenp@548 | 258 | T_NARROWOOP, // T_NARROWOOP = 16, |
coleenp@4037 | 259 | T_METADATA, // T_METADATA = 17, |
coleenp@4037 | 260 | T_CONFLICT // T_CONFLICT = 18, |
duke@435 | 261 | }; |
duke@435 | 262 | |
duke@435 | 263 | |
kvn@464 | 264 | int _type2aelembytes[T_CONFLICT+1] = { |
duke@435 | 265 | 0, // 0 |
duke@435 | 266 | 0, // 1 |
duke@435 | 267 | 0, // 2 |
duke@435 | 268 | 0, // 3 |
duke@435 | 269 | T_BOOLEAN_aelem_bytes, // T_BOOLEAN = 4, |
duke@435 | 270 | T_CHAR_aelem_bytes, // T_CHAR = 5, |
duke@435 | 271 | T_FLOAT_aelem_bytes, // T_FLOAT = 6, |
duke@435 | 272 | T_DOUBLE_aelem_bytes, // T_DOUBLE = 7, |
duke@435 | 273 | T_BYTE_aelem_bytes, // T_BYTE = 8, |
duke@435 | 274 | T_SHORT_aelem_bytes, // T_SHORT = 9, |
duke@435 | 275 | T_INT_aelem_bytes, // T_INT = 10, |
duke@435 | 276 | T_LONG_aelem_bytes, // T_LONG = 11, |
duke@435 | 277 | T_OBJECT_aelem_bytes, // T_OBJECT = 12, |
duke@435 | 278 | T_ARRAY_aelem_bytes, // T_ARRAY = 13, |
duke@435 | 279 | 0, // T_VOID = 14, |
kvn@464 | 280 | T_OBJECT_aelem_bytes, // T_ADDRESS = 15, |
coleenp@548 | 281 | T_NARROWOOP_aelem_bytes,// T_NARROWOOP= 16, |
coleenp@4037 | 282 | T_OBJECT_aelem_bytes, // T_METADATA = 17, |
coleenp@4037 | 283 | 0 // T_CONFLICT = 18, |
duke@435 | 284 | }; |
duke@435 | 285 | |
kvn@464 | 286 | #ifdef ASSERT |
kvn@464 | 287 | int type2aelembytes(BasicType t, bool allow_address) { |
kvn@464 | 288 | assert(allow_address || t != T_ADDRESS, " "); |
kvn@464 | 289 | return _type2aelembytes[t]; |
kvn@464 | 290 | } |
kvn@464 | 291 | #endif |
duke@435 | 292 | |
duke@435 | 293 | // Support for 64-bit integer arithmetic |
duke@435 | 294 | |
duke@435 | 295 | // The following code is mostly taken from JVM typedefs_md.h and system_md.c |
duke@435 | 296 | |
coleenp@548 | 297 | static const jlong high_bit = (jlong)1 << (jlong)63; |
duke@435 | 298 | static const jlong other_bits = ~high_bit; |
duke@435 | 299 | |
duke@435 | 300 | jlong float2long(jfloat f) { |
duke@435 | 301 | jlong tmp = (jlong) f; |
duke@435 | 302 | if (tmp != high_bit) { |
duke@435 | 303 | return tmp; |
duke@435 | 304 | } else { |
duke@435 | 305 | if (g_isnan((jdouble)f)) { |
duke@435 | 306 | return 0; |
duke@435 | 307 | } |
duke@435 | 308 | if (f < 0) { |
duke@435 | 309 | return high_bit; |
duke@435 | 310 | } else { |
duke@435 | 311 | return other_bits; |
duke@435 | 312 | } |
duke@435 | 313 | } |
duke@435 | 314 | } |
duke@435 | 315 | |
duke@435 | 316 | |
duke@435 | 317 | jlong double2long(jdouble f) { |
duke@435 | 318 | jlong tmp = (jlong) f; |
duke@435 | 319 | if (tmp != high_bit) { |
duke@435 | 320 | return tmp; |
duke@435 | 321 | } else { |
duke@435 | 322 | if (g_isnan(f)) { |
duke@435 | 323 | return 0; |
duke@435 | 324 | } |
duke@435 | 325 | if (f < 0) { |
duke@435 | 326 | return high_bit; |
duke@435 | 327 | } else { |
duke@435 | 328 | return other_bits; |
duke@435 | 329 | } |
duke@435 | 330 | } |
duke@435 | 331 | } |
duke@435 | 332 | |
duke@435 | 333 | // least common multiple |
duke@435 | 334 | size_t lcm(size_t a, size_t b) { |
duke@435 | 335 | size_t cur, div, next; |
duke@435 | 336 | |
duke@435 | 337 | cur = MAX2(a, b); |
duke@435 | 338 | div = MIN2(a, b); |
duke@435 | 339 | |
duke@435 | 340 | assert(div != 0, "lcm requires positive arguments"); |
duke@435 | 341 | |
duke@435 | 342 | |
duke@435 | 343 | while ((next = cur % div) != 0) { |
duke@435 | 344 | cur = div; div = next; |
duke@435 | 345 | } |
duke@435 | 346 | |
duke@435 | 347 | |
duke@435 | 348 | julong result = julong(a) * b / div; |
duke@435 | 349 | assert(result <= (size_t)max_uintx, "Integer overflow in lcm"); |
duke@435 | 350 | |
duke@435 | 351 | return size_t(result); |
duke@435 | 352 | } |