[to #49775478] fix tenant_id and mod_name in PL code generator and JIT

This commit is contained in:
0xacc
2023-05-25 18:17:31 +00:00
committed by ob-robot
parent 6de40b6e88
commit 072dab0f7d
8 changed files with 46 additions and 31 deletions

View File

@ -12,6 +12,7 @@
#include "lib/alloc/alloc_struct.h"
#include "lib/ob_define.h"
#include "lib/allocator/ob_mod_define.h"
#include "lib/coro/co_var.h"
#include "lib/oblog/ob_log.h"
#include "lib/utility/ob_fast_convert.h"
@ -20,6 +21,10 @@ using namespace oceanbase;
using namespace lib;
using namespace common;
thread_local ObMemAttr ObMallocHookAttrGuard::tl_mem_attr(OB_SERVER_TENANT_ID,
"glibc_malloc",
ObCtxIds::GLIBC);
bool ObLabel::operator==(const ObLabel &other) const
{
bool bret = false;

View File

@ -588,6 +588,27 @@ private:
char buf_[MAX_LEN + 1];
};
class ObMallocHookAttrGuard
{
public:
ObMallocHookAttrGuard(const ObMemAttr& attr)
: old_attr_(tl_mem_attr)
{
tl_mem_attr = attr;
}
~ObMallocHookAttrGuard()
{
tl_mem_attr = old_attr_;
}
static ObMemAttr get_tl_mem_attr()
{
return tl_mem_attr;
}
private:
static thread_local ObMemAttr tl_mem_attr;
ObMemAttr old_attr_;
};
} // end of namespace lib
} // end of namespace oceanbase

View File

@ -20,9 +20,7 @@ using namespace oceanbase::common;
using namespace oceanbase::lib;
bool g_malloc_hook_inited = false;
thread_local ObMemAttr ObMallocHookAttrGuard::tl_mem_attr(OB_SERVER_TENANT_ID,
"glibc_malloc",
ObCtxIds::GLIBC);
void init_malloc_hook()
{
g_malloc_hook_inited = true;

View File

@ -20,31 +20,5 @@ inline bool& in_hook()
thread_local bool in_hook = false;
return in_hook;
}
namespace oceanbase
{
namespace lib
{
class ObMallocHookAttrGuard
{
public:
ObMallocHookAttrGuard(ObMemAttr& attr)
: old_attr_(tl_mem_attr)
{
tl_mem_attr = attr;
}
~ObMallocHookAttrGuard()
{
tl_mem_attr = old_attr_;
}
static ObMemAttr get_tl_mem_attr()
{
return tl_mem_attr;
}
private:
static thread_local ObMemAttr tl_mem_attr;
ObMemAttr old_attr_;
};
}
}
#endif /* MALLOC_HOOK_H */

View File

@ -9,7 +9,7 @@ file(GLOB_RECURSE objit_SRC "*.h" "*.cpp" "${CMAKE_CURRENT_SROUCE_DIR}/../includ
add_definitions(-std=gnu++14)
add_library(objit_objects OBJECT ${objit_SRC})
target_link_libraries(objit_objects PRIVATE oblib_base_base objit_base)
target_link_libraries(objit_objects PRIVATE oblib_base_base ob_share objit_base)
# Define a static library target named OBJIT_RAW.
add_library(objit STATIC dummy.cpp)

View File

@ -29,6 +29,8 @@
#include "lib/utility/ob_macro_utils.h"
#include "lib/allocator/ob_malloc.h"
#include "lib/container/ob_se_array.h"
#include "share/rc/ob_tenant_base.h"
#include "lib/alloc/malloc_hook.h"
using namespace llvm;
@ -477,6 +479,7 @@ int ObLLVMSwitch::add_case(const ObLLVMValue &value, ObLLVMBasicBlock &block)
ObLLVMHelper::~ObLLVMHelper()
{
lib::ObMallocHookAttrGuard malloc_guard(ObMemAttr(MTL_ID(), "PlJit"));
final();
if (nullptr != jit_) {
jit_->~ObOrcJit();
@ -486,6 +489,7 @@ ObLLVMHelper::~ObLLVMHelper()
int ObLLVMHelper::init()
{
lib::ObMallocHookAttrGuard malloc_guard(ObMemAttr(MTL_ID(), "PlJit"));
int ret = OB_SUCCESS;
if (nullptr == (jc_ = OB_NEWx(core::JitContext, (&allocator_)))) {
@ -507,6 +511,7 @@ int ObLLVMHelper::init()
void ObLLVMHelper::final()
{
lib::ObMallocHookAttrGuard malloc_guard(ObMemAttr(MTL_ID(), "PlJit"));
if (nullptr != jc_) {
jc_->~JitContext();
allocator_.free(jc_);
@ -525,15 +530,18 @@ int ObLLVMHelper::initialize()
void ObLLVMHelper::compile_module(bool optimization)
{
if (optimization) {
lib::ObMallocHookAttrGuard malloc_guard(ObMemAttr(MTL_ID(), "PlCodeGen"));
jc_->optimize();
LOG_INFO("================Optimized LLVM Module================");
dump_module();
}
lib::ObMallocHookAttrGuard malloc_guard(ObMemAttr(MTL_ID(), "PlJit"));
jc_->compile();
}
void ObLLVMHelper::dump_module()
{
lib::ObMallocHookAttrGuard malloc_guard(ObMemAttr(MTL_ID(), "PlCodeGen"));
if (OB_ISNULL(jc_)) {
//do nothing
} else {
@ -546,6 +554,7 @@ void ObLLVMHelper::dump_module()
void ObLLVMHelper::dump_debuginfo()
{
lib::ObMallocHookAttrGuard malloc_guard(ObMemAttr(MTL_ID(), "PlCodeGen"));
if (OB_ISNULL(jit_) || jit_->get_debug_info_size() <= 0) {
// do nothing ...
} else {
@ -555,6 +564,7 @@ void ObLLVMHelper::dump_debuginfo()
int ObLLVMHelper::verify_function(ObLLVMFunction &function)
{
lib::ObMallocHookAttrGuard malloc_guard(ObMemAttr(MTL_ID(), "PlCodeGen"));
int ret = OB_SUCCESS;
if (OB_ISNULL(jc_)) {
ret = OB_NOT_INIT;
@ -571,6 +581,7 @@ int ObLLVMHelper::verify_function(ObLLVMFunction &function)
int ObLLVMHelper::verify_module()
{
lib::ObMallocHookAttrGuard malloc_guard(ObMemAttr(MTL_ID(), "PlCodeGen"));
int ret = OB_SUCCESS;
std::string verify_error;
llvm::raw_string_ostream verify_raw_os(verify_error);
@ -586,6 +597,7 @@ int ObLLVMHelper::verify_module()
uint64_t ObLLVMHelper::get_function_address(const ObString &name)
{
lib::ObMallocHookAttrGuard guard(ObMemAttr(MTL_ID(), "PlJit"));
return jc_->TheJIT->get_function_address(std::string(name.ptr(), name.length()));
}

View File

@ -194,7 +194,7 @@ public:
debug_mode_(session_info_.is_pl_debug_on() && func_ast.is_routine()),
oracle_mode_(oracle_mode)
{
goto_label_map_.create(func_ast.get_body()->get_stmts().count(), ObModIds::OB_PL);
goto_label_map_.create(func_ast.get_body()->get_stmts().count(), "PlCodeGen");
}
virtual ~ObPLCodeGenerator() {}

View File

@ -23,6 +23,7 @@
#include "pl/ob_pl_resolver.h"
#include "pl/ob_pl_code_generator.h"
#include "pl/ob_pl_package.h"
#include "lib/alloc/malloc_hook.h"
namespace oceanbase {
using namespace common;
@ -159,6 +160,7 @@ int ObPLCompiler::compile(
func.get_di_helper(),
lib::is_oracle_mode()) {
#endif
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), "PlCodeGen"));
if (OB_FAIL(cg.init())) {
LOG_WARN("failed to init code generator", K(ret));
} else if (OB_FAIL(cg.generate(func))) {
@ -385,6 +387,7 @@ int ObPLCompiler::compile(const uint64_t id, ObPLFunction &func)
func.get_di_helper(),
lib::is_oracle_mode()) {
#endif
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), "PlCodeGen"));
if (OB_FAIL(cg.init())) {
LOG_WARN("failed to init code generator", K(ret));
} else if (OB_FAIL(cg.generate(func))) {
@ -704,6 +707,7 @@ int ObPLCompiler::compile_package(const ObPackageInfo &package_info,
package.get_di_helper(),
lib::is_oracle_mode()) {
#endif
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), "PlCodeGen"));
OZ (cg.init());
OZ (cg.generate(package));
}
@ -1121,6 +1125,7 @@ int ObPLCompiler::compile_subprogram_table(common::ObIAllocator &allocator,
routine->get_di_helper(),
lib::is_oracle_mode()) {
#endif
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), "PlCodeGen"));
if (OB_FAIL(cg.init())) {
LOG_WARN("init code generator failed", K(ret));
} else if (OB_FAIL(cg.generate(*routine))) {