Skip to content

Commit

Permalink
Update build files for java8 build (facebook#9541)
Browse files Browse the repository at this point in the history
Summary:
For RocksJava 7 we will move from requiring Java 7 to Java 8.

* This simplifies the `Makefile` as we no longer need to deal with Java 7; so we no longer use `javah`.
* Added a java-version target which is invoked by the java target, and which exits if the version of java being used is not 8 or greater.
* Enforces java 8 as a minimum.
* Fixed CMake build.

* Fixed broken java event listener test, as the test was broken and the assertions in the callbacks were not causing assertions in the tests. The callbacks now queue up assertion errors for the main thread of the tests to check.
* Fixed C++ dangling pointers in the test code.

Pull Request resolved: facebook#9541

Reviewed By: pdillinger

Differential Revision: D34214929

Pulled By: jay-zhuang

fbshipit-source-id: fdff348758d0a23a742e83c87d5f54073ce16ca6
  • Loading branch information
alanpaxton authored and facebook-github-bot committed Feb 17, 2022
1 parent 5e64407 commit 36ce2e2
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 241 deletions.
2 changes: 1 addition & 1 deletion build_tools/build_detect_platform
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ esac
PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS ${CXXFLAGS}"
JAVA_LDFLAGS="$PLATFORM_LDFLAGS"
JAVA_STATIC_LDFLAGS="$PLATFORM_LDFLAGS"
JAVAC_ARGS="-source 7"
JAVAC_ARGS="-source 8"

if [ "$CROSS_COMPILE" = "true" -o "$FBCODE_BUILD" = "true" ]; then
# Cross-compiling; do not try any compilation tests.
Expand Down
16 changes: 10 additions & 6 deletions java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,17 @@ set(JAVA_TESTCLASSPATH ${JAVA_JUNIT_JAR} ${JAVA_HAMCR_JAR} ${JAVA_MOCKITO_JAR} $
set(JNI_OUTPUT_DIR ${PROJECT_SOURCE_DIR}/java/include)
file(MAKE_DIRECTORY ${JNI_OUTPUT_DIR})

if(${Java_VERSION_MINOR} VERSION_LESS_EQUAL "7" AND ${Java_VERSION_MAJOR} STREQUAL "1")
message(FATAL_ERROR "Detected Java 7 or older (${Java_VERSION_STRING}), minimum required version in now Java 8")
endif()

if(${Java_VERSION_MAJOR} VERSION_GREATER_EQUAL "10" AND ${CMAKE_VERSION} VERSION_LESS "3.11.4")
# Java 10 and newer don't have javah, but the alternative GENERATE_NATIVE_HEADERS requires CMake 3.11.4 or newer
message(FATAL_ERROR "Detected Java 10 or newer (${Java_VERSION_STRING}), to build with CMake please upgrade CMake to 3.11.4 or newer")

elseif(${CMAKE_VERSION} VERSION_LESS "3.11.4" OR (${Java_VERSION_MINOR} STREQUAL "7" AND ${Java_VERSION_MAJOR} STREQUAL "1"))
# Old CMake or Java 1.7 prepare the JAR...
message("Preparing Jar for Java 7")
elseif(${CMAKE_VERSION} VERSION_LESS "3.11.4")
# Old CMake
message("Using an old CMAKE (${CMAKE_VERSION}) - JNI headers generated in separate step")
add_jar(
rocksdbjni_classes
SOURCES
Expand Down Expand Up @@ -405,9 +409,9 @@ if(NOT EXISTS ${JAVA_ASSERTJ_JAR})
file(RENAME ${JAVA_TMP_JAR} ${JAVA_ASSERTJ_JAR})
endif()

if(${CMAKE_VERSION} VERSION_LESS "3.11.4" OR (${Java_VERSION_MINOR} STREQUAL "7" AND ${Java_VERSION_MAJOR} STREQUAL "1"))
# Old CMake or Java 1.7 ONLY generate JNI headers, Java 1.8+ JNI is handled in add_jar step above
message("Preparing JNI headers for Java 7")
if(${CMAKE_VERSION} VERSION_LESS "3.11.4")
# Old CMake ONLY generate JNI headers, otherwise JNI is handled in add_jar step above
message("Preparing JNI headers for old CMake (${CMAKE_VERSION})")
set(NATIVE_JAVA_CLASSES
org.rocksdb.AbstractCompactionFilter
org.rocksdb.AbstractCompactionFilterFactory
Expand Down
44 changes: 18 additions & 26 deletions java/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,6 @@ JAVAC_CMD := javac
endif
endif

ifeq ($(JAVAH_CMD),)
ifneq ($(JAVA_HOME),)
JAVAH_CMD := $(JAVA_HOME)/bin/javah
else
JAVAH_CMD := javah
endif
endif

ifeq ($(JAVADOC_CMD),)
ifneq ($(JAVA_HOME),)
JAVADOC_CMD := $(JAVA_HOME)/bin/javadoc
Expand All @@ -268,6 +260,17 @@ JAVADOC_CMD := javadoc
endif
endif

# Look for the Java version (1.6->6, 1.7->7, 1.8->8, 11.0->11, 13.0->13, 15.0->15 etc..)
JAVAC_VERSION := $(shell $(JAVAC_CMD) -version 2>&1)
JAVAC_MAJOR_VERSION := $(word 2,$(subst ., ,$(JAVAC_VERSION)))
ifeq ($(JAVAC_MAJOR_VERSION),1)
JAVAC_MAJOR_VERSION := $(word 3,$(subst ., ,$(JAVAC_VERSION)))
endif

# Test whether the version we see meets our minimum
MIN_JAVAC_MAJOR_VERSION := 8
JAVAC_VERSION_GE_MIN := $(shell [ $(JAVAC_MAJOR_VERSION) -ge $(MIN_JAVAC_MAJOR_VERSION) ] > /dev/null 2>&1 && echo true)

# Set the default JAVA_ARGS to "" for DEBUG_LEVEL=0
JAVA_ARGS ?=

Expand All @@ -283,6 +286,12 @@ endif
# of failing in Travis builds.)
DEPS_URL?=https://rocksdb-deps.s3-us-west-2.amazonaws.com/jars

java-version:
ifneq ($(JAVAC_VERSION_GE_MIN),true)
echo 'Java version is $(JAVAC_VERSION), minimum required version is $(MIN_JAVAC_MAJOR_VERSION)'
exit 1
endif

clean: clean-not-downloaded clean-downloaded

clean-not-downloaded:
Expand All @@ -301,22 +310,13 @@ javadocs: java

javalib: java java_test javadocs

java:
java: java-version
$(AM_V_GEN)mkdir -p $(MAIN_CLASSES)
ifeq ($(shell $(JAVAC_CMD) -version 2>&1 | grep 1.7.0 > /dev/null; printf $$?), 0)
$(AM_V_at)$(JAVAC_CMD) $(JAVAC_ARGS) -d $(MAIN_CLASSES)\
$(MAIN_SRC)/org/rocksdb/util/*.java\
$(MAIN_SRC)/org/rocksdb/*.java
else
$(AM_V_at)$(JAVAC_CMD) $(JAVAC_ARGS) -h $(NATIVE_INCLUDE) -d $(MAIN_CLASSES)\
$(MAIN_SRC)/org/rocksdb/util/*.java\
$(MAIN_SRC)/org/rocksdb/*.java
endif
$(AM_V_at)@cp ../HISTORY.md ./HISTORY-CPP.md
$(AM_V_at)@rm -f ./HISTORY-CPP.md
ifeq ($(shell $(JAVAH_CMD) -version 2>&1 | grep 1.7.0 > /dev/null; printf $$?), 0)
$(AM_V_at)$(JAVAH_CMD) -cp $(MAIN_CLASSES) -d $(NATIVE_INCLUDE) -jni $(NATIVE_JAVA_CLASSES)
endif

sample: java
$(AM_V_GEN)mkdir -p $(SAMPLES_MAIN_CLASSES)
Expand Down Expand Up @@ -415,18 +415,10 @@ resolve_test_deps: $(JAVA_JUNIT_JAR_PATH) $(JAVA_HAMCREST_JAR_PATH) $(JAVA_MOCKI

java_test: java resolve_test_deps
$(AM_V_GEN)mkdir -p $(TEST_CLASSES)
ifeq ($(shell $(JAVAC_CMD) -version 2>&1|grep 1.7.0 >/dev/null; printf $$?),0)
$(AM_V_at)$(JAVAC_CMD) $(JAVAC_ARGS) -cp $(MAIN_CLASSES):$(JAVA_TESTCLASSPATH) -d $(TEST_CLASSES)\
$(TEST_SRC)/org/rocksdb/test/*.java\
$(TEST_SRC)/org/rocksdb/util/*.java\
$(TEST_SRC)/org/rocksdb/*.java
$(AM_V_at)$(JAVAH_CMD) -cp $(MAIN_CLASSES):$(TEST_CLASSES) -d $(NATIVE_INCLUDE) -jni $(NATIVE_JAVA_TEST_CLASSES)
else
$(AM_V_at)$(JAVAC_CMD) $(JAVAC_ARGS) -cp $(MAIN_CLASSES):$(JAVA_TESTCLASSPATH) -h $(NATIVE_INCLUDE) -d $(TEST_CLASSES)\
$(TEST_SRC)/org/rocksdb/test/*.java\
$(TEST_SRC)/org/rocksdb/util/*.java\
$(TEST_SRC)/org/rocksdb/*.java
endif

test: java java_test run_test

Expand Down
15 changes: 9 additions & 6 deletions java/rocksjni/testable_event_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// (found in the LICENSE.Apache file in the root directory).
#include <climits>
#include <cstdint>
#include <iostream>
#include <utility>

#include "include/org_rocksdb_test_TestableEventListener.h"
Expand Down Expand Up @@ -184,21 +185,23 @@ void Java_org_rocksdb_test_TestableEventListener_invokeAllCallbacks(
write_stall_info.condition.prev = WriteStallCondition::kStopped;
el->OnStallConditionsChanged(write_stall_info);

FileOperationInfo op_info = FileOperationInfo(
FileOperationType::kRead, "/file/path",
const std::string file_path = "/file/path";
const auto start_timestamp =
std::make_pair(std::chrono::time_point<std::chrono::system_clock,
std::chrono::nanoseconds>(
std::chrono::nanoseconds(1600699420000000000ll)),
std::chrono::time_point<std::chrono::steady_clock,
std::chrono::nanoseconds>(
std::chrono::nanoseconds(1600699420000000000ll))),
std::chrono::nanoseconds(1600699420000000000ll)));
const auto finish_timestamp =
std::chrono::time_point<std::chrono::steady_clock,
std::chrono::nanoseconds>(
std::chrono::nanoseconds(1600699425000000000ll)),
status);
std::chrono::nanoseconds(1600699425000000000ll));
FileOperationInfo op_info =
FileOperationInfo(FileOperationType::kRead, file_path, start_timestamp,
finish_timestamp, status);
op_info.offset = UINT64_MAX;
op_info.length = SIZE_MAX;
op_info.status = status;

el->OnFileReadFinish(op_info);
el->OnFileWriteFinish(op_info);
Expand Down
Loading

0 comments on commit 36ce2e2

Please sign in to comment.