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