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