Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/CMakeLists.txt
5986 views
1
################################################################################
2
# Copyright (c) 2017, 2022 IBM Corp. and others
3
#
4
# This program and the accompanying materials are made available under
5
# the terms of the Eclipse Public License 2.0 which accompanies this
6
# distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
# or the Apache License, Version 2.0 which accompanies this distribution and
8
# is available at https://www.apache.org/licenses/LICENSE-2.0.
9
#
10
# This Source Code may also be made available under the following
11
# Secondary Licenses when the conditions for such availability set
12
# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
# General Public License, version 2 with the GNU Classpath
14
# Exception [1] and GNU General Public License, version 2 with the
15
# OpenJDK Assembly Exception [2].
16
#
17
# [1] https://www.gnu.org/software/classpath/license.html
18
# [2] http://openjdk.java.net/legal/assembly-exception.html
19
#
20
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
################################################################################
22
23
include(CheckCXXCompilerFlag)
24
# This CMakeLists is included by the VM CMake lists, and works after composition
25
# has occurred.
26
#
27
# Relies on a few pieces of OMR, and a few pieces of the VM CMakeLists.
28
#
29
# Longer term, this will of course have to collapse into the VM builds.
30
31
if(OMR_ARCH_X86)
32
# On Windows, the proper binary format is not auto detected.
33
if(OMR_OS_WINDOWS)
34
if(OMR_ENV_DATA64)
35
set(CMAKE_ASM_NASM_OBJECT_FORMAT win64)
36
else()
37
set(CMAKE_ASM_NASM_OBJECT_FORMAT win32)
38
endif()
39
endif()
40
enable_language(ASM_NASM)
41
# We have to manually append "/" to the paths as NASM versions older than v2.14 requires trailing / in the directory paths.
42
set(asm_inc_dirs
43
"-I${j9vm_SOURCE_DIR}/oti/"
44
"-I${j9vm_BINARY_DIR}/oti/"
45
"-I${CMAKE_CURRENT_SOURCE_DIR}/"
46
"-I${CMAKE_CURRENT_SOURCE_DIR}/x/runtime/"
47
"-I${CMAKE_CURRENT_SOURCE_DIR}/x/amd64/runtime/"
48
"-I${CMAKE_CURRENT_SOURCE_DIR}/x/i386/runtime/"
49
)
50
omr_append_flags(CMAKE_ASM_NASM_FLAGS ${asm_inc_dirs})
51
# For whatever reason cmake does not apply compile definitions when building nasm objects.
52
# The if guard is here in case they ever start doing so.
53
if(NOT CMAKE_ASM_NASM_COMPILE_OBJECT MATCHES "<DEFINES>")
54
# Tack on defines immediately following the compiler name.
55
string(REPLACE
56
"<CMAKE_ASM_NASM_COMPILER>"
57
"<CMAKE_ASM_NASM_COMPILER> <DEFINES>"
58
CMAKE_ASM_NASM_COMPILE_OBJECT
59
"${CMAKE_ASM_NASM_COMPILE_OBJECT}"
60
)
61
endif()
62
endif()
63
64
# Using the linker option -static-libgcc results in an error on OSX. The option -static-libstdc++ is unused.
65
# Therefore these options have been excluded from OSX.
66
if((OMR_TOOLCONFIG STREQUAL "gnu") AND (NOT OMR_OS_OSX))
67
check_cxx_compiler_flag("-static-libstdc++" ALLOWS_STATIC_LIBCPP)
68
endif()
69
70
# This target is created so that various subdirectories can add dependencies to it.
71
# The j9jit target will then depend on it, propagating the dependencies.
72
# This is required because at the time we include the subdirectories, the j9jit target
73
# does not yet exist (and as such can't have dependencies addded to it).
74
add_custom_target(j9jit_generate)
75
76
# On Windows, exceptions are controlled via the preprocessor define _HAS_EXCEPTIONS.
77
# We need to enable it again, after OMR platform config removed it.
78
get_directory_property(compile_defs COMPILE_DEFINITIONS)
79
list(REMOVE_ITEM compile_defs "_HAS_EXCEPTIONS=0")
80
set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS ${compile_defs})
81
82
omr_add_tracegen(env/j9jit.tdf)
83
84
# this is a workaround because the JIT code includes the tracegen header as <env/ut_j9jit.h>
85
add_custom_command(
86
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/env/ut_j9jit.h
87
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ut_j9jit.h
88
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/ut_j9jit.h" "${CMAKE_CURRENT_BINARY_DIR}/env/ut_j9jit.h"
89
VERBATIM
90
)
91
92
add_custom_target(j9jit_tracegen DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/env/ut_j9jit.h)
93
94
# J9VM_OPT_JITSERVER
95
if(J9VM_OPT_JITSERVER)
96
message(STATUS "JITServer is enabled")
97
98
if(OPENSSL_BUNDLE_LIB_PATH) # --enable-openssl-bundling
99
set(OPENSSL_ROOT_DIR ${OPENSSL_BUNDLE_LIB_PATH})
100
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,$ORIGIN/..")
101
elseif(OPENSSL_DIR) # --with-openssl=fetched only
102
set(OPENSSL_ROOT_DIR ${OPENSSL_DIR})
103
endif()
104
105
find_package(OpenSSL REQUIRED)
106
include_directories(${OPENSSL_INCLUDE_DIR})
107
endif()
108
109
# TODO We should get rid of this, but it's still required by the compiler_support module in OMR.
110
set(J9SRC ${j9vm_SOURCE_DIR})
111
112
# include compiler support module from OMR
113
include(OmrCompilerSupport)
114
115
# Override masm2gas with J9JIT version until we've
116
# resolved the divergence.
117
set(masm2gas_path build/scripts/masm2gas.pl )
118
get_filename_component(masm2gas_path ${masm2gas_path} ABSOLUTE)
119
set(MASM2GAS_PATH ${masm2gas_path} CACHE INTERNAL "MASM2GAS PATH")
120
121
# The list of files that are added to the compiler in addition
122
# To the defaults provided by create_omr_compiler_library
123
set(J9JIT_FILES "" CACHE INTERNAL "The computed list of j9jit files")
124
125
# Used inside added subdirectories to help
126
# fill in the object list
127
macro(j9jit_files)
128
set(J9JIT_FILES ${J9JIT_FILES} ${ARGN} CACHE INTERNAL "The computed list of j9jit files")
129
endmacro(j9jit_files)
130
131
j9jit_files(${CMAKE_CURRENT_BINARY_DIR}/ut_j9jit.c)
132
133
# Add our subdirectories.
134
add_subdirectory(codegen)
135
add_subdirectory(compile)
136
add_subdirectory(control)
137
add_subdirectory(env)
138
add_subdirectory(il)
139
add_subdirectory(ilgen)
140
add_subdirectory(infra)
141
add_subdirectory(optimizer)
142
add_subdirectory(ras)
143
add_subdirectory(runtime)
144
145
if(J9VM_OPT_JITSERVER)
146
add_subdirectory(net)
147
endif()
148
149
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${TR_HOST_ARCH}")
150
add_subdirectory(${TR_HOST_ARCH})
151
endif()
152
153
if(NOT TR_TARGET_ARCH STREQUAL TR_HOST_ARCH AND IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${TR_TARGET_ARCH}")
154
add_subdirectory(${TR_TARGET_ARCH})
155
endif()
156
157
# Some files in OMR provide duplicate or extra functionality not needed
158
# in J9, so we need to remove them.
159
set(REMOVED_OMR_FILES
160
${omr_SOURCE_DIR}/compiler/codegen/CCData.cpp
161
${omr_SOURCE_DIR}/compiler/control/CompileMethod.cpp
162
${omr_SOURCE_DIR}/compiler/control/CompilationController.cpp
163
${omr_SOURCE_DIR}/compiler/env/FEBase.cpp
164
${omr_SOURCE_DIR}/compiler/optimizer/FEInliner.cpp
165
${omr_SOURCE_DIR}/compiler/env/JitConfig.cpp
166
${omr_SOURCE_DIR}/compiler/env/PersistentAllocator.cpp
167
${omr_SOURCE_DIR}/compiler/env/SystemSegmentProvider.cpp
168
${omr_SOURCE_DIR}/compiler/infra/OMRMonitor.cpp
169
${omr_SOURCE_DIR}/compiler/runtime/Trampoline.cpp
170
${omr_SOURCE_DIR}/compiler/runtime/Runtime.cpp
171
${omr_SOURCE_DIR}/compiler/ilgen/IlInjector.cpp
172
${omr_SOURCE_DIR}/compiler/ilgen/OMRBytecodeBuilder.cpp
173
${omr_SOURCE_DIR}/compiler/ilgen/OMRIlBuilder.cpp
174
${omr_SOURCE_DIR}/compiler/ilgen/OMRIlType.cpp
175
${omr_SOURCE_DIR}/compiler/ilgen/OMRIlValue.cpp
176
${omr_SOURCE_DIR}/compiler/ilgen/OMRJitBuilderRecorder.cpp
177
${omr_SOURCE_DIR}/compiler/ilgen/OMRJitBuilderRecorderBinaryBuffer.cpp
178
${omr_SOURCE_DIR}/compiler/ilgen/OMRJitBuilderRecorderBinaryFile.cpp
179
${omr_SOURCE_DIR}/compiler/ilgen/OMRJitBuilderRecorderTextFile.cpp
180
${omr_SOURCE_DIR}/compiler/ilgen/OMRMethodBuilder.cpp
181
${omr_SOURCE_DIR}/compiler/ilgen/OMRThunkBuilder.cpp
182
${omr_SOURCE_DIR}/compiler/ilgen/OMRTypeDictionary.cpp
183
${omr_SOURCE_DIR}/compiler/ilgen/OMRVirtualMachineOperandArray.cpp
184
${omr_SOURCE_DIR}/compiler/ilgen/OMRVirtualMachineOperandStack.cpp
185
${omr_SOURCE_DIR}/compiler/ilgen/OMRVirtualMachineRegister.cpp
186
${omr_SOURCE_DIR}/compiler/ilgen/OMRVirtualMachineRegisterInStruct.cpp
187
${omr_SOURCE_DIR}/compiler/ilgen/OMRVirtualMachineState.cpp
188
)
189
190
get_target_property(compiler_defines j9vm_compiler_defines INTERFACE_COMPILE_DEFINITIONS)
191
# Extra defines not provided by the create_omr_compiler_library call.
192
set(TARGET_DEFINES
193
J9_PROJECT_SPECIFIC
194
${compiler_defines}
195
)
196
197
# When VM is built with CMake, we should just use the
198
# INTERFACE specification of target_link_libraries,
199
# though that would also involve teaching MASM2GAS and
200
# PASM2ASM about target includes.
201
#
202
# In the meantime, like the makefiles, this is using
203
# the includes from the SDK.
204
set(J9_INCLUDES
205
# From jitinclude.mk
206
${omr_SOURCE_DIR}/thread
207
${omr_SOURCE_DIR}/gc/include
208
# endjitinclude.mk
209
../ # Frustratingly there are some #include "frob/baz.hpp" references in the compiler which require this.
210
${j9vm_SOURCE_DIR}/codert_vm
211
${j9vm_SOURCE_DIR}/gc_include
212
${j9vm_SOURCE_DIR}/gc_glue_java
213
${j9vm_SOURCE_DIR}/jit_vm
214
${j9vm_SOURCE_DIR}/nls
215
${j9vm_SOURCE_DIR}/oti
216
${j9vm_SOURCE_DIR}/include
217
${j9vm_SOURCE_DIR}/util
218
${j9vm_BINARY_DIR}
219
${j9vm_BINARY_DIR}/oti
220
${omr_BINARY_DIR}
221
${CMAKE_CURRENT_BINARY_DIR}
222
)
223
224
# Platform-specific lists of flags, derived directly from the makefiles.
225
set(J9_SHAREDFLAGS
226
${OMR_PLATFORM_COMPILE_OPTIONS}
227
)
228
set(J9_CFLAGS
229
${OMR_PLATFORM_C_COMPILE_OPTIONS}
230
)
231
set(J9_CXXFLAGS
232
${OMR_PLATFORM_CXX_COMPILE_OPTIONS}
233
)
234
235
if(OMR_OS_LINUX OR OMR_OS_OSX)
236
list(APPEND J9_SHAREDFLAGS
237
-fno-strict-aliasing
238
-Wno-deprecated
239
-Wno-enum-compare
240
-Wno-write-strings
241
-fomit-frame-pointer
242
-fasynchronous-unwind-tables
243
-Wreturn-type
244
-pthread
245
)
246
247
# Platform-specific CXX flags, also derived from the makefiles.
248
list(APPEND J9_CXXFLAGS
249
-fno-threadsafe-statics
250
-Wno-invalid-offsetof
251
)
252
if(NOT J9VM_OPT_JITSERVER)
253
list(APPEND J9_CXXFLAGS -fno-rtti)
254
endif()
255
256
list(APPEND J9_CFLAGS -std=gnu89)
257
elseif(OMR_OS_WINDOWS)
258
list(APPEND J9_SHAREDFLAGS
259
-D_WIN32
260
-DWIN32
261
-DSUPPORTS_THREAD_LOCAL
262
-DWINDOWS
263
)
264
elseif(OMR_OS_AIX)
265
list(APPEND J9_SHAREDFLAGS
266
-DAIXPPC
267
-DRS6000
268
-D_XOPEN_SOURCE_EXTENDED=1
269
-D_ALL_SOURCE
270
-DSUPPORTS_THREAD_LOCAL
271
)
272
if(OMR_ENV_DATA64)
273
list(APPEND J9_SHAREDFLAGS -q64)
274
if(OMR_TOOLCONFIG STREQUAL "xlc")
275
# Modify the arch tuning value we inherit from OMR.
276
list(REMOVE_ITEM TR_COMPILE_OPTIONS "-qarch=pwr7")
277
list(APPEND TR_COMPILE_OPTIONS "-qarch=ppc64grsq")
278
279
if(CMAKE_C_COMPILER_IS_XLCLANG)
280
# xlclang/xlclang++ options
281
list(APPEND SPP_FLAGS -qlanglvl=extc99)
282
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lc++")
283
endif()
284
endif()
285
else()
286
list(APPEND J9_SHAREDFLAGS -q32)
287
endif()
288
elseif(OMR_OS_ZOS)
289
list(APPEND TARGET_DEFINES
290
J9VM_TIERED_CODE_CACHE
291
MAXMOVE
292
)
293
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/usr/lpp/hzc/lib")
294
else()
295
message(SEND_ERROR "unsupported platform")
296
endif()
297
298
if(OMR_ARCH_S390)
299
list(APPEND TARGET_DEFINES COMPRESS_AOT_DATA)
300
endif()
301
302
# Add optional user-specified compiler flags that only apply to the JIT.
303
list(APPEND J9_CFLAGS ${J9JIT_EXTRA_CFLAGS})
304
list(APPEND J9_CXXFLAGS ${J9JIT_EXTRA_CXXFLAGS})
305
306
# Note: J9_CFLAGS and J9_CXXFLAGS are appended after J9_SHAREDFLAGS so that
307
# OMR_PLATFORM_C_COMPILE_OPTIONS and OMR_PLATFORM_CXX_COMPILE_OPTIONS
308
# end up after OMR_PLATFORM_COMPILE_OPTIONS, which matches the rest
309
# of the VM build (see cmake/modules/OmrPlatform.cmake in OMR).
310
# This allows the user to pass extra compiler options via
311
# OMR_PLATFORM_C_COMPILE_OPTIONS and OMR_PLATFORM_CXX_COMPILE_OPTIONS
312
# to override the defaults specified by OMR_PLATFORM_COMPILE_OPTIONS,
313
# e.g. in order to produce a debug build.
314
omr_stringify(J9_CFLAGS_STR ${J9_SHAREDFLAGS} ${J9_CFLAGS})
315
omr_stringify(J9_CXXFLAGS_STR ${J9_SHAREDFLAGS} ${J9_CXXFLAGS})
316
317
# Note: This is explicitly overriding what's provided by
318
# the VM CMakeLists, as they pass -fno-exceptions
319
# right now, and the JIT needs exceptions.
320
set(CMAKE_CXX_FLAGS "${J9_CXXFLAGS_STR}")
321
set(CMAKE_C_FLAGS "${J9_CFLAGS_STR}")
322
323
if(OMR_ARCH_X86 OR OMR_ARCH_S390)
324
set(OMR_WARNINGS_AS_ERRORS ON)
325
set(OMR_ENHANCED_WARNINGS OFF)
326
else()
327
set(OMR_WARNINGS_AS_ERRORS OFF)
328
set(OMR_ENHANCED_WARNINGS OFF)
329
endif()
330
331
create_omr_compiler_library(NAME j9jit
332
SHARED
333
OUTPUT_NAME j9jit${J9VM_VERSION_SUFFIX}
334
OBJECTS ${J9_FILES} ${J9JIT_FILES} ${NOT_EXFRRED}
335
DEFINES J9_PROJECT_SPECIFIC ${TARGET_DEFINES}
336
INCLUDES ${J9_INCLUDES}
337
FILTER ${REMOVED_OMR_FILES}
338
)
339
340
if(OMR_OS_ZOS)
341
# Workaround a compile problem on z/OS by appending "-O" (to override "-O3").
342
set_property(SOURCE "optimizer/VectorAPIExpansion.cpp" APPEND PROPERTY COMPILE_FLAGS "-O")
343
endif()
344
345
add_dependencies(j9jit
346
omrgc_hookgen
347
j9jit_tracegen
348
j9jit_generate
349
)
350
351
target_link_libraries(j9jit
352
PRIVATE
353
j9vm_interface
354
j9avl
355
j9codert_vm
356
j9hashtable
357
j9jit_vm
358
j9pool
359
j9stackmap
360
j9util
361
j9utilcore
362
j9hookable
363
j9thr
364
${CMAKE_DL_LIBS}
365
)
366
367
# This is a bit hokey, but cmake can't track the fact that files are generated across directories.
368
# Note: while these are only needed on Z, setting the properties unconditionally has no ill-effect.
369
set_source_files_properties(
370
${CMAKE_CURRENT_BINARY_DIR}/z/runtime/Math.s
371
${CMAKE_CURRENT_BINARY_DIR}/z/runtime/PicBuilder.s
372
${CMAKE_CURRENT_BINARY_DIR}/z/runtime/Recompilation.s
373
${CMAKE_CURRENT_BINARY_DIR}/z/runtime/ValueProf.s
374
PROPERTIES
375
GENERATED TRUE
376
)
377
378
if(OMR_OS_LINUX)
379
set_property(TARGET j9jit APPEND_STRING PROPERTY
380
LINK_FLAGS " -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/build/scripts/j9jit.linux.exp")
381
target_link_libraries(j9jit PRIVATE m)
382
elseif(OMR_OS_WINDOWS)
383
target_sources(j9jit PRIVATE build/scripts/j9jit.def)
384
elseif(OMR_OS_AIX)
385
set_property(TARGET j9jit APPEND_STRING PROPERTY
386
LINK_FLAGS " -Wl,-bE:${CMAKE_CURRENT_SOURCE_DIR}/build/scripts/j9jit.aix.exp")
387
endif()
388
389
if((OMR_TOOLCONFIG STREQUAL "gnu") AND ALLOWS_STATIC_LIBCPP)
390
# We assume that if the compiler allows -static-libstdc++
391
# it will also allow -static-libgcc.
392
set_property(TARGET j9jit APPEND_STRING PROPERTY
393
LINK_FLAGS " -static-libgcc -static-libstdc++")
394
endif()
395
396
if(OMR_ARCH_S390)
397
if(OMR_OS_ZOS)
398
target_include_directories(j9jit BEFORE PRIVATE /usr/lpp/hzc/include)
399
target_link_libraries(j9jit PRIVATE zz)
400
else()
401
target_link_libraries(j9jit PRIVATE j9zlib)
402
endif()
403
endif()
404
405
set_property(TARGET j9jit PROPERTY LINKER_LANGUAGE CXX)
406
407
# Note: ddrgen can't handle the templates used in the JIT.
408
target_enable_ddr(j9jit NO_DEBUG_INFO)
409
410
file(GLOB_RECURSE headers
411
${CMAKE_CURRENT_SOURCE_DIR}/runtime/*.h
412
${CMAKE_CURRENT_SOURCE_DIR}/runtime/*.hpp
413
)
414
415
ddr_add_headers(j9jit
416
${headers}
417
)
418
419
ddr_set_add_targets(omrddr j9jit)
420
421
if(OMR_OS_ZOS)
422
# Make sure that -Wc,EXPORTALL is applied.
423
omr_process_exports(j9jit)
424
endif()
425
426
install(
427
TARGETS j9jit
428
LIBRARY DESTINATION ${j9vm_SOURCE_DIR}
429
RUNTIME DESTINATION ${j9vm_SOURCE_DIR}
430
)
431
432