Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Remove the size assert of je_nallocx #39293

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

trueeyu
Copy link
Contributor

@trueeyu trueeyu commented Jan 17, 2024

Why I'm doing:

If build with jemalloc-debug=true, BE will crash when using jni scanner.

<jemalloc>: src/jemalloc.c:3963: Failed assertion: "size != 0"
*** Aborted at 1705466978 (unix time) try "date -d @1705466978" if you are using GNU date ***
PC: @     0x7f823f35d387 __GI_raise
*** SIGABRT (@0x3f000009b9d) received by PID 39837 (TID 0x7f81c91f1700) from PID 39837; stack trace: ***
    @          0xfc71752 google::(anonymous namespace)::FailureSignalHandler()
    @     0x7f823f704630 (unknown)
    @     0x7f823f35d387 __GI_raise
    @     0x7f823f35ea78 __GI_abort
    @         0x1069970e jenallocx
    @          0xac64d60 malloc
    @     0x7f80c392529a getDiagnosticCommandArgumentInfoArray
    @     0x7f80c39257f2 Java_com_sun_management_internal_DiagnosticCommandImpl_getDiagnosticCommandInfo
    @     0x7f811bb6e197 (unknown)

Jni Diagnostic will use malloc(0)

/* According to ISO C it is perfectly legal for malloc to return zero if called with a zero argument */

jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command,
                                              int num_arg) {
  int i;
  jobject obj;
  jobjectArray result;
  dcmdArgInfo* dcmd_arg_info_array;
  jclass dcmdArgInfoCls;
  jclass arraysCls;
  jmethodID mid;
  jobject resultList;

  dcmd_arg_info_array = (dcmdArgInfo*) malloc(num_arg * sizeof(dcmdArgInfo));
  /* According to ISO C it is perfectly legal for malloc to return zero if called with a zero argument */
  if (dcmd_arg_info_array == NULL && num_arg != 0) {
    JNU_ThrowOutOfMemoryError(env, 0);
    return NULL;
  }

For jemalloc, malloc(0) is equivalent to malloc(1), the pr: jemalloc/jemalloc#1341 already remove the size=0 assert for malloc, but the assert in nallocx is not removed.

What I'm doing:

#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <array>
#include <memory>
#include <queue>
#include <atomic>
#include <mutex>
#include "jemalloc.h"

using namespace std;

int main() {
    void* ptr = je_malloc(0);
    std::cout << "MALLOC OK:" << ptr << std::endl;
    std::cout << "SIZE: " << jemalloc_usable_size(ptr) << std::endl;
    std::cout << "NALLOCX_SIZE: " << je_nallocx(0, 0) << std::endl;
    je_free(ptr);

    return 0;
}

g++ b.cpp -lpthread -ljemalloc -L./lib_debug

./a.out 
MALLOC OK:0x7efc9e408000
SIZE: 8
<jemalloc>: src/jemalloc.c:3963: Failed assertion: "size != 0"

Behavior after removal

./a.out 
MALLOC OK:0x7f095bc08000
SIZE: 8
NALLOCX_SIZE: 8

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.2
    • 3.1
    • 3.0
    • 2.5

@trueeyu trueeyu requested a review from a team as a code owner January 17, 2024 08:31
@github-actions github-actions bot added the 3.2 label Jan 17, 2024
@trueeyu
Copy link
Contributor Author

trueeyu commented Jan 18, 2024

@Mergifyio rebase

Signed-off-by: trueeyu <lxhhust350@qq.com>
Copy link
Contributor

mergify bot commented Jan 18, 2024

rebase

✅ Branch has been successfully rebased

Copy link

[FE Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@trueeyu trueeyu merged commit b328767 into StarRocks:main Jan 18, 2024
36 checks passed
Copy link

@Mergifyio backport branch-3.2

@github-actions github-actions bot removed the 3.2 label Jan 18, 2024
Copy link
Contributor

mergify bot commented Jan 18, 2024

backport branch-3.2

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jan 18, 2024
Signed-off-by: trueeyu <lxhhust350@qq.com>
(cherry picked from commit b328767)
wanpengfei-git pushed a commit that referenced this pull request Jan 18, 2024
@yongbingwang
Copy link
Contributor

@mergify backport branch-3.2-fp

Copy link
Contributor

mergify bot commented Jan 18, 2024

backport branch-3.2-fp

❌ No backport have been created

  • Backport to branch branch-3.2-fp failed

GitHub error: Branch not found

Seaven pushed a commit to Seaven/starrocks that referenced this pull request Jan 30, 2024
Signed-off-by: trueeyu <lxhhust350@qq.com>
Signed-off-by: Seaven <seaven_7@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants