[CP] [to #53439720] fix quantity upper limit of UDTs a PL can reference to

This commit is contained in:
0xacc 2024-02-07 11:36:58 +00:00 committed by ob-robot
parent 2585b814c8
commit 97793c3112
5 changed files with 70 additions and 17 deletions

View File

@ -32,6 +32,7 @@
#include "lib/container/ob_se_array.h"
#include "share/rc/ob_tenant_base.h"
#include "lib/alloc/malloc_hook.h"
#include "pl/ob_pl_allocator.h"
using namespace llvm;
@ -587,7 +588,7 @@ int ObLLVMHelper::init_llvm() {
void ObLLVMHelper::compile_module(bool optimization)
{
if (optimization) {
OB_LLVM_MALLOC_GUARD("PlCodeGen");
OB_LLVM_MALLOC_GUARD(GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN));
jc_->optimize();
LOG_INFO("================Optimized LLVM Module================");
dump_module();
@ -598,7 +599,7 @@ void ObLLVMHelper::compile_module(bool optimization)
void ObLLVMHelper::dump_module()
{
OB_LLVM_MALLOC_GUARD("PlCodeGen");
OB_LLVM_MALLOC_GUARD(GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN));
if (OB_ISNULL(jc_)) {
//do nothing
} else {
@ -611,7 +612,7 @@ void ObLLVMHelper::dump_module()
void ObLLVMHelper::dump_debuginfo()
{
OB_LLVM_MALLOC_GUARD("PlCodeGen");
OB_LLVM_MALLOC_GUARD(GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN));
if (OB_ISNULL(jit_) || jit_->get_debug_info_size() <= 0) {
// do nothing ...
} else {
@ -621,7 +622,7 @@ void ObLLVMHelper::dump_debuginfo()
int ObLLVMHelper::verify_function(ObLLVMFunction &function)
{
OB_LLVM_MALLOC_GUARD("PlCodeGen");
OB_LLVM_MALLOC_GUARD(GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN));
int ret = OB_SUCCESS;
if (OB_ISNULL(jc_)) {
ret = OB_NOT_INIT;
@ -638,7 +639,7 @@ int ObLLVMHelper::verify_function(ObLLVMFunction &function)
int ObLLVMHelper::verify_module()
{
OB_LLVM_MALLOC_GUARD("PlCodeGen");
OB_LLVM_MALLOC_GUARD(GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN));
int ret = OB_SUCCESS;
std::string verify_error;
llvm::raw_string_ostream verify_raw_os(verify_error);

View File

@ -21,6 +21,7 @@ PL_MOD_DEF(OB_PL_DEBUG_MOD, "PlDebug")
PL_MOD_DEF(OB_PL_DEBUG_SYS_MOD, "PlDebugSys")
PL_MOD_DEF(OB_PL_ANY_DATA, "AnyData")
PL_MOD_DEF(OB_PL_ANY_TYPE, "AnyType")
PL_MOD_DEF(OB_PL_CODE_GEN, "PlCodeGen")
#endif
@ -142,8 +143,11 @@ static constexpr const char* OB_PL_MOD_DEF[PL_MOD_IDX_NUM] =
#undef PL_MOD_DEF
};
#define GET_PL_MOD_STRING(type) (type > OB_MOD_INVALID && type < PL_MOD_IDX_NUM) ? OB_PL_MOD_DEF[type] : "PlTemp"
#define GET_PL_MOD_STRING(type) \
(type > oceanbase::pl::OB_MOD_INVALID && \
type < oceanbase::pl::PL_MOD_IDX_NUM) \
? oceanbase::pl::OB_PL_MOD_DEF[type] \
: "PlTemp"
}
}

View File

@ -3527,7 +3527,37 @@ int ObPLCodeGenerator::build_opaque_type(const ObUserDefinedType &opaque_type,
int ObPLCodeGenerator::init()
{
int ret = OB_SUCCESS;
if (debug_mode_ && OB_FAIL(di_helper_.init(helper_.get_jc()))) {
// CG local types + external types at least, so pre-allocate doubled buckets
// bucket number will grow up automatically if udt_count_guess is not enough
int64_t udt_count_guess =
(ast_.get_user_type_table().get_count() +
ast_.get_user_type_table().get_external_types().count()) * 2;
// make udt_count_guess at least 64, to prevent size grow up frequently in bad case
if (udt_count_guess < 64) {
udt_count_guess = 64;
}
int64_t goto_label_count_guess = 64;
if (OB_NOT_NULL(ast_.get_body()) &&
ast_.get_body()->get_stmts().count() > goto_label_count_guess) {
goto_label_count_guess = ast_.get_body()->get_stmts().count();
}
if (OB_FAIL(user_type_map_.create(
udt_count_guess,
ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(OB_PL_CODE_GEN))))){
LOG_WARN("failed to create user_type_map_", K(ret), K(udt_count_guess));
} else if (OB_FAIL(di_user_type_map_.create(
udt_count_guess,
ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(OB_PL_CODE_GEN))))){
LOG_WARN("failed to create di_user_type_map_", K(ret), K(udt_count_guess));
} else if (OB_FAIL(goto_label_map_.create(
goto_label_count_guess,
ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(OB_PL_CODE_GEN))))) {
LOG_WARN("failed to create goto_label_map_", K(ret), K(goto_label_count_guess));
} else if (debug_mode_ && OB_FAIL(di_helper_.init(helper_.get_jc()))) {
LOG_WARN("failed to init di helper", K(ret));
} else if (OB_FAIL(init_spi_service())) {
LOG_WARN("failed to init spi service", K(ret));

View File

@ -194,9 +194,7 @@ public:
di_user_type_map_(),
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(), "PlCodeGen");
}
{ }
virtual ~ObPLCodeGenerator() {}
@ -488,8 +486,28 @@ public:
}
inline jit::ObLLVMFunction &get_func() { return func_; }
inline ObPLSEArray<jit::ObLLVMValue> &get_vars() { return vars_; }
typedef common::hash::ObPlacementHashMap<uint64_t, jit::ObLLVMType, 733> ObLLVMTypeMap;
typedef common::hash::ObPlacementHashMap<uint64_t, jit::ObLLVMDIType, 733> ObLLVMDITypeMap;
typedef common::hash::ObHashMap<
uint64_t, jit::ObLLVMType,
common::hash::NoPthreadDefendMode,
common::hash::hash_func<uint64_t>,
common::hash::equal_to<uint64_t>,
common::hash::SimpleAllocer<common::hash::ObHashTableNode<
common::hash::HashMapPair<uint64_t, jit::ObLLVMType>>>,
common::hash::NormalPointer,
common::ObMalloc,
2> // EXTEND_RATIO
ObLLVMTypeMap;
typedef common::hash::ObHashMap<
uint64_t, jit::ObLLVMDIType,
common::hash::NoPthreadDefendMode,
common::hash::hash_func<uint64_t>,
common::hash::equal_to<uint64_t>,
common::hash::SimpleAllocer<common::hash::ObHashTableNode<
common::hash::HashMapPair<uint64_t, jit::ObLLVMDIType>>>,
common::hash::NormalPointer,
common::ObMalloc,
2> // EXTEND_RATIO
ObLLVMDITypeMap;
inline ObLLVMTypeMap &get_user_type_map() { return user_type_map_; }
int set_var_addr_to_param_store(int64_t var_index, jit::ObLLVMValue &var, jit::ObLLVMValue &init_value);
int get_llvm_type(const ObPLDataType &pl_type, jit::ObLLVMType &ir_type);

View File

@ -230,7 +230,7 @@ int ObPLCompiler::compile(
func.get_di_helper(),
lib::is_oracle_mode()) {
#endif
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), "PlCodeGen"));
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN)));
uint64_t lock_idx = stmt_id != OB_INVALID_ID ? stmt_id : murmurhash(block->str_value_, block->str_len_, 0);
ObBucketHashWLockGuard compile_guard(GCTX.pl_engine_->get_jit_lock(), lock_idx);
// check session status after get lock
@ -469,7 +469,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"));
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN)));
ObBucketHashWLockGuard compile_guard(GCTX.pl_engine_->get_jit_lock(), id);
// check session status after get lock
if (OB_FAIL(ObPL::check_session_alive(session_info_))) {
@ -801,7 +801,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"));
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN)));
OZ (cg.init());
OZ (cg.generate(package));
}
@ -1300,7 +1300,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"));
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN)));
if (OB_FAIL(cg.init())) {
LOG_WARN("init code generator failed", K(ret));
} else if (OB_FAIL(cg.generate(*routine))) {