Skip to content

Minimal runtime GC collects pinned objects. #1646

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

Closed
forcepusher opened this issue Jan 30, 2021 · 2 comments · Fixed by #1650
Closed

Minimal runtime GC collects pinned objects. #1646

forcepusher opened this issue Jan 30, 2021 · 2 comments · Fixed by #1650
Labels

Comments

@forcepusher
Copy link
Contributor

forcepusher commented Jan 30, 2021

UPDATE: See the short version of the repro.
However this one might still be useful because it has to pass the test.

Repro: MinimalGCBugRepro.zip
Steps to reproduce:

  1. npm run asbuild:incremental then npm test.
  2. Observe the expected repeating trace 123456.
  3. npm run asbuild:minimal then npm test.
  4. Observe the unexpected traces with random numbers.

Reproduction overview:

export class SomeClass {
  public someArray: StaticArray<SomeNestedClass>;

  public constructor() {
    this.someArray = new StaticArray<SomeNestedClass>(1);
    this.someArray[0] = new SomeNestedClass();
  }

  public growArray(): void {
    const resizedArray = new StaticArray<SomeNestedClass>(this.someArray.length * 2);
    memory.copy(changetype<usize>(resizedArray), changetype<usize>(this.someArray),
      offsetof<SomeNestedClass>() * this.someArray.length);
    this.someArray = resizedArray;
  }

  public outputFirstArrayElement(): void {
    trace(this.someArray[0].someField.toString());
  }
}

class SomeNestedClass {
  public someField: i32 = 123456;
}
const myModule = require("..");

const someClass = new myModule.SomeClass();
myModule.__pin(someClass);
someClass.growArray();
someClass.outputFirstArrayElement();
myModule.__collect();
someClass.growArray();
someClass.outputFirstArrayElement();
@forcepusher forcepusher changed the title GC minimal runtime collects referenced items. Minimal runtime GC collects pinned items. Jan 30, 2021
@forcepusher
Copy link
Contributor Author

forcepusher commented Jan 30, 2021

Seems like none of the memory copying magic, neither the StaticArray needed to break it. A regular Array drops the references to classes anyway.

Repro v3: MinimalGCBugReproV3.zip
Steps to reproduce:

  1. npm run asbuild:incremental then npm test.
  2. Observe the expected repeating trace 123456.
  3. npm run asbuild:minimal then npm test.
  4. Observe the error after a second trace.

Bonus: Web Editor reproduction link. Switching to incremental mitigates it.

Reproduction overview:

export class SomeClass {
  public someArray: Array<SomeNestedClass>;

  public constructor() {
    this.someArray = new Array<SomeNestedClass>(1);
    this.someArray[0] = new SomeNestedClass();
  }

  public outputFirstArrayElement(): void {
    trace(this.someArray[0].someField.toString());
  }
}

class SomeNestedClass {
  public someField: i32 = 123456;
}
const myModule = require("..");

const someClass = new myModule.SomeClass();
myModule.__pin(someClass);
someClass.outputFirstArrayElement();
myModule.__collect();
someClass.outputFirstArrayElement();
myModule.__collect();
someClass.outputFirstArrayElement();

@forcepusher forcepusher changed the title Minimal runtime GC collects pinned items. Minimal runtime GC collects pinned objects. Jan 30, 2021
@dcodeIO dcodeIO added the bug label Jan 31, 2021
@dcodeIO
Copy link
Member

dcodeIO commented Jan 31, 2021

Thanks for digging through this, the repro was super helpful :) Should be fixed with the next release at 0 UTC.

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

Successfully merging a pull request may close this issue.

2 participants