[CP] [to #55730303] fix: fix a PL JIT core when memory is insufficient

This commit is contained in:
0xacc 2024-04-09 12:54:00 +00:00 committed by ob-robot
parent eed677c16e
commit 852f63a7b3
4 changed files with 37 additions and 15 deletions

View File

@ -352,7 +352,8 @@ public:
public:
ObLLVMHelper(common::ObIAllocator &allocator)
: allocator_(allocator),
: is_inited_(false),
allocator_(allocator),
jc_(NULL),
jit_(NULL) {}
virtual ~ObLLVMHelper();
@ -457,6 +458,7 @@ private:
static int init_llvm();
private:
bool is_inited_;
common::ObIAllocator &allocator_;
core::JitContext *jc_;
core::ObOrcJit *jit_;

View File

@ -505,7 +505,10 @@ int ObLLVMHelper::init()
int ret = OB_SUCCESS;
OB_LLVM_MALLOC_GUARD("PlJit");
if (nullptr == (jc_ = OB_NEWx(core::JitContext, (&allocator_)))) {
if (is_inited_) {
ret = OB_INIT_TWICE;
LOG_WARN("ObLLVMHelper has been inited", K(ret), K(lbt()));
} else if (nullptr == (jc_ = OB_NEWx(core::JitContext, (&allocator_)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("failed to alloc memory for jit context", K(ret));
#ifndef ORC2
@ -513,10 +516,24 @@ int ObLLVMHelper::init()
#else
} else if (nullptr == (jit_ = core::ObOrcJit::create(allocator_))) {
#endif
jc_->~JitContext();
allocator_.free(jc_);
jc_ = nullptr;
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("failed to alloc memory for jit", K(ret));
} else if (OB_FAIL(jc_->InitializeModule(*jit_))) {
jit_->~ObOrcJit();
allocator_.free(jit_);
jit_ = nullptr;
jc_->~JitContext();
allocator_.free(jc_);
jc_ = nullptr;
LOG_WARN("failed to initialize module", K(ret));
} else {
jc_->InitializeModule(*jit_);
is_inited_ = true;
}
return ret;

View File

@ -4148,6 +4148,20 @@ void ObPLCompileUnit::dump_deleted_log_info(const bool is_debug_log /* = true */
}
}
ObPLCompileUnit::ObPLCompileUnit(sql::ObLibCacheNameSpace ns,
lib::MemoryContext &mem_context)
: ObPLCacheObject(ns, mem_context), routine_table_(allocator_),
type_table_(), helper_(allocator_), di_helper_(allocator_),
can_cached_(true)
{
#ifndef USE_MCJIT
int ret = OB_SUCCESS;
if (OB_FAIL(helper_.init())) {
LOG_WARN("failed to init llvm helper", K(ret), K(helper_.get_jc()));
}
#endif // USE_MCJIT
}
ObPLFunction::~ObPLFunction()
{
int ret = OB_SUCCESS;

View File

@ -227,18 +227,7 @@ class ObPLCompileUnit : public ObPLCacheObject
{
friend class ::test::MockCacheObjectFactory;
public:
ObPLCompileUnit(sql::ObLibCacheNameSpace ns, lib::MemoryContext &mem_context)
: ObPLCacheObject(ns, mem_context),
routine_table_(allocator_),
type_table_(),
helper_(allocator_),
di_helper_(allocator_),
can_cached_(true)
{
#ifndef USE_MCJIT
helper_.init();
#endif
}
ObPLCompileUnit(sql::ObLibCacheNameSpace ns, lib::MemoryContext &mem_context);
virtual ~ObPLCompileUnit();
inline bool get_can_cached() { return can_cached_; }