Skip to content

Commit

Permalink
aarch64: make java-base and related modules compile
Browse files Browse the repository at this point in the history
This patch does more than what the title suggests and ideally
should be split in at least 2 parts. But it would require substantial
amount of work to untangle those and more importantly re-test at this point.

So firstly, this patch modifies makefiles and module.py files
of java related modules and others like golang that include
modules/java-base/common.gmk to make it possible to build
on aarch64 host. It achieves it mostly by including modules/common.gmk
which provides necessary rules for compiling on both x64 and aarch64 hosts
as well as cross-compiling aarch64 on x64 host. This also removes
a lot of repeated boiler plate and makes many changed makefiles
more consistent with each other. Finally all build artifacts
like object files are output to
./build/<release|debug>.[arch]/modules/[module] directories instead of
modules/[module].

Secondly, this patch also modifies the build process to dynamically
determine which jdk to use and which java tests to run. Therefore
new version of modules/java/module.py detects which version of java
(8 or 9 and above) is in the PATH and accordingly selects openjdk8-from-host
or openjdk9_1x-from-host. In addition, we also make java-tests
makefile generate list of java tests to be executed when test.py is run.
This is necessary because our java "wrapper" mechanism is no longer
compatible with Java 9 and above and we need to filter out java-isolated
and java-non-isolated tests. New version of test.py simply reads
list of java tests to be executed from modules/java-tests/test_commands,
generated during build time.

Signed-off-by: Waldemar Kozaczuk <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
wkozaczuk authored and nyh committed Jun 14, 2021
1 parent 615e456 commit 665a0ec
Show file tree
Hide file tree
Showing 27 changed files with 293 additions and 253 deletions.
43 changes: 19 additions & 24 deletions modules/cloud-init/Makefile
Original file line number Diff line number Diff line change
@@ -1,51 +1,46 @@
SRC = $(shell readlink -f ../..)
include $(SRC)/modules/java-base/common.gmk
include ../common.gmk

autodepend = -MD -MT $@ -MP
CXXFLAGS = -g -rdynamic -Wall -std=c++11 -fPIC $(INCLUDES) $(autodepend)
src = $(SRC)
arch = x64
module_out := $(out)/modules/cloud-init

CXXFLAGS = -g -rdynamic -Wall -std=c++11 -fPIC $(COMMON)

boost-libs := -lboost_system -lboost_filesystem

HTTPSERVER_API_DIR = ../../modules/httpserver-api
INCLUDES += -I$(HTTPSERVER_API_DIR)
HTTPSERVER_API_DIR = $(out)/modules/httpserver-api
INCLUDES += -I../httpserver-api

# the build target executable:
TARGET = cloud-init
CPP_FILES := client.cc cloud-init.cc data-source.cc main.cc template.cc cassandra-module.cc json.cc
OBJ_FILES := $(addprefix obj/,$(CPP_FILES:.cc=.o))
OBJ_FILES := $(addprefix $(module_out)/,$(CPP_FILES:.cc=.o))
DEPS := $(OBJ_FILES:.o=.d)

STUB_HTTPSERVER_LIBS = $(HTTPSERVER_API_DIR)/httpserver-stub.so
LIBS = -lpthread $(boost-libs) $(DEPEDNDS_LIBS) -lyaml-cpp -L$(HTTPSERVER_API_DIR)/ -lhttpserver-api

quiet = $(if $V, $1, @echo " $2"; $1)
very-quiet = $(if $V, $1, @$1)


module: all

all: init $(TARGET).so tst-template
all: init $(module_out)/$(TARGET).so $(module_out)/tst-template

init:
$(call very-quiet, mkdir -p obj)
$(call very-quiet, mkdir -p $(module_out))

tst-template: template.cc tst-template.cc
$(call quiet, $(CXX) -g -Wall -std=c++11 -o $@ $^ -lboost_unit_test_framework -DBOOST_TEST_DYN_LINK, LINK $@)
$(module_out)/tst-template: template.cc tst-template.cc
$(call quiet, $(CXX) -g -Wall -std=c++11 $(LDFLAGS) -o $@ $^ -lboost_unit_test_framework -DBOOST_TEST_DYN_LINK, LINK $@)

$(TARGET): $(OBJ_FILES)
$(call quiet, $(CXX) $(CXXFLAGS) -o $(TARGET) $^ $(LIBS) $(STUB_HTTPSERVER_LIBS), LINK $@)
$(module_out)/$(TARGET): $(OBJ_FILES)
$(call quiet, $(CXX) $(CXXFLAGS) $(LDFLAGS) $(module_out)/-o $(TARGET) $^ $(LIBS) $(STUB_HTTPSERVER_LIBS), LINK $@)

$(TARGET).so: $(OBJ_FILES)
$(call quiet, $(CXX) $(CXXFLAGS) $(STATIC_LIBS) -shared -o $(TARGET).so $^ $(LIBS), LINK $@)
$(module_out)/$(TARGET).so: $(OBJ_FILES)
$(call quiet, $(CXX) $(CXXFLAGS) $(LDFLAGS) $(STATIC_LIBS) -shared -o $(module_out)/$(TARGET).so $^ $(LIBS), LINK $@)
echo '/usr/mgmt/cloud-init.so: ./modules/cloud-init/cloud-init.so' > usr.manifest

obj/%.o: %.cc
$(module_out)/%.o: %.cc
$(call quiet, $(CXX) $(CXXFLAGS) -c -o $@ $<, CXX $@)

clean:
$(call quiet, $(RM) -f $(TARGET).so tst-template, CLEAN)
$(call very-quiet, $(RM) -rf obj)
$(call quiet, $(RM) -f $(module_out)/$(TARGET).so $(module_out)/tst-template, CLEAN)
$(call very-quiet, $(RM) -rf $(module_out))

ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
Expand Down
1 change: 0 additions & 1 deletion modules/cloud-init/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
_module = '${OSV_BASE}/modules/cloud-init'

usr_files = FileMap()
usr_files.add(os.path.join(_module, 'cloud-init.so')).to('/usr/mgmt/cloud-init.so')
usr_files.add(os.path.join(_module, 'cloud-init.yaml')).to('/usr/mgmt/cloud-init.yaml')
usr_files.add(os.path.join(_module, 'cmdline')).to('/init/00-cmdline')

Expand Down
27 changes: 12 additions & 15 deletions modules/golang/Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
SRC = $(shell readlink -f ../..)
include $(SRC)/modules/java-base/common.gmk
include ../common.gmk

autodepend = -MD -MT $@ -MP
CXXFLAGS = -g -rdynamic -Wall -std=c++11 -fPIC $(INCLUDES) $(autodepend)
module_out := $(out)/modules/golang

CXXFLAGS = -g -rdynamic -Wall -std=c++11 -fPIC $(COMMON)

# the build target executable:
TARGET = go
CPP_FILES := $(TARGET).cc
OBJ_FILES := $(addprefix obj/,$(CPP_FILES:.cc=.o))
OBJ_FILES := $(addprefix $(module_out)/,$(CPP_FILES:.cc=.o))
DEPS := $(OBJ_FILES:.o=.d)

quiet = $(if $V, $1, @echo " $2"; $1)
very-quiet = $(if $V, $1, @$1)

$(TARGET).so: $(OBJ_FILES)
$(call quiet, $(CXX) $(CXXFLAGS) -shared -o $(TARGET).so $^ $(LIBS), LINK $@)
$(module_out)/$(TARGET).so: $(OBJ_FILES)
$(call quiet, $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $(module_out)/$(TARGET).so $^ $(LIBS), LINK $@)

obj/%.o: %.cc
$(module_out)/%.o: %.cc
$(call quiet, $(CXX) $(CXXFLAGS) -c -o $@ $<, CXX $@)

init:
@echo " MKDIRS"
$(call very-quiet, mkdir -p obj)
$(call very-quiet, mkdir -p $(module_out))
.PHONY: init

module: init $(TARGET).so
echo '/go.so: $${MODULE_DIR}/go.so' > usr.manifest
module: init $(module_out)/$(TARGET).so
echo '/go.so: ./modules/golang/go.so' > usr.manifest

clean:
rm -f $(TARGET)*.so usr.manifest
$(call very-quiet, $(RM) -rf obj)
$(call very-quiet, $(RM) -rf $(module_out))
1 change: 1 addition & 0 deletions modules/httpserver-jolokia-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr.manifest
67 changes: 20 additions & 47 deletions modules/httpserver-jolokia-plugin/Makefile
Original file line number Diff line number Diff line change
@@ -1,75 +1,48 @@
SRC = $(shell readlink -f ../..)
include $(SRC)/modules/java-base/common.gmk
include ../common.gmk

module_out := $(out)/modules/httpserver-jolokia-plugin
INCLUDES += -I. -I../httpserver-api

jdkbase = $(dir $(shell readlink -f $$(which javac)))/..
INCLUDES += -I$(jdkbase)/include -I$(jdkbase)/include/linux

# compiler flags:
# -g adds debugging information to the executable file
# -Wall turns on most, but not all, compiler warnings
autodepend = -MD -MT $@ -MP
CXXFLAGS = -g -Wall -std=c++11 -fPIC $(INCLUDES) -O2 $(autodepend)
src = $(shell readlink -f ../..)
CXXFLAGS = -g -Wall -std=c++11 -fPIC $(COMMON) -O2

CODE_GEN_FROM_JSON := ../httpserver-api/json2code.py
RM := /bin/rm

ifndef ARCH
ARCH = x64
endif

ifndef mode
mode = release
endif

ifndef OSV_BUILD_PATH
OSV_BUILD_PATH = $(src)/build/$(mode).$(ARCH)
endif

# the build target executable:
TARGET = jolokia
JSON_FILES := $(wildcard api-doc/listings/*.json)
JSON_CC_FILES := $(subst .json,.json.cc,$(subst api-doc/listings/,autogen/,$(JSON_FILES)))
CPP_FILES := $(JSON_CC_FILES) $(wildcard *.cc)
OBJ_FILES := $(addprefix obj/,$(CPP_FILES:.cc=.o))

# link with -mt if present, else the base version (and hope it is multithreaded)
boost-mt := -mt
boost-lib-dir := $(dir $(shell $(CC) --print-file-name libboost_system$(boost-mt).a))
ifeq ($(filter /%,$(boost-lib-dir)),)
boost-mt :=
boost-lib-dir := $(dir $(shell $(CC) --print-file-name libboost_system$(boost-mt).a))
ifeq ($(filter /%,$(boost-lib-dir)),)
$(error Error: libboost_system.a needs to be installed.)
endif
endif

STATIC_LIBS = $(boost-lib-dir)/libboost_program_options$(boost-mt).a
DYN_LIBS = -lpthread -ldl -L$(libs-dir) -lyaml-cpp $(boost-libs)
OBJ_FILES := $(addprefix $(module_out)/,$(CPP_FILES:.cc=.o))

DYN_LIBS = -lpthread -ldl -lyaml-cpp
DYN_LIBS += -lssl -lcrypto

LIBS = $(DYN_LIBS) $(STATIC_LIBS)

quiet = $(if $V, $1, @echo " $2"; $1)
very-quiet = $(if $V, $1, @$1)

DEPS := $(OBJ_FILES:.o=.d)

module: all
echo '/usr/mgmt/plugins/jolokia.so: ./modules/httpserver-jolokia-plugin/jolokia.so' > usr.manifest

all: $(TARGET).so
all: $(module_out)/$(TARGET).so
cd jolokia-agent && mvn -q package -DskipTests=true

init:
@echo " MKDIRS"
$(call very-quiet, mkdir -p obj)
$(call very-quiet, mkdir -p obj/json)
$(call very-quiet, mkdir -p obj/api)
$(call very-quiet, mkdir -p obj/autogen)
$(call very-quiet, mkdir -p $(module_out)/json)
$(call very-quiet, mkdir -p $(module_out)/api)
$(call very-quiet, mkdir -p $(module_out)/autogen)
$(call very-quiet, mkdir -p autogen)
.PHONY: init

$(TARGET).so: $(OBJ_FILES)
$(call quiet, $(CXX) $(CXXFLAGS) -shared $(STATIC_LIBS) -o $@ $^ $(DYN_LIBS), LINK $@)
$(module_out)/$(TARGET).so: $(OBJ_FILES)
$(call quiet, $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(STATIC_LIBS) -o $@ $^ $(DYN_LIBS), LINK $@)

ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
Expand All @@ -78,17 +51,17 @@ endif
autogen/%.cc: api-doc/listings/% $(CODE_GEN_FROM_JSON) | init
$(call quiet,./$(CODE_GEN_FROM_JSON) -f $< -ns json, GEN $@)

obj/%.o: %.cc | init
$(module_out)/%.o: %.cc | init
$(call quiet, $(CXX) $(CXXFLAGS) -c -MMD -o $@ $<, CXX $@)

# jolokia.cc depends on autogen/jolokia.json.hh, which needs to be
# auto-generated before jolokia.cc is compiled
obj/jolokia.o: autogen/jolokia.json.cc
$(module_out)/jolokia.o: autogen/jolokia.json.cc

clean:
$(call quiet, $(RM) -f $(TARGET).so, CLEAN)
$(call quiet, $(RM) -f $(module_out)/$(TARGET).so, CLEAN)
$(call very-quiet, $(RM) -f usr.manifest)
$(call very-quiet, $(RM) -rf obj)
$(call very-quiet, $(RM) -rf $(module_out))
$(call very-quiet, $(RM) -rf autogen)
cd jolokia-agent && mvn -q clean
-rm -f dependency-reduced-pom.xml
1 change: 0 additions & 1 deletion modules/httpserver-jolokia-plugin/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
_module = '${OSV_BASE}/modules/httpserver-jolokia-plugin'

usr_files = FileMap()
usr_files.add(os.path.join(_module, 'jolokia.so')).to('/usr/mgmt/plugins/jolokia.so')
usr_files.add(os.path.join(_module, 'api-doc/listings/jolokia.json')).to('/usr/mgmt/api/listings/jolokia.json')
usr_files.add(os.path.join(_module, 'jolokia-agent/target/jolokia-agent.jar')).to('/usr/mgmt/jolokia-agent.jar')
19 changes: 10 additions & 9 deletions modules/java-base/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
include ../common.gmk

module_out := $(out)/modules/java-base
export module_out

include common.gmk

ifeq ($(arch),aarch64)
java-targets :=
else
java-targets := obj/jni/monitor.so obj/jvm/jni_helpers.o obj/jvm/java_api.o obj/balloon/jvm_balloon.o
endif
java-targets := $(module_out)/jni/monitor.so $(module_out)/jvm/jni_helpers.o $(module_out)/jvm/java_api.o $(module_out)/balloon/jvm_balloon.o

module: all

all: $(init) $(java-targets)

init:
@echo " MKDIRS"
$(call very-quiet, mkdir -p obj/jni)
$(call very-quiet, mkdir -p obj/jvm)
$(call very-quiet, mkdir -p obj/balloon)
$(call very-quiet, mkdir -p $(module_out)/jni)
$(call very-quiet, mkdir -p $(module_out)/jvm)
$(call very-quiet, mkdir -p $(module_out)/balloon)
.PHONY: init

clean:
$(call very-quiet, $(RM) -rf obj)
$(call very-quiet, $(RM) -rf $(module_out))
38 changes: 11 additions & 27 deletions modules/java-base/common.gmk
Original file line number Diff line number Diff line change
@@ -1,45 +1,29 @@
jdkbase = $(dir $(shell readlink -f $$(which javac)))/..

INCLUDES = -I$(src)/arch/$(arch) -I$(src) -I$(src)/include -I$(src)/arch/common
INCLUDES += -I$(src)/include/glibc-compat
INCLUDES += $(shell $(CXX) -E -xc++ - -v </dev/null 2>&1 | awk '/^End/ {exit} /^ .*c\+\+/ {print "-isystem" $$0}')
INCLUDES += -isystem $(src)/include/api
INCLUDES += -isystem $(src)/include/api/$(arch)
INCLUDES += -I$(src)/build/$(mode)/gen/include
INCLUDES += -I$(src)/java
INCLUDES += -I$(jdkbase)/include -I$(jdkbase)/include/linux

autodepend = -MD -MT $@ -MP
COMMON_FLAGS = -g -Wall -fPIC $(INCLUDES) -O2 $(autodepend) -DCONF_debug_memory=0 -D_KERNEL
CXXFLAGS = -std=c++11 $(COMMON_FLAGS)
CFLAGS = -std=gnu99 $(COMMON_FLAGS)
COMMON += -g -Wall -fPIC -O2 -DCONF_debug_memory=0 -D_KERNEL

src = $(shell readlink -f ../..)
java-base-path := $(src)/modules/java-base

RM := /bin/rm
CXXFLAGS = -std=c++11 $(COMMON)
CFLAGS = -std=gnu99 $(COMMON)

ifndef arch
arch = x64
endif
java-base-path := $(src)/modules/java-base

ifndef mode
mode = release
endif
javac_exe_path = $(shell realpath $$(which javac))
javac_bin_path = $(shell dirname $(javac_exe_path))
java_jdk_path = $(shell dirname $(javac_bin_path))

configuration-defines = conf-preempt conf-debug_memory conf-logger_debug

configuration = $(foreach cf,$(configuration-defines), \
-D$(cf:conf-%=CONF_%)=$($(cf)))

quiet = $(if $V, $1, @echo " $2"; $1)
very-quiet = $(if $V, $1, @$1)

obj/%.o: %.cc | init
$(module_out)/%.o: %.cc | init
$(call quiet, $(CXX) $(CXXFLAGS) -c -MMD -o $@ $<, CXX $@)

obj/%.o: %.c | init
$(module_out)/%.o: %.c | init
$(call quiet, $(CC) $(CFLAGS) -c -MMD -o $@ $<, CC $@)

%.so: %.o
$(call quiet, $(CXX) $(CXXFLAGS) -shared -o $@ $^, LINK $@)
$(module_out)/%.so: %.o | init
$(call quiet, $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $^, LINK $@)
4 changes: 4 additions & 0 deletions modules/java-base/java.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ extern size_t jvm_heap_size;
// sets up the class path, and runs the jar or class specified in these
// parameters.

#ifdef __aarch64__
#define JVM_PATH "/usr/lib/jvm/jre/lib/aarch64/server/libjvm.so"
#else
#define JVM_PATH "/usr/lib/jvm/jre/lib/amd64/server/libjvm.so"
#endif
#define JVM9_PATH "/usr/lib/jvm/java/lib/server/libjvm.so"

#if defined(RUN_JAVA_NON_ISOLATED)
Expand Down
2 changes: 1 addition & 1 deletion modules/java-base/usr.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#

[manifest]
/usr/lib/jni/monitor.so: ${MODULE_DIR}/obj/jni/monitor.so
/usr/lib/jni/monitor.so: ./modules/java-base/jni/monitor.so
Loading

0 comments on commit 665a0ec

Please sign in to comment.