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

Segmentation Fault in rakudo 2016.08.1-55-gb1c444f built on MoarVM version 2016.08 #400

Open
l4mbd0x opened this issue Aug 31, 2016 · 3 comments

Comments

@l4mbd0x
Copy link

l4mbd0x commented Aug 31, 2016

Hi, I've implemented a simple bubbleSort and if I use large file inputs it gives this error.
bubbleSort alg: http://bpaste.net/show/3f41f8ec1ce4
example input: http://bpaste.net/show/0f4b8a2f8eaa
The error is happening in bubbleSort.

@niner
Copy link
Contributor

niner commented Aug 31, 2016

100 % reproducible. gdb gives me:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff78e99c0 in MVM_coerce_istrue (tc=0x6037c0, obj=0xeb9d30, res_reg=0x0, true_addr=0x7ffff5c6ed6e "\207\001\023", false_addr=0x7ffff5c6ed1a "\a", flip=1 '\001') at src/core/coerce.c:33
33              switch (bs == NULL ? MVM_BOOL_MODE_NOT_TYPE_OBJECT : bs->mode) {
(gdb) bt
#0  0x00007ffff78e99c0 in MVM_coerce_istrue (tc=0x6037c0, obj=0xeb9d30, res_reg=0x0, true_addr=0x7ffff5c6ed6e "\207\001\023", false_addr=0x7ffff5c6ed1a "\a", flip=1 '\001')
    at src/core/coerce.c:33
#1  0x00007ffff78cdee8 in MVM_interp_run (tc=tc@entry=0x6037c0, initial_invoke=0x48000000000001, invoke_data=0x0) at src/core/interp.c:242
#2  0x00007ffff798e9b9 in MVM_vm_run_file (instance=0x603010, filename=0x7fffffffdd6e "/home/nine/rakudo/install/share/perl6/runtime/perl6.moarvm") at src/moar.c:304
#3  0x00000000004010ab in main (argc=8, argv=0x7fffffffd718) at src/main.c:191
(gdb) p bs
$1 = (MVMBoolificationSpec *) 0x48000000000001
(gdb) p *obj
$2 = {header = {sc_forward_u = {forwarder = 0xffffffff00000019, sc = {sc_idx = 25, idx = 4294967295}, st = 0xffffffff00000019}, owner = 42458928, flags = 0, size = 0}, st = 0x7ffff51432f0}
(gdb) p *(obj->st)
$3 = {header = {sc_forward_u = {forwarder = 0x0, sc = {sc_idx = 0, idx = 0}, st = 0x0}, owner = 1, flags = 0, size = 72}, REPR = 0xe56aa0, REPR_data = 0x0, size = 4111741752, 
  type_check_cache_length = 32767, mode_flags = 0, type_check_cache = 0x287dee8, method_cache = 0x611d50, type_cache_id = 0, container_spec = 0x0, container_data = 0x0, 
  boolification_spec = 0x48000000000001, hll_owner = 0x6063b0, hll_role = 21586488, invoke = 0x7ffff5142ef0, invocation_spec = 0x7ffff51432f0, WHAT = 0x333df60, WHO = 0x0, HOW = 0x0, 
  paramet = {ric = {parameterizer = 0x0, lookup = 0x38000000000001}, erized = {parametric_type = 0x0, parameters = 0x38000000000001}}, HOW_sc = 0xe56620, HOW_idx = 0, method_cache_offset = 0, 
  method_cache_sc = 0x22a4b90, debug_name = 0xe58e98 "\031"}
(gdb) l
28      void MVM_coerce_istrue(MVMThreadContext *tc, MVMObject *obj, MVMRegister *res_reg,
29              MVMuint8 *true_addr, MVMuint8 *false_addr, MVMuint8 flip) {
30          MVMint64 result = 0;
31          if (!MVM_is_null(tc, obj)) {
32              MVMBoolificationSpec *bs = obj->st->boolification_spec;
33              switch (bs == NULL ? MVM_BOOL_MODE_NOT_TYPE_OBJECT : bs->mode) {
34                  case MVM_BOOL_MODE_CALL_METHOD: {
35                      MVMObject *code = MVM_frame_find_invokee(tc, bs->method, NULL);
36                      MVMCallsite *inv_arg_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG);
37                      if (res_reg) {

@moritz
Copy link
Contributor

moritz commented Aug 31, 2016

valgrind output:

Invalid read of size 4
   at 0x4FAFA50: MVM_coerce_istrue (in /home/mlenz/p6/rakudo/install/lib/libmoar.so)
   by 0x4F9764F: MVM_interp_run (in /home/mlenz/p6/rakudo/install/lib/libmoar.so)
   by 0x5053FD8: MVM_vm_run_file (in /home/mlenz/p6/rakudo/install/lib/libmoar.so)
   by 0x400FBE: main (in /home/mlenz/p6/rakudo/install/bin/moar)
 Address 0x48000000000009 is not stack'd, malloc'd or (recently) free'd


Process terminating with default action of signal 11 (SIGSEGV)
 General Protection Fault
   at 0x4FAFA50: MVM_coerce_istrue (in /home/mlenz/p6/rakudo/install/lib/libmoar.so)
   by 0x4F9764F: MVM_interp_run (in /home/mlenz/p6/rakudo/install/lib/libmoar.so)
   by 0x5053FD8: MVM_vm_run_file (in /home/mlenz/p6/rakudo/install/lib/libmoar.so)
   by 0x400FBE: main (in /home/mlenz/p6/rakudo/install/bin/moar)

Here's the script reproduced, in case the paste bin doesn't like us:

#!/usr/bin/perl6
# bubble sorting algorithm, time complexities (Best = n, Average = n², Worst = n²)

my $name = @*ARGS.pop;
sub store($name) { 
        my @tmp; for "$name.txt".IO.words -> $word { @tmp.push($word); }; return @tmp; 
}
sub bubbleSort(@tmp) {
        for ^@tmp -> $i { for $i ^..^ @tmp -> $j { @tmp[$j] < @tmp[$i] and @tmp[$i,$j] = @tmp[$j,$i]; } }
}

my @array = store $name;
bubbleSort @array;

The input data is the output of seq 0 4999.

@l4mbd0x
Copy link
Author

l4mbd0x commented Sep 1, 2016

Some findings:

  1. After running the code again a few times without touching the code it generates another error report:
    Internal error: invalid thread ID 58765088 in GC work pass

  2. After looking at each individual part of the code I found out that the first '^' of the expression: $i ^..^ @tmp is the reason for the issue.

  3. Instead of $i ^..^ @tmp change it to ($i+1)..^ @tmp and semantically it won't change the result, but won't give any errors. Wouldn't it be the implementation of '^' for the lower boundary of the range the cause of this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants