Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions be/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,27 @@ if ("${DORIS_JAVA_HOME}" STREQUAL "")
set(DORIS_JAVA_HOME "$ENV{JAVA_HOME}")
endif()

execute_process(COMMAND chmod 755 ${BASE_DIR}/../tools/find_libjvm.sh)
execute_process(COMMAND ${BASE_DIR}/../tools/find_libjvm.sh OUTPUT_VARIABLE LIBJVM_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
FILE(GLOB_RECURSE LIB_JVM ${LIBJVM_PATH})
if("${LIB_JVM}" STREQUAL "")
message(STATUS "there is no libjvm found!")
else()
set(DORIS_DEPENDENCIES
${DORIS_DEPENDENCIES}
jvm
)
add_library(jvm SHARED IMPORTED)
set_target_properties(jvm PROPERTIES IMPORTED_LOCATION ${LIB_JVM})
include_directories(${DORIS_JAVA_HOME}/include)
if (NOT OS_MACOSX)
include_directories(${DORIS_JAVA_HOME}/include/linux)
else()
include_directories(${DORIS_JAVA_HOME}/include/darwin)
endif()
add_definitions("-DLIBJVM")
endif()

include_directories(${DORIS_JAVA_HOME}/include)
if (NOT OS_MACOSX)
include_directories(${DORIS_JAVA_HOME}/include/linux)
Expand Down Expand Up @@ -569,6 +590,8 @@ if (NOT OS_MACOSX)
-static-libgcc
-lstdc++fs
-lresolv
#-L/mnt/datadisk0/chenqi/jdk-17.0.8/lib/server/
#-ljvm
)
else()
set(DORIS_LINK_LIBS
Expand Down
2 changes: 1 addition & 1 deletion be/src/util/jni-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ Status JniUtil::get_jni_scanner_class(JNIEnv* env, const char* classname,
}

Status JniUtil::Init() {
RETURN_IF_ERROR(LibJVMLoader::instance().load());
//RETURN_IF_ERROR(LibJVMLoader::instance().load());

// Get the JNIEnv* corresponding to current thread.
JNIEnv* env = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions be/src/util/libjvm_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
#include "jni.h"
#include "jni_md.h"

_JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM** vm_buf, jsize bufLen,
/*_JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM** vm_buf, jsize bufLen,
jsize* numVMs) {
return doris::LibJVMLoader::JNI_GetCreatedJavaVMs(vm_buf, bufLen, numVMs);
}

_JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM** pvm, void** penv, void* args) {
return doris::LibJVMLoader::JNI_CreateJavaVM(pvm, penv, args);
}
}*/

namespace {

Expand Down
35 changes: 35 additions & 0 deletions bin/start_be.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

set -eo pipefail

#export JAVA_HOME=/data/chenqi/jdk-17.0.8/

curdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

MACHINE_OS=$(uname -s)
Expand Down Expand Up @@ -132,6 +134,7 @@ export CLASSPATH="${DORIS_HOME}/conf/:${DORIS_CLASSPATH}:${CLASSPATH}"
# DORIS_CLASSPATH is for self-managed jni
export DORIS_CLASSPATH="-Djava.class.path=${DORIS_CLASSPATH}"

#export LD_LIBRARY_PATH="${DORIS_HOME}/lib/hadoop_hdfs/native:/data/chenqi/jdk-17.0.8/lib/server:${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH="${DORIS_HOME}/lib/hadoop_hdfs/native:${LD_LIBRARY_PATH}"

jdk_version() {
Expand Down Expand Up @@ -160,6 +163,36 @@ jdk_version() {
return 0
}

setup_java_env() {
local java_version

if [[ -z "${JAVA_HOME}" ]]; then
return 1
fi

local jvm_arch='amd64'
if [[ "$(uname -m)" == 'aarch64' ]]; then
jvm_arch='aarch64'
fi
java_version="$(
set -e
jdk_version "${JAVA_HOME}/bin/java"
)"
if [[ "${java_version}" -gt 8 ]]; then
export LD_LIBRARY_PATH="${JAVA_HOME}/lib/server:${JAVA_HOME}/lib:${LD_LIBRARY_PATH}"
# JAVA_HOME is jdk
elif [[ -d "${JAVA_HOME}/jre" ]]; then
export LD_LIBRARY_PATH="${JAVA_HOME}/jre/lib/${jvm_arch}/server:${JAVA_HOME}/jre/lib/${jvm_arch}:${LD_LIBRARY_PATH}"
# JAVA_HOME is jre
else
export LD_LIBRARY_PATH="${JAVA_HOME}/lib/${jvm_arch}/server:${JAVA_HOME}/lib/${jvm_arch}:${LD_LIBRARY_PATH}"
fi
}

# prepare jvm if needed
setup_java_env || true


# export env variables from be.conf
#
# LOG_DIR
Expand Down Expand Up @@ -339,9 +372,11 @@ else
fi

if [[ "${RUN_DAEMON}" -eq 1 ]]; then
#LD_PRELOAD=/data/chenqi/hive_write_output/libjemalloc_doris.so nohup ${LIMIT:+${LIMIT}} "${DORIS_HOME}/lib/doris_be" "$@" >>"${LOG_DIR}/be.out" 2>&1 </dev/null &
nohup ${LIMIT:+${LIMIT}} "${DORIS_HOME}/lib/doris_be" "$@" >>"${LOG_DIR}/be.out" 2>&1 </dev/null &
elif [[ "${RUN_CONSOLE}" -eq 1 ]]; then
export DORIS_LOG_TO_STDERR=1
#LD_PRELOAD=/data/chenqi/hive_write_output/libjemalloc_doris.so ${LIMIT:+${LIMIT}} "${DORIS_HOME}/lib/doris_be" "$@" 2>&1 </dev/null
${LIMIT:+${LIMIT}} "${DORIS_HOME}/lib/doris_be" "$@" 2>&1 </dev/null
else
${LIMIT:+${LIMIT}} "${DORIS_HOME}/lib/doris_be" "$@" >>"${LOG_DIR}/be.out" 2>&1 </dev/null
Expand Down
61 changes: 61 additions & 0 deletions tools/find_libjvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

jdk_version() {
local java_cmd="${1}"
local result
local IFS=$'\n'

if [[ -z "${java_cmd}" ]]; then
result=no_java
return 1
else
local version
# remove \r for Cygwin
version="$("${java_cmd}" -Xms32M -Xmx32M -version 2>&1 | tr '\r' '\n' | grep version | awk '{print $3}')"
version="${version//\"/}"
if [[ "${version}" =~ ^1\. ]]; then
result="$(echo "${version}" | awk -F '.' '{print $2}')"
else
result="$(echo "${version}" | awk -F '.' '{print $1}')"
fi
fi
echo "${result}"
return 0
}

java_version=$(jdk_version "${JAVA_HOME:-}/bin/java")
jvm_arch='amd64'
if [[ "$(uname -m)" == 'aarch64' ]]; then
jvm_arch='aarch64'
fi
if [[ "${java_version}" -gt 8 ]]; then
export LIBJVM_PATH="${JAVA_HOME}/lib"
# JAVA_HOME is jdk
elif [[ -d "${JAVA_HOME}/jre" ]]; then
export LIBJVM_PATH="${JAVA_HOME}/jre/lib/${jvm_arch}"
# JAVA_HOME is jre
else
export LIBJVM_PATH="${JAVA_HOME}/lib/${jvm_arch}"
fi

if [[ "$(uname -s)" != 'Darwin' ]]; then
echo "${LIBJVM_PATH}"/*/libjvm.so
else
echo "${LIBJVM_PATH}"/*/libjvm.dylib
fi