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

Crash in garbage collector when heap is resized #59

Closed
vidya88 opened this issue Sep 24, 2019 · 2 comments
Closed

Crash in garbage collector when heap is resized #59

vidya88 opened this issue Sep 24, 2019 · 2 comments

Comments

@vidya88
Copy link

vidya88 commented Sep 24, 2019

@asahi3g commented on Mar 12

To Reproduce

package main
func fooB(path str) {
	var ss []i32
	var INIT_HEAP_SIZE i32 = 32 * (1 << 20) // TODO : should be tested against real cx/config.go::INIT_HEAP_SIZE
	for i := 0; i < INIT_HEAP_SIZE; i++ {
		ss = append(ss, 1)
	}
}
func fooA(path str, filename str, s f32, r f32) {
	fooB(sprintf("%s/%s", path, filename))
}
func main()() {
	fooA("test", "A", 1.0, 2.0)
}

Expected behavior

Screenshots

error: tests/pending_20.cx:7, CX_RUNTIME_ERROR, runtime error: index out of range
===Callstack===
>>> fooB()
Inputs
error: tests/pending_20.cx:7, CX_RUNTIME_ERROR, runtime error: slice bounds out of range
===Callstack===
>>> fooB()
Inputs
error: tests/pending_20.cx:7, CX_RUNTIME_ERROR, runtime error: slice bounds out of range
===Callstack===
>>> fooB()
Inputs
panic: runtime error: index out of range [recovered]
	panic: runtime error: slice bounds out of range [recovered]
	panic: runtime error: slice bounds out of range [recovered]
	panic: runtime error: slice bounds out of range

goroutine 1 [running, locked to thread]:
github.com/skycoin/cx/cx.ReadStr(0x14, 0xc00019b680, 0x9bef14, 0x3)
	/home/reash/go/src/github.com/skycoin/cx/cx/op.go:494 +0x244
github.com/skycoin/cx/cx.getNonCollectionValue(0x14, 0xc00019b680, 0xc00019b680, 0x9bef14, 0x3, 0x9ae6c0, 0x14)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:853 +0x8ad
github.com/skycoin/cx/cx.GetPrintableValue(0x14, 0xc00019b680, 0xc0005600a8, 0x2)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:963 +0x7d6
github.com/skycoin/cx/cx.(*CXProgram).PrintStack(0xc0004de000)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:53 +0x2b1
github.com/skycoin/cx/cx.runtimeErrorInfo(0x9547e0, 0xd83b40, 0xd83b01, 0x5)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:814 +0x2ef
github.com/skycoin/cx/cx.RuntimeError()
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:841 +0x16d
panic(0x9547e0, 0xd83b40)
	/usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/skycoin/cx/cx.ReadStr(0x14, 0xc00019b680, 0x9bef14, 0x3)
	/home/reash/go/src/github.com/skycoin/cx/cx/op.go:494 +0x244
github.com/skycoin/cx/cx.getNonCollectionValue(0x14, 0xc00019b680, 0xc00019b680, 0x9bef14, 0x3, 0x9ae6c0, 0x14)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:853 +0x8ad
github.com/skycoin/cx/cx.GetPrintableValue(0x14, 0xc00019b680, 0xc000560838, 0x2)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:963 +0x7d6
github.com/skycoin/cx/cx.(*CXProgram).PrintStack(0xc0004de000)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:53 +0x2b1
github.com/skycoin/cx/cx.runtimeErrorInfo(0x9547e0, 0xd83b40, 0xd83b01, 0x5)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:814 +0x2ef
github.com/skycoin/cx/cx.RuntimeError()
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:841 +0x16d
panic(0x9547e0, 0xd83b40)
	/usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/skycoin/cx/cx.ReadStr(0x14, 0xc00019b680, 0x9bef14, 0x3)
	/home/reash/go/src/github.com/skycoin/cx/cx/op.go:494 +0x244
github.com/skycoin/cx/cx.getNonCollectionValue(0x14, 0xc00019b680, 0xc00019b680, 0x9bef14, 0x3, 0x9ae6c0, 0x14)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:853 +0x8ad
github.com/skycoin/cx/cx.GetPrintableValue(0x14, 0xc00019b680, 0xc000826fc8, 0x2)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:963 +0x7d6
github.com/skycoin/cx/cx.(*CXProgram).PrintStack(0xc0004de000)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:53 +0x2b1
github.com/skycoin/cx/cx.runtimeErrorInfo(0x9547e0, 0xd83b30, 0xd83b01, 0x5)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:814 +0x2ef
github.com/skycoin/cx/cx.RuntimeError()
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:841 +0x16d
panic(0x9547e0, 0xd83b30)
	/usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/skycoin/cx/cx.MarkAndCompact()
	/home/reash/go/src/github.com/skycoin/cx/cx/op.go:196 +0x50c
github.com/skycoin/cx/cx.AllocateSeq(0x200011, 0x4)
	/home/reash/go/src/github.com/skycoin/cx/cx/op.go:263 +0x8a
github.com/skycoin/cx/cx.SliceResize(0x10003f0010003f, 0x40001, 0x4, 0x100018)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:672 +0x361
github.com/skycoin/cx/cx.SliceAppend(0x10003f0010003f, 0xc0002c8018, 0x4, 0x1fffec, 0xc000827540)
	/home/reash/go/src/github.com/skycoin/cx/cx/utilities.go:701 +0x54
github.com/skycoin/cx/cx.opAppend(0xc000079360, 0x14)
	/home/reash/go/src/github.com/skycoin/cx/cx/op_und.go:405 +0x219
github.com/skycoin/cx/cx.init.1.func1(0xc0004de000)
	/home/reash/go/src/github.com/skycoin/cx/cx/opcodes_bare.go:1476 +0x1664
github.com/skycoin/cx/cx.init.3.func1(0xc0004de000)
	/home/reash/go/src/github.com/skycoin/cx/cx/opcodes_extra.go:780 +0x14c6
github.com/skycoin/cx/cx.(*CXCall).ccall(0xc0001c2030, 0xc0004de000, 0x0, 0x0)
	/home/reash/go/src/github.com/skycoin/cx/cx/execute.go:310 +0x331
github.com/skycoin/cx/cx.(*CXProgram).Run(0xc0004de000, 0x9bed01, 0xc0005618c8, 0xffffffffffffffff, 0x0, 0x0)
	/home/reash/go/src/github.com/skycoin/cx/cx/execute.go:119 +0x117
github.com/skycoin/cx/cx.(*CXProgram).RunCompiled(0xc0004de000, 0x0, 0x0, 0x0, 0x0, 0xc000180e70, 0x0)
	/home/reash/go/src/github.com/skycoin/cx/cx/execute.go:201 +0x238
main.main()
	/home/reash/go/src/github.com/skycoin/cx/cxgo/cxgo.nn.go:8885 +0xce2

Desktop:

  • OS: Linux
  • CX Version : 0.6.1, d8775bf
@vidya88
Copy link
Author

vidya88 commented Sep 24, 2019

@amherag commented on Sep 9

This seems to be fixed now. For the record, I ran this code (which uses 2 Mb of heap memory as INIT_HEAP_SIZE; I also tried with 4 Mb and it worked, which means that CX is correctly expanding the heap size beyond INIT_HEAP_SIZE).

package main
func fooB(path str) {
	var ss []i32
	var INIT_HEAP_SIZE i32 = 2097152
	for i := 0; i < INIT_HEAP_SIZE; i++ {
		ss = append(ss, 1)
	}
}
func fooA(path str, filename str, s f32, r f32) {
	fooB(sprintf("%s/%s", path, filename))
}
func main()() {
	fooA("test", "A", 1.0, 2.0)
}

@SkycoinSynth
Copy link
Contributor

Resolved

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

2 participants