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_SHENANDOAH_GC 164 #define INCLUDE_SHENANDOAH_GC 0 165 #endif 166 167 #ifndef INCLUDE_NMT 168 #define INCLUDE_NMT 1 169 #endif // INCLUDE_NMT 170 171 #if INCLUDE_NMT 172 #define NOT_NMT_RETURN /* next token must be ; */ 173 #define NOT_NMT_RETURN_(code) /* next token must be ; */ 174 #else 175 #define NOT_NMT_RETURN {} 176 #define NOT_NMT_RETURN_(code) { return code; } 177 #endif // INCLUDE_NMT 178 179 #ifndef INCLUDE_TRACE 180 #define INCLUDE_TRACE 1 181 #endif // INCLUDE_TRACE 182 183 #ifndef INCLUDE_JVMCI 184 #define INCLUDE_JVMCI 1 185 #endif 186 187 #ifdef INCLUDE_AOT 188 # if INCLUDE_AOT && !(INCLUDE_JVMCI) 189 # error "Must have JVMCI for AOT" 190 # endif 191 #else 192 # define INCLUDE_AOT 0 193 #endif 194 195 #if INCLUDE_JVMCI 196 #define JVMCI_ONLY(code) code 197 #define NOT_JVMCI(code) 198 #define NOT_JVMCI_RETURN /* next token must be ; */ 199 #else 200 #define JVMCI_ONLY(code) 201 #define NOT_JVMCI(code) code 202 #define NOT_JVMCI_RETURN {} 203 #endif // INCLUDE_JVMCI 204 205 #if INCLUDE_AOT 206 #define AOT_ONLY(code) code 207 #define NOT_AOT(code) 208 #define NOT_AOT_RETURN /* next token must be ; */ 209 #else 210 #define AOT_ONLY(code) 211 #define NOT_AOT(code) code 212 #define NOT_AOT_RETURN {} 213 #endif // INCLUDE_AOT 214 215 // COMPILER1 variant 216 #ifdef COMPILER1 217 #ifdef COMPILER2 218 #define TIERED 219 #endif 220 #define COMPILER1_PRESENT(code) code 221 #else // COMPILER1 222 #define COMPILER1_PRESENT(code) 223 #endif // COMPILER1 224 225 // COMPILER2 variant 226 #ifdef COMPILER2 227 #define COMPILER2_PRESENT(code) code 228 #define NOT_COMPILER2(code) 229 #else // COMPILER2 230 #define COMPILER2_PRESENT(code) 231 #define NOT_COMPILER2(code) code 232 #endif // COMPILER2 233 234 // COMPILER2 or JVMCI 235 #if defined(COMPILER2) || INCLUDE_JVMCI 236 #define COMPILER2_OR_JVMCI 1 237 #define COMPILER2_OR_JVMCI_PRESENT(code) code 238 #define NOT_COMPILER2_OR_JVMCI(code) 239 #else 240 #define COMPILER2_OR_JVMCI 0 241 #define COMPILER2_OR_JVMCI_PRESENT(code) 242 #define NOT_COMPILER2_OR_JVMCI(code) code 243 #endif 244 245 #ifdef TIERED 246 #define TIERED_ONLY(code) code 247 #define NOT_TIERED(code) 248 #else // TIERED 249 #define TIERED_ONLY(code) 250 #define NOT_TIERED(code) code 251 #endif // TIERED 252 253 254 // PRODUCT variant 255 #ifdef PRODUCT 256 #define PRODUCT_ONLY(code) code 257 #define NOT_PRODUCT(code) 258 #define NOT_PRODUCT_ARG(arg) 259 #define PRODUCT_RETURN {} 260 #define PRODUCT_RETURN0 { return 0; } 261 #define PRODUCT_RETURN_(code) { code } 262 #else // PRODUCT 263 #define PRODUCT_ONLY(code) 264 #define NOT_PRODUCT(code) code 265 #define NOT_PRODUCT_ARG(arg) arg, 266 #define PRODUCT_RETURN /*next token must be ;*/ 267 #define PRODUCT_RETURN0 /*next token must be ;*/ 268 #define PRODUCT_RETURN_(code) /*next token must be ;*/ 269 #endif // PRODUCT 270 271 #ifdef CHECK_UNHANDLED_OOPS 272 #define CHECK_UNHANDLED_OOPS_ONLY(code) code 273 #define NOT_CHECK_UNHANDLED_OOPS(code) 274 #else 275 #define CHECK_UNHANDLED_OOPS_ONLY(code) 276 #define NOT_CHECK_UNHANDLED_OOPS(code) code 277 #endif // CHECK_UNHANDLED_OOPS 278 279 #ifdef CC_INTERP 280 #define CC_INTERP_ONLY(code) code 281 #define NOT_CC_INTERP(code) 282 #else 283 #define CC_INTERP_ONLY(code) 284 #define NOT_CC_INTERP(code) code 285 #endif // CC_INTERP 286 287 #ifdef ASSERT 288 #define DEBUG_ONLY(code) code 289 #define NOT_DEBUG(code) 290 #define NOT_DEBUG_RETURN /*next token must be ;*/ 291 // Historical. 292 #define debug_only(code) code 293 #else // ASSERT 294 #define DEBUG_ONLY(code) 295 #define NOT_DEBUG(code) code 296 #define NOT_DEBUG_RETURN {} 297 #define debug_only(code) 298 #endif // ASSERT 299 300 #ifdef _LP64 301 #define LP64_ONLY(code) code 302 #define NOT_LP64(code) 303 #else // !_LP64 304 #define LP64_ONLY(code) 305 #define NOT_LP64(code) code 306 #endif // _LP64 307 308 #ifdef LINUX 309 #define LINUX_ONLY(code) code 310 #define NOT_LINUX(code) 311 #else 312 #define LINUX_ONLY(code) 313 #define NOT_LINUX(code) code 314 #endif 315 316 #ifdef AIX 317 #define AIX_ONLY(code) code 318 #define NOT_AIX(code) 319 #else 320 #define AIX_ONLY(code) 321 #define NOT_AIX(code) code 322 #endif 323 324 #ifdef SOLARIS 325 #define SOLARIS_ONLY(code) code 326 #define NOT_SOLARIS(code) 327 #else 328 #define SOLARIS_ONLY(code) 329 #define NOT_SOLARIS(code) code 330 #endif 331 332 #ifdef _WINDOWS 333 #define WINDOWS_ONLY(code) code 334 #define NOT_WINDOWS(code) 335 #else 336 #define WINDOWS_ONLY(code) 337 #define NOT_WINDOWS(code) code 338 #endif 339 340 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) 341 #define BSD 342 #define BSD_ONLY(code) code 343 #define NOT_BSD(code) 344 #else 345 #define BSD_ONLY(code) 346 #define NOT_BSD(code) code 347 #endif 348 349 #ifdef _WIN64 350 #define WIN64_ONLY(code) code 351 #define NOT_WIN64(code) 352 #else 353 #define WIN64_ONLY(code) 354 #define NOT_WIN64(code) code 355 #endif 356 357 #if defined(ZERO) 358 #define ZERO_ONLY(code) code 359 #define NOT_ZERO(code) 360 #else 361 #define ZERO_ONLY(code) 362 #define NOT_ZERO(code) code 363 #endif 364 365 #if defined(SHARK) 366 #define SHARK_ONLY(code) code 367 #define NOT_SHARK(code) 368 #else 369 #define SHARK_ONLY(code) 370 #define NOT_SHARK(code) code 371 #endif 372 373 #if defined(IA32) || defined(AMD64) 374 #define X86 375 #define X86_ONLY(code) code 376 #define NOT_X86(code) 377 #else 378 #undef X86 379 #define X86_ONLY(code) 380 #define NOT_X86(code) code 381 #endif 382 383 #ifdef IA32 384 #define IA32_ONLY(code) code 385 #define NOT_IA32(code) 386 #else 387 #define IA32_ONLY(code) 388 #define NOT_IA32(code) code 389 #endif 390 391 // This is a REALLY BIG HACK, but on AIX <sys/systemcfg.h> unconditionally defines IA64. 392 // At least on AIX 7.1 this is a real problem because 'systemcfg.h' is indirectly included 393 // by 'pthread.h' and other common system headers. 394 395 #if defined(IA64) && !defined(AIX) 396 #define IA64_ONLY(code) code 397 #define NOT_IA64(code) 398 #else 399 #define IA64_ONLY(code) 400 #define NOT_IA64(code) code 401 #endif 402 403 #ifdef AMD64 404 #define AMD64_ONLY(code) code 405 #define NOT_AMD64(code) 406 #else 407 #define AMD64_ONLY(code) 408 #define NOT_AMD64(code) code 409 #endif 410 411 #ifdef S390 412 #define S390_ONLY(code) code 413 #define NOT_S390(code) 414 #else 415 #define S390_ONLY(code) 416 #define NOT_S390(code) code 417 #endif 418 419 #ifdef SPARC 420 #define SPARC_ONLY(code) code 421 #define NOT_SPARC(code) 422 #else 423 #define SPARC_ONLY(code) 424 #define NOT_SPARC(code) code 425 #endif 426 427 #if defined(PPC32) || defined(PPC64) 428 #ifndef PPC 429 #define PPC 430 #endif 431 #define PPC_ONLY(code) code 432 #define NOT_PPC(code) 433 #else 434 #undef PPC 435 #define PPC_ONLY(code) 436 #define NOT_PPC(code) code 437 #endif 438 439 #ifdef PPC32 440 #define PPC32_ONLY(code) code 441 #define NOT_PPC32(code) 442 #else 443 #define PPC32_ONLY(code) 444 #define NOT_PPC32(code) code 445 #endif 446 447 #ifdef PPC64 448 #define PPC64_ONLY(code) code 449 #define NOT_PPC64(code) 450 #else 451 #define PPC64_ONLY(code) 452 #define NOT_PPC64(code) code 453 #endif 454 455 #ifdef E500V2 456 #define E500V2_ONLY(code) code 457 #define NOT_E500V2(code) 458 #else 459 #define E500V2_ONLY(code) 460 #define NOT_E500V2(code) code 461 #endif 462 463 // Note: There are three ARM ports. They set the following in the makefiles: 464 // 1. Closed 32-bit port: -DARM -DARM32 -DTARGET_ARCH_arm 465 // 2. Closed 64-bit port: -DARM -DAARCH64 -D_LP64 -DTARGET_ARCH_arm 466 // 3. Open 64-bit port: -DAARCH64 -D_LP64 -DTARGET_ARCH_aaarch64 467 #ifdef ARM 468 #define ARM_ONLY(code) code 469 #define NOT_ARM(code) 470 #else 471 #define ARM_ONLY(code) 472 #define NOT_ARM(code) code 473 #endif 474 475 #ifdef ARM32 476 #define ARM32_ONLY(code) code 477 #define NOT_ARM32(code) 478 #else 479 #define ARM32_ONLY(code) 480 #define NOT_ARM32(code) code 481 #endif 482 483 #ifdef AARCH64 484 #define AARCH64_ONLY(code) code 485 #define NOT_AARCH64(code) 486 #else 487 #define AARCH64_ONLY(code) 488 #define NOT_AARCH64(code) code 489 #endif 490 491 #define define_pd_global(type, name, value) const type pd_##name = value; 492 493 // Helper macros for constructing file names for includes. 494 #define CPU_HEADER_STEM(basename) PASTE_TOKENS(basename, INCLUDE_SUFFIX_CPU) 495 #define OS_HEADER_STEM(basename) PASTE_TOKENS(basename, INCLUDE_SUFFIX_OS) 496 #define OS_CPU_HEADER_STEM(basename) PASTE_TOKENS(basename, PASTE_TOKENS(INCLUDE_SUFFIX_OS, INCLUDE_SUFFIX_CPU)) 497 498 // Include platform dependent files. 499 // 500 // This macro constructs from basename and INCLUDE_SUFFIX_OS / 501 // INCLUDE_SUFFIX_CPU, which are set on the command line, the name of 502 // platform dependent files to be included. 503 // Example: INCLUDE_SUFFIX_OS=_linux / INCLUDE_SUFFIX_CPU=_sparc 504 // CPU_HEADER_INLINE(macroAssembler) --> macroAssembler_sparc.inline.hpp 505 // OS_CPU_HEADER(vmStructs) --> vmStructs_linux_sparc.hpp 506 // 507 // basename<cpu>.hpp / basename<cpu>.inline.hpp 508 #define CPU_HEADER_H(basename) XSTR(CPU_HEADER_STEM(basename).h) 509 #define CPU_HEADER(basename) XSTR(CPU_HEADER_STEM(basename).hpp) 510 #define CPU_HEADER_INLINE(basename) XSTR(CPU_HEADER_STEM(basename).inline.hpp) 511 // basename<os>.hpp / basename<os>.inline.hpp 512 #define OS_HEADER_H(basename) XSTR(OS_HEADER_STEM(basename).h) 513 #define OS_HEADER(basename) XSTR(OS_HEADER_STEM(basename).hpp) 514 #define OS_HEADER_INLINE(basename) XSTR(OS_HEADER_STEM(basename).inline.hpp) 515 // basename<os><cpu>.hpp / basename<os><cpu>.inline.hpp 516 #define OS_CPU_HEADER(basename) XSTR(OS_CPU_HEADER_STEM(basename).hpp) 517 #define OS_CPU_HEADER_INLINE(basename) XSTR(OS_CPU_HEADER_STEM(basename).inline.hpp) 518 519 // To use Atomic::inc(jshort* dest) and Atomic::dec(jshort* dest), the address must be specially 520 // aligned, such that (*dest) occupies the upper 16 bits of an aligned 32-bit word. The best way to 521 // achieve is to place your short value next to another short value, which doesn't need atomic ops. 522 // 523 // Example 524 // ATOMIC_SHORT_PAIR( 525 // volatile short _refcount, // needs atomic operation 526 // unsigned short _length // number of UTF8 characters in the symbol (does not need atomic op) 527 // ); 528 529 #ifdef VM_LITTLE_ENDIAN 530 #define ATOMIC_SHORT_PAIR(atomic_decl, non_atomic_decl) \ 531 non_atomic_decl; \ 532 atomic_decl 533 #else 534 #define ATOMIC_SHORT_PAIR(atomic_decl, non_atomic_decl) \ 535 atomic_decl; \ 536 non_atomic_decl 537 #endif 538 539 #endif // SHARE_VM_UTILITIES_MACROS_HPP