Skip to content

Commit 4e7edbf

Browse files
0xaccob-robot
authored andcommitted
[CP] [to #53439720] fix quantity upper limit of UDTs a PL can reference to
1 parent dc76ede commit 4e7edbf

5 files changed

Lines changed: 70 additions & 17 deletions

File tree

src/objit/src/ob_llvm_helper.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "lib/container/ob_se_array.h"
3333
#include "share/rc/ob_tenant_base.h"
3434
#include "lib/alloc/malloc_hook.h"
35+
#include "pl/ob_pl_allocator.h"
3536

3637
using namespace llvm;
3738

@@ -587,7 +588,7 @@ int ObLLVMHelper::init_llvm() {
587588
void ObLLVMHelper::compile_module(bool optimization)
588589
{
589590
if (optimization) {
590-
OB_LLVM_MALLOC_GUARD("PlCodeGen");
591+
OB_LLVM_MALLOC_GUARD(GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN));
591592
jc_->optimize();
592593
LOG_INFO("================Optimized LLVM Module================");
593594
dump_module();
@@ -598,7 +599,7 @@ void ObLLVMHelper::compile_module(bool optimization)
598599

599600
void ObLLVMHelper::dump_module()
600601
{
601-
OB_LLVM_MALLOC_GUARD("PlCodeGen");
602+
OB_LLVM_MALLOC_GUARD(GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN));
602603
if (OB_ISNULL(jc_)) {
603604
//do nothing
604605
} else {
@@ -611,7 +612,7 @@ void ObLLVMHelper::dump_module()
611612

612613
void ObLLVMHelper::dump_debuginfo()
613614
{
614-
OB_LLVM_MALLOC_GUARD("PlCodeGen");
615+
OB_LLVM_MALLOC_GUARD(GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN));
615616
if (OB_ISNULL(jit_) || jit_->get_debug_info_size() <= 0) {
616617
// do nothing ...
617618
} else {
@@ -621,7 +622,7 @@ void ObLLVMHelper::dump_debuginfo()
621622

622623
int ObLLVMHelper::verify_function(ObLLVMFunction &function)
623624
{
624-
OB_LLVM_MALLOC_GUARD("PlCodeGen");
625+
OB_LLVM_MALLOC_GUARD(GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN));
625626
int ret = OB_SUCCESS;
626627
if (OB_ISNULL(jc_)) {
627628
ret = OB_NOT_INIT;
@@ -638,7 +639,7 @@ int ObLLVMHelper::verify_function(ObLLVMFunction &function)
638639

639640
int ObLLVMHelper::verify_module()
640641
{
641-
OB_LLVM_MALLOC_GUARD("PlCodeGen");
642+
OB_LLVM_MALLOC_GUARD(GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN));
642643
int ret = OB_SUCCESS;
643644
std::string verify_error;
644645
llvm::raw_string_ostream verify_raw_os(verify_error);

src/pl/ob_pl_allocator.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ PL_MOD_DEF(OB_PL_DEBUG_MOD, "PlDebug")
2121
PL_MOD_DEF(OB_PL_DEBUG_SYS_MOD, "PlDebugSys")
2222
PL_MOD_DEF(OB_PL_ANY_DATA, "AnyData")
2323
PL_MOD_DEF(OB_PL_ANY_TYPE, "AnyType")
24+
PL_MOD_DEF(OB_PL_CODE_GEN, "PlCodeGen")
2425
#endif
2526

2627

@@ -142,8 +143,11 @@ static constexpr const char* OB_PL_MOD_DEF[PL_MOD_IDX_NUM] =
142143
#undef PL_MOD_DEF
143144
};
144145

145-
#define GET_PL_MOD_STRING(type) (type > OB_MOD_INVALID && type < PL_MOD_IDX_NUM) ? OB_PL_MOD_DEF[type] : "PlTemp"
146-
146+
#define GET_PL_MOD_STRING(type) \
147+
(type > oceanbase::pl::OB_MOD_INVALID && \
148+
type < oceanbase::pl::PL_MOD_IDX_NUM) \
149+
? oceanbase::pl::OB_PL_MOD_DEF[type] \
150+
: "PlTemp"
147151
}
148152
}
149153

src/pl/ob_pl_code_generator.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3527,7 +3527,37 @@ int ObPLCodeGenerator::build_opaque_type(const ObUserDefinedType &opaque_type,
35273527
int ObPLCodeGenerator::init()
35283528
{
35293529
int ret = OB_SUCCESS;
3530-
if (debug_mode_ && OB_FAIL(di_helper_.init(helper_.get_jc()))) {
3530+
3531+
// CG local types + external types at least, so pre-allocate doubled buckets
3532+
// bucket number will grow up automatically if udt_count_guess is not enough
3533+
int64_t udt_count_guess =
3534+
(ast_.get_user_type_table().get_count() +
3535+
ast_.get_user_type_table().get_external_types().count()) * 2;
3536+
3537+
// make udt_count_guess at least 64, to prevent size grow up frequently in bad case
3538+
if (udt_count_guess < 64) {
3539+
udt_count_guess = 64;
3540+
}
3541+
3542+
int64_t goto_label_count_guess = 64;
3543+
if (OB_NOT_NULL(ast_.get_body()) &&
3544+
ast_.get_body()->get_stmts().count() > goto_label_count_guess) {
3545+
goto_label_count_guess = ast_.get_body()->get_stmts().count();
3546+
}
3547+
3548+
if (OB_FAIL(user_type_map_.create(
3549+
udt_count_guess,
3550+
ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(OB_PL_CODE_GEN))))){
3551+
LOG_WARN("failed to create user_type_map_", K(ret), K(udt_count_guess));
3552+
} else if (OB_FAIL(di_user_type_map_.create(
3553+
udt_count_guess,
3554+
ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(OB_PL_CODE_GEN))))){
3555+
LOG_WARN("failed to create di_user_type_map_", K(ret), K(udt_count_guess));
3556+
} else if (OB_FAIL(goto_label_map_.create(
3557+
goto_label_count_guess,
3558+
ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(OB_PL_CODE_GEN))))) {
3559+
LOG_WARN("failed to create goto_label_map_", K(ret), K(goto_label_count_guess));
3560+
} else if (debug_mode_ && OB_FAIL(di_helper_.init(helper_.get_jc()))) {
35313561
LOG_WARN("failed to init di helper", K(ret));
35323562
} else if (OB_FAIL(init_spi_service())) {
35333563
LOG_WARN("failed to init spi service", K(ret));

src/pl/ob_pl_code_generator.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@ class ObPLCodeGenerator
194194
di_user_type_map_(),
195195
debug_mode_(session_info_.is_pl_debug_on() && func_ast.is_routine()),
196196
oracle_mode_(oracle_mode)
197-
{
198-
goto_label_map_.create(func_ast.get_body()->get_stmts().count(), "PlCodeGen");
199-
}
197+
{ }
200198

201199
virtual ~ObPLCodeGenerator() {}
202200

@@ -488,8 +486,28 @@ class ObPLCodeGenerator
488486
}
489487
inline jit::ObLLVMFunction &get_func() { return func_; }
490488
inline ObPLSEArray<jit::ObLLVMValue> &get_vars() { return vars_; }
491-
typedef common::hash::ObPlacementHashMap<uint64_t, jit::ObLLVMType, 733> ObLLVMTypeMap;
492-
typedef common::hash::ObPlacementHashMap<uint64_t, jit::ObLLVMDIType, 733> ObLLVMDITypeMap;
489+
typedef common::hash::ObHashMap<
490+
uint64_t, jit::ObLLVMType,
491+
common::hash::NoPthreadDefendMode,
492+
common::hash::hash_func<uint64_t>,
493+
common::hash::equal_to<uint64_t>,
494+
common::hash::SimpleAllocer<common::hash::ObHashTableNode<
495+
common::hash::HashMapPair<uint64_t, jit::ObLLVMType>>>,
496+
common::hash::NormalPointer,
497+
common::ObMalloc,
498+
2> // EXTEND_RATIO
499+
ObLLVMTypeMap;
500+
typedef common::hash::ObHashMap<
501+
uint64_t, jit::ObLLVMDIType,
502+
common::hash::NoPthreadDefendMode,
503+
common::hash::hash_func<uint64_t>,
504+
common::hash::equal_to<uint64_t>,
505+
common::hash::SimpleAllocer<common::hash::ObHashTableNode<
506+
common::hash::HashMapPair<uint64_t, jit::ObLLVMDIType>>>,
507+
common::hash::NormalPointer,
508+
common::ObMalloc,
509+
2> // EXTEND_RATIO
510+
ObLLVMDITypeMap;
493511
inline ObLLVMTypeMap &get_user_type_map() { return user_type_map_; }
494512
int set_var_addr_to_param_store(int64_t var_index, jit::ObLLVMValue &var, jit::ObLLVMValue &init_value);
495513
int get_llvm_type(const ObPLDataType &pl_type, jit::ObLLVMType &ir_type);

src/pl/ob_pl_compile.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ int ObPLCompiler::compile(
230230
func.get_di_helper(),
231231
lib::is_oracle_mode()) {
232232
#endif
233-
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), "PlCodeGen"));
233+
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN)));
234234
uint64_t lock_idx = stmt_id != OB_INVALID_ID ? stmt_id : murmurhash(block->str_value_, block->str_len_, 0);
235235
ObBucketHashWLockGuard compile_guard(GCTX.pl_engine_->get_jit_lock(), lock_idx);
236236
// check session status after get lock
@@ -469,7 +469,7 @@ int ObPLCompiler::compile(const uint64_t id, ObPLFunction &func)
469469
func.get_di_helper(),
470470
lib::is_oracle_mode()) {
471471
#endif
472-
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), "PlCodeGen"));
472+
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN)));
473473
ObBucketHashWLockGuard compile_guard(GCTX.pl_engine_->get_jit_lock(), id);
474474
// check session status after get lock
475475
if (OB_FAIL(ObPL::check_session_alive(session_info_))) {
@@ -801,7 +801,7 @@ int ObPLCompiler::compile_package(const ObPackageInfo &package_info,
801801
package.get_di_helper(),
802802
lib::is_oracle_mode()) {
803803
#endif
804-
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), "PlCodeGen"));
804+
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN)));
805805
OZ (cg.init());
806806
OZ (cg.generate(package));
807807
}
@@ -1300,7 +1300,7 @@ int ObPLCompiler::compile_subprogram_table(common::ObIAllocator &allocator,
13001300
routine->get_di_helper(),
13011301
lib::is_oracle_mode()) {
13021302
#endif
1303-
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), "PlCodeGen"));
1303+
lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(MTL_ID(), GET_PL_MOD_STRING(pl::OB_PL_CODE_GEN)));
13041304
if (OB_FAIL(cg.init())) {
13051305
LOG_WARN("init code generator failed", K(ret));
13061306
} else if (OB_FAIL(cg.generate(*routine))) {

0 commit comments

Comments
 (0)