1 /* 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_UTILITIES_MACROS_HPP 26 #define SHARE_VM_UTILITIES_MACROS_HPP 27 28 // Use this to mark code that needs to be cleaned up (for development only) 29 #define NEEDS_CLEANUP 30 31 // Makes a string of the argument (which is not macro-expanded) 32 #define STR(a) #a 33 34 // Makes a string of the macro expansion of a 35 #define XSTR(a) STR(a) 36 37 // Allow commas in macro arguments. 38 #define COMMA , 39 40 // Apply pre-processor token pasting to the expansions of x and y. 41 // The token pasting operator (##) prevents its arguments from being 42 // expanded. This macro allows expansion of its arguments before the 43 // concatenation is performed. Note: One auxilliary level ought to be 44 // sufficient, but two are used because of bugs in some preprocesors. 45 #define PASTE_TOKENS(x, y) PASTE_TOKENS_AUX(x, y) 46 #define PASTE_TOKENS_AUX(x, y) PASTE_TOKENS_AUX2(x, y) 47 #define PASTE_TOKENS_AUX2(x, y) x ## y 48 49 // -DINCLUDE_<something>=0 | 1 can be specified on the command line to include 50 // or exclude functionality. 51 52 #ifndef INCLUDE_JVMTI 53 #define INCLUDE_JVMTI 1 54 #endif // INCLUDE_JVMTI 55 56 #if INCLUDE_JVMTI 57 #define JVMTI_ONLY(x) x 58 #define NOT_JVMTI(x) 59 #define NOT_JVMTI_RETURN 60 #define NOT_JVMTI_RETURN_(code) /* next token must be ; */ 61 #else 62 #define JVMTI_ONLY(x) 63 #define NOT_JVMTI(x) x 64 #define NOT_JVMTI_RETURN { return; } 65 #define NOT_JVMTI_RETURN_(code) { return code; } 66 #endif // INCLUDE_JVMTI 67 68 #ifndef INCLUDE_FPROF 69 #define INCLUDE_FPROF 1 70 #endif 71 72 #if INCLUDE_FPROF 73 #define NOT_FPROF_RETURN /* next token must be ; */ 74 #define NOT_FPROF_RETURN_(code) /* next token must be ; */ 75 #else 76 #define NOT_FPROF_RETURN {} 77 #define NOT_FPROF_RETURN_(code) { return code; } 78 #endif // INCLUDE_FPROF 79 80 #ifndef INCLUDE_VM_STRUCTS 81 #define INCLUDE_VM_STRUCTS 1 82 #endif 83 84 #if INCLUDE_VM_STRUCTS 85 #define NOT_VM_STRUCTS_RETURN /* next token must be ; */ 86 #define NOT_VM_STRUCTS_RETURN_(code) /* next token must be ; */ 87 #else 88 #define NOT_VM_STRUCTS_RETURN {} 89 #define NOT_VM_STRUCTS_RETURN_(code) { return code; } 90 #endif // INCLUDE_VM_STRUCTS 91 92 #ifndef INCLUDE_JNI_CHECK 93 #define INCLUDE_JNI_CHECK 1 94 #endif 95 96 #if INCLUDE_JNI_CHECK 97 #define NOT_JNI_CHECK_RETURN /* next token must be ; */ 98 #define NOT_JNI_CHECK_RETURN_(code) /* next token must be ; */ 99 #else 100 #define NOT_JNI_CHECK_RETURN {} 101 #define NOT_JNI_CHECK_RETURN_(code) { return code; } 102 #endif // INCLUDE_JNI_CHECK 103 104 #ifndef INCLUDE_SERVICES 105 #define INCLUDE_SERVICES 1 106 #endif 107 108 #if INCLUDE_SERVICES 109 #define NOT_SERVICES_RETURN /* next token must be ; */ 110 #define NOT_SERVICES_RETURN_(code) /* next token must be ; */ 111 #else 112 #define NOT_SERVICES_RETURN {} 113 #define NOT_SERVICES_RETURN_(code) { return code; } 114 #endif // INCLUDE_SERVICES 115 116 #ifndef INCLUDE_CDS 117 #define INCLUDE_CDS 1 118 #endif 119 120 #if INCLUDE_CDS 121 #define CDS_ONLY(x) x 122 #define NOT_CDS(x) 123 #define NOT_CDS_RETURN /* next token must be ; */ 124 #define NOT_CDS_RETURN_(code) /* next token must be ; */ 125 #else 126 #define CDS_ONLY(x) 127 #define NOT_CDS(x) x 128 #define NOT_CDS_RETURN {} 129 #define NOT_CDS_RETURN_(code) { return code; } 130 #endif // INCLUDE_CDS 131 132 #ifndef INCLUDE_MANAGEMENT 133 #define INCLUDE_MANAGEMENT 1 134 #endif // INCLUDE_MANAGEMENT 135 136 #if INCLUDE_MANAGEMENT 137 #define NOT_MANAGEMENT_RETURN /* next token must be ; */ 138 #define NOT_MANAGEMENT_RETURN_(code) /* next token must be ; */ 139 #else 140 #define NOT_MANAGEMENT_RETURN {} 141 #define NOT_MANAGEMENT_RETURN_(code) { return code; } 142 #endif // INCLUDE_MANAGEMENT 143 144 /* 145 * When INCLUDE_ALL_GCS is false the only garbage collectors 146 * included in the JVM are defaultNewGeneration and markCompact. 147 * 148 * When INCLUDE_ALL_GCS is true all garbage collectors are 149 * included in the JVM. 150 */ 151 #ifndef INCLUDE_ALL_GCS 152 #define INCLUDE_ALL_GCS 1 153 #endif // INCLUDE_ALL_GCS 154 155 #if INCLUDE_ALL_GCS 156 #define NOT_ALL_GCS_RETURN /* next token must be ; */ 157 #define NOT_ALL_GCS_RETURN_(code) /* next token must be ; */ 158 #else 159 #define NOT_ALL_GCS_RETURN {} 160 #define NOT_ALL_GCS_RETURN_(code) { return code; } 161 #endif // INCLUDE_ALL_GCS 162 163 #ifndef INCLUDE_NMT 164 #define INCLUDE_NMT 1 165 #endif // INCLUDE_NMT 166 167 #if INCLUDE_NMT 168 #define NOT_NMT_RETURN /* next token must be ; */ 169 #define NOT_NMT_RETURN_(code) /* next token must be ; */ 170 #else 171 #define NOT_NMT_RETURN {} 172 #define NOT_NMT_RETURN_(code) { return code; } 173 #endif // INCLUDE_NMT 174 175 #ifndef INCLUDE_TRACE 176 #define INCLUDE_TRACE 1 177 #endif // INCLUDE_TRACE 178 179 #ifndef INCLUDE_JVMCI 180 #define INCLUDE_JVMCI 1 181 #endif 182 183 #ifdef INCLUDE_AOT 184 # if INCLUDE_AOT && !(INCLUDE_JVMCI) 185 # error "Must have JVMCI for AOT" 186 # endif 187 #else 188 # define INCLUDE_AOT 0 189 #endif 190 191 #if INCLUDE_JVMCI 192 #define JVMCI_ONLY(code) code 193 #define NOT_JVMCI(code) 194 #define NOT_JVMCI_RETURN /* next token must be ; */ 195 #else 196 #define JVMCI_ONLY(code) 197 #define NOT_JVMCI(code) code 198 #define NOT_JVMCI_RETURN {} 199 #endif // INCLUDE_JVMCI 200 201 #if INCLUDE_AOT 202 #define AOT_ONLY(code) code 203 #define NOT_AOT(code) 204 #define NOT_AOT_RETURN /* next token must be ; */ 205 #else 206 #define AOT_ONLY(code) 207 #define NOT_AOT(code) code 208 #define NOT_AOT_RETURN {} 209 #endif // INCLUDE_AOT 210 211 // COMPILER1 variant 212 #ifdef COMPILER1 213 #ifdef COMPILER2 214 #define TIERED 215 #endif 216 #define COMPILER1_PRESENT(code) code 217 #else // COMPILER1 218 #define COMPILER1_PRESENT(code) 219 #endif // COMPILER1 220 221 // COMPILER2 variant 222 #ifdef COMPILER2 223 #define COMPILER2_PRESENT(code) code 224 #define NOT_COMPILER2(code) 225 #else // COMPILER2 226 #define COMPILER2_PRESENT(code) 227 #define NOT_COMPILER2(code) code 228 #endif // COMPILER2 229 230 // COMPILER2 or JVMCI 231 #if defined(COMPILER2) || INCLUDE_JVMCI 232 #define COMPILER2_OR_JVMCI 1 233 #define COMPILER2_OR_JVMCI_PRESENT(code) code 234 #define NOT_COMPILER2_OR_JVMCI(code) 235 #else 236 #define COMPILER2_OR_JVMCI 0 237 #define COMPILER2_OR_JVMCI_PRESENT(code) 238 #define NOT_COMPILER2_OR_JVMCI(code) code 239 #endif 240 241 #ifdef TIERED 242 #define TIERED_ONLY(code) code 243 #define NOT_TIERED(code) 244 #else // TIERED 245 #define TIERED_ONLY(code) 246 #define NOT_TIERED(code) code 247 #endif // TIERED 248 249 250 // PRODUCT variant 251 #ifdef PRODUCT 252 #define PRODUCT_ONLY(code) code 253 #define NOT_PRODUCT(code) 254 #define NOT_PRODUCT_ARG(arg) 255 #define PRODUCT_RETURN {} 256 #define PRODUCT_RETURN0 { return 0; } 257 #define PRODUCT_RETURN_(code) { code } 258 #else // PRODUCT 259 #define PRODUCT_ONLY(code) 260 #define NOT_PRODUCT(code) code 261 #define NOT_PRODUCT_ARG(arg) arg, 262 #define PRODUCT_RETURN /*next token must be ;*/ 263 #define PRODUCT_RETURN0 /*next token must be ;*/ 264 #define PRODUCT_RETURN_(code) /*next token must be ;*/ 265 #endif // PRODUCT 266 267 #ifdef CHECK_UNHANDLED_OOPS 268 #define CHECK_UNHANDLED_OOPS_ONLY(code) code 269 #define NOT_CHECK_UNHANDLED_OOPS(code) 270 #else 271 #define CHECK_UNHANDLED_OOPS_ONLY(code) 272 #define NOT_CHECK_UNHANDLED_OOPS(code) code 273 #endif // CHECK_UNHANDLED_OOPS 274 275 #ifdef CC_INTERP 276 #define CC_INTERP_ONLY(code) code 277 #define NOT_CC_INTERP(code) 278 #else 279 #define CC_INTERP_ONLY(code) 280 #define NOT_CC_INTERP(code) code 281 #endif // CC_INTERP 282 283 #ifdef ASSERT 284 #define DEBUG_ONLY(code) code 285 #define NOT_DEBUG(code) 286 #define NOT_DEBUG_RETURN /*next token must be ;*/ 287 // Historical. 288 #define debug_only(code) code 289 #else // ASSERT 290 #define DEBUG_ONLY(code) 291 #define NOT_DEBUG(code) code 292 #define NOT_DEBUG_RETURN {} 293 #define debug_only(code) 294 #endif // ASSERT 295 296 #ifdef _LP64 297 #define LP64_ONLY(code) code 298 #define NOT_LP64(code) 299 #else // !_LP64 300 #define LP64_ONLY(code) 301 #define NOT_LP64(code) code 302 #endif // _LP64 303 304 #ifdef LINUX 305 #define LINUX_ONLY(code) code 306 #define NOT_LINUX(code) 307 #else 308 #define LINUX_ONLY(code) 309 #define NOT_LINUX(code) code 310 #endif 311 312 #ifdef AIX 313 #define AIX_ONLY(code) code 314 #define NOT_AIX(code) 315 #else 316 #define AIX_ONLY(code) 317 #define NOT_AIX(code) code 318 #endif 319 320 #ifdef SOLARIS 321 #define SOLARIS_ONLY(code) code 322 #define NOT_SOLARIS(code) 323 #else 324 #define SOLARIS_ONLY(code) 325 #define NOT_SOLARIS(code) code 326 #endif 327 328 #ifdef _WINDOWS 329 #define WINDOWS_ONLY(code) code 330 #define NOT_WINDOWS(code) 331 #else 332 #define WINDOWS_ONLY(code) 333 #define NOT_WINDOWS(code) code 334 #endif 335 336 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) 337 #define BSD 338 #define BSD_ONLY(code) code 339 #define NOT_BSD(code) 340 #else 341 #define BSD_ONLY(code) 342 #define NOT_BSD(code) code 343 #endif 344 345 #ifdef _WIN64 346 #define WIN64_ONLY(code) code 347 #define NOT_WIN64(code) 348 #else 349 #define WIN64_ONLY(code) 350 #define NOT_WIN64(code) code 351 #endif 352 353 #if defined(ZERO) 354 #define ZERO_ONLY(code) code 355 #define NOT_ZERO(code) 356 #else 357 #define ZERO_ONLY(code) 358 #define NOT_ZERO(code) code 359 #endif 360 361 #if defined(SHARK) 362 #define SHARK_ONLY(code) code 363 #define NOT_SHARK(code) 364 #else 365 #define SHARK_ONLY(code) 366 #define NOT_SHARK(code) code 367 #endif 368 369 #if defined(IA32) || defined(AMD64) 370 #define X86 371 #define X86_ONLY(code) code 372 #define NOT_X86(code) 373 #else 374 #undef X86 375 #define X86_ONLY(code) 376 #define NOT_X86(code) code 377 #endif 378 379 #ifdef IA32 380 #define IA32_ONLY(code) code 381 #define NOT_IA32(code) 382 #else 383 #define IA32_ONLY(code) 384 #define NOT_IA32(code) code 385 #endif 386 387 // This is a REALLY BIG HACK, but on AIX <sys/systemcfg.h> unconditionally defines IA64. 388 // At least on AIX 7.1 this is a real problem because 'systemcfg.h' is indirectly included 389 // by 'pthread.h' and other common system headers. 390 391 #if defined(IA64) && !defined(AIX) 392 #define IA64_ONLY(code) code 393 #define NOT_IA64(code) 394 #else 395 #define IA64_ONLY(code) 396 #define NOT_IA64(code) code 397 #endif 398 399 #ifdef AMD64 400 #define AMD64_ONLY(code) code 401 #define NOT_AMD64(code) 402 #else 403 #define AMD64_ONLY(code) 404 #define NOT_AMD64(code) code 405 #endif 406 407 #ifdef S390 408 #define S390_ONLY(code) code 409 #define NOT_S390(code) 410 #else 411 #define S390_ONLY(code) 412 #define NOT_S390(code) code 413 #endif 414 415 #ifdef SPARC 416 #define SPARC_ONLY(code) code 417 #define NOT_SPARC(code) 418 #else 419 #define SPARC_ONLY(code) 420 #define NOT_SPARC(code) code 421 #endif 422 423 #if defined(PPC32) || defined(PPC64) 424 #ifndef PPC 425 #define PPC 426 #endif 427 #define PPC_ONLY(code) code 428 #define NOT_PPC(code) 429 #else 430 #undef PPC 431 #define PPC_ONLY(code) 432 #define NOT_PPC(code) code 433 #endif 434 435 #ifdef PPC32 436 #define PPC32_ONLY(code) code 437 #define NOT_PPC32(code) 438 #else 439 #define PPC32_ONLY(code) 440 #define NOT_PPC32(code) code 441 #endif 442 443 #ifdef PPC64 444 #define PPC64_ONLY(code) code 445 #define NOT_PPC64(code) 446 #else 447 #define PPC64_ONLY(code) 448 #define NOT_PPC64(code) code 449 #endif 450 451 #ifdef E500V2 452 #define E500V2_ONLY(code) code 453 #define NOT_E500V2(code) 454 #else 455 #define E500V2_ONLY(code) 456 #define NOT_E500V2(code) code 457 #endif 458 459 // Note: There are three ARM ports. They set the following in the makefiles: 460 // 1. Closed 32-bit port: -DARM -DARM32 -DTARGET_ARCH_arm 461 // 2. Closed 64-bit port: -DARM -DAARCH64 -D_LP64 -DTARGET_ARCH_arm 462 // 3. Open 64-bit port: -DAARCH64 -D_LP64 -DTARGET_ARCH_aaarch64 463 #ifdef ARM 464 #define ARM_ONLY(code) code 465 #define NOT_ARM(code) 466 #else 467 #define ARM_ONLY(code) 468 #define NOT_ARM(code) code 469 #endif 470 471 #ifdef ARM32 472 #define ARM32_ONLY(code) code 473 #define NOT_ARM32(code) 474 #else 475 #define ARM32_ONLY(code) 476 #define NOT_ARM32(code) code 477 #endif 478 479 #ifdef AARCH64 480 #define AARCH64_ONLY(code) code 481 #define NOT_AARCH64(code) 482 #else 483 #define AARCH64_ONLY(code) 484 #define NOT_AARCH64(code) code 485 #endif 486 487 #define define_pd_global(type, name, value) const type pd_##name = value; 488 489 // Helper macros for constructing file names for includes. 490 #define CPU_HEADER_STEM(basename) PASTE_TOKENS(basename, INCLUDE_SUFFIX_CPU) 491 #define OS_HEADER_STEM(basename) PASTE_TOKENS(basename, INCLUDE_SUFFIX_OS) 492 #define OS_CPU_HEADER_STEM(basename) PASTE_TOKENS(basename, PASTE_TOKENS(INCLUDE_SUFFIX_OS, INCLUDE_SUFFIX_CPU)) 493 494 // Include platform dependent files. 495 // 496 // This macro constructs from basename and INCLUDE_SUFFIX_OS / 497 // INCLUDE_SUFFIX_CPU, which are set on the command line, the name of 498 // platform dependent files to be included. 499 // Example: INCLUDE_SUFFIX_OS=_linux / INCLUDE_SUFFIX_CPU=_sparc 500 // CPU_HEADER_INLINE(macroAssembler) --> macroAssembler_sparc.inline.hpp 501 // OS_CPU_HEADER(vmStructs) --> vmStructs_linux_sparc.hpp 502 // 503 // basename<cpu>.hpp / basename<cpu>.inline.hpp 504 #define CPU_HEADER_H(basename) XSTR(CPU_HEADER_STEM(basename).h) 505 #define CPU_HEADER(basename) XSTR(CPU_HEADER_STEM(basename).hpp) 506 #define CPU_HEADER_INLINE(basename) XSTR(CPU_HEADER_STEM(basename).inline.hpp) 507 // basename<os>.hpp / basename<os>.inline.hpp 508 #define OS_HEADER_H(basename) XSTR(OS_HEADER_STEM(basename).h) 509 #define OS_HEADER(basename) XSTR(OS_HEADER_STEM(basename).hpp) 510 #define OS_HEADER_INLINE(basename) XSTR(OS_HEADER_STEM(basename).inline.hpp) 511 // basename<os><cpu>.hpp / basename<os><cpu>.inline.hpp 512 #define OS_CPU_HEADER(basename) XSTR(OS_CPU_HEADER_STEM(basename).hpp) 513 #define OS_CPU_HEADER_INLINE(basename) XSTR(OS_CPU_HEADER_STEM(basename).inline.hpp) 514 515 // To use Atomic::inc(jshort* dest) and Atomic::dec(jshort* dest), the address must be specially 516 // aligned, such that (*dest) occupies the upper 16 bits of an aligned 32-bit word. The best way to 517 // achieve is to place your short value next to another short value, which doesn't need atomic ops. 518 // 519 // Example 520 // ATOMIC_SHORT_PAIR( 521 // volatile short _refcount, // needs atomic operation 522 // unsigned short _length // number of UTF8 characters in the symbol (does not need atomic op) 523 // ); 524 525 #ifdef VM_LITTLE_ENDIAN 526 #define ATOMIC_SHORT_PAIR(atomic_decl, non_atomic_decl) \ 527 non_atomic_decl; \ 528 atomic_decl 529 #else 530 #define ATOMIC_SHORT_PAIR(atomic_decl, non_atomic_decl) \ 531 atomic_decl; \ 532 non_atomic_decl 533 #endif 534 535 #endif // SHARE_VM_UTILITIES_MACROS_HPP