Skip to content

Commit

Permalink
#431 Lua4J Demo compiled to WebAssembly does not work (#435)
Browse files Browse the repository at this point in the history
* #431 Lua4J Demo compiled to WebAssembly does not work
* #430 RuntimeError:unreachable error from Vue.js WebAssembly integration test
  • Loading branch information
mirkosertic authored Jul 29, 2020
1 parent 390b4ba commit 857bbe3
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 4 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ jobs:
- uses: joschi/setup-jdk@v1
with:
java-version: ${{ matrix.java }}
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: wget https://apt.llvm.org/llvm.sh
- run: chmod +x llvm.sh
- run: sudo ./llvm.sh 10
Expand All @@ -49,6 +55,12 @@ jobs:
- uses: joschi/setup-jdk@v1
with:
java-version: ${{ matrix.java }}
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: wget https://apt.llvm.org/llvm.sh
- run: chmod +x llvm.sh
- run: sudo ./llvm.sh 10
Expand All @@ -64,6 +76,12 @@ jobs:
- uses: joschi/setup-jdk@v1
with:
java-version: ${{ matrix.java }}
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: wget https://apt.llvm.org/llvm.sh
- run: chmod +x llvm.sh
- run: sudo ./llvm.sh 10
Expand All @@ -79,6 +97,12 @@ jobs:
- uses: joschi/setup-jdk@v1
with:
java-version: ${{ matrix.java }}
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: wget https://apt.llvm.org/llvm.sh
- run: chmod +x llvm.sh
- run: sudo ./llvm.sh 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static void internalFree(final int current) {
final int currentNext = Address.getIntValue(current, 4);

if (currentPrev != 0) {
Address.setIntValue(current, 4, currentNext);
Address.setIntValue(currentPrev, 4, currentNext);
} else {
Address.setIntValue(heapBase, 8, currentNext);
}
Expand Down Expand Up @@ -339,12 +339,14 @@ public static boolean isUsedByStaticData(final int aOwningBlock) {
public static boolean isUsedByStaticDataUserSpace(final int aPtrToObject) {
int dataStart = 0;
final int theDataEnd = Address.getDataEnd();

while(dataStart <= theDataEnd) {
if (Address.getIntValue(dataStart, 0) == aPtrToObject) {
return true;
}
dataStart += 4;
}

return false;
}

Expand All @@ -357,6 +359,7 @@ public static boolean isUsedByStackUserSpace(final int aPtrToObject) {
if (Address.systemHasStack() == 0) {
return false;
}

int stackStart = Address.getStackTop();
final int memorySize = Address.getMemorySize();
while(stackStart + 4 < memorySize) {
Expand All @@ -379,6 +382,8 @@ public static boolean isUsedByHeapUserSpace(final int aPtrToObject) {

int current = Address.getIntValue(heapBase, 8);
while(current != 0) {
final int next = Address.getIntValue(current, 4);

// Ignore self reference
if (allocationPtr != current) {
final int theSize = Address.getIntValue(current, 0);
Expand All @@ -388,7 +393,7 @@ public static boolean isUsedByHeapUserSpace(final int aPtrToObject) {
}
}
}
current = Address.getIntValue(current, 4);
current = next;
}

return false;
Expand Down Expand Up @@ -423,7 +428,7 @@ public static int IncrementalGC(final int blockLimit) {
final int next = Address.getIntValue(current, 4);
final int survivorCount = Address.getIntValue(current, 8);
if (currentEpoch % survivorCount == 0) {
if (!isUsedByHeap(current) && !isUsedByStack(current) && !(isUsedByStaticData(current)) && (!isUsedAsCallback(current + 12))) {
if (!isUsedByHeap(current) && !isUsedByStack(current) && !(isUsedByStaticData(current)) && (!isUsedAsCallback(current + 16))) {
internalFree(current);
freeCounter++;
} else {
Expand All @@ -436,6 +441,7 @@ public static int IncrementalGC(final int blockLimit) {
// We have reached the limit for the current run
// We save the next block to proceed and exit here
Address.setIntValue(heapBase, 12, next);

return stepCounter;
}
}
Expand Down
67 changes: 67 additions & 0 deletions core/src/test/java/de/mirkosertic/bytecoder/classlib/GCTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2020 Mirko Sertic
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.mirkosertic.bytecoder.classlib;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import de.mirkosertic.bytecoder.api.web.ClickEvent;
import de.mirkosertic.bytecoder.api.web.EventListener;
import de.mirkosertic.bytecoder.api.web.EventTarget;
import de.mirkosertic.bytecoder.api.web.Window;
import de.mirkosertic.bytecoder.backend.CompileTarget;
import de.mirkosertic.bytecoder.unittest.BytecoderTestOption;
import de.mirkosertic.bytecoder.unittest.BytecoderTestOptions;
import de.mirkosertic.bytecoder.unittest.BytecoderUnitTestRunner;

@RunWith(BytecoderUnitTestRunner.class)
@BytecoderTestOptions(value = {
@BytecoderTestOption(backend = CompileTarget.BackendType.wasm, preferStackifier = true),
}, includeJVM = false)
public class GCTest {

private static EventListener<ClickEvent> registerClicklistenerOn(final EventTarget target) {
final EventListener<ClickEvent> listener = new EventListener<ClickEvent>() {
@Override
public void run(ClickEvent aEvent) {

}
};
target.addEventListener("click", listener);
return listener;
}

@Test
public void testListenerGC() {
final Window w = Window.window();
final EventListener<ClickEvent> listener = registerClicklistenerOn(w);
final int ptr = Address.ptrOf(listener);
Assert.assertTrue(MemoryManager.isUsedAsCallback(ptr));
Assert.assertFalse(MemoryManager.isUsedByHeapUserSpace(ptr));
Assert.assertTrue(MemoryManager.isUsedByStackUserSpace(ptr));
Assert.assertFalse(MemoryManager.isUsedByStaticDataUserSpace(ptr));
Assert.assertTrue(MemoryManager.indexInAllocationList(ptr) >= 0);

MemoryManager.GC();

Assert.assertTrue(MemoryManager.isUsedAsCallback(ptr));
Assert.assertFalse(MemoryManager.isUsedByHeapUserSpace(ptr));
Assert.assertTrue(MemoryManager.isUsedByStackUserSpace(ptr));
Assert.assertFalse(MemoryManager.isUsedByStaticDataUserSpace(ptr));
Assert.assertTrue(MemoryManager.indexInAllocationList(ptr) >= 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2020 Mirko Sertic
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.mirkosertic.bytecoder.classlib;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import de.mirkosertic.bytecoder.api.web.ClickEvent;
import de.mirkosertic.bytecoder.api.web.EventListener;
import de.mirkosertic.bytecoder.api.web.EventTarget;
import de.mirkosertic.bytecoder.api.web.Window;
import de.mirkosertic.bytecoder.backend.CompileTarget;
import de.mirkosertic.bytecoder.unittest.BytecoderTestOption;
import de.mirkosertic.bytecoder.unittest.BytecoderTestOptions;
import de.mirkosertic.bytecoder.unittest.BytecoderUnitTestRunner;

@RunWith(BytecoderUnitTestRunner.class)
@BytecoderTestOptions(value = {
@BytecoderTestOption(backend = CompileTarget.BackendType.wasm_llvm, preferStackifier = true),
}, includeJVM = false)
public class GCTestStackless {

private static EventListener<ClickEvent> registerClicklistenerOn(final EventTarget target) {
final EventListener<ClickEvent> listener = new EventListener<ClickEvent>() {
@Override
public void run(ClickEvent aEvent) {

}
};
target.addEventListener("click", listener);
return listener;
}

@Test
public void testListenerGC() {
final Window w = Window.window();
final EventListener<ClickEvent> listener = registerClicklistenerOn(w);
final int ptr = Address.ptrOf(listener);
Assert.assertTrue(MemoryManager.isUsedAsCallback(ptr));
Assert.assertFalse(MemoryManager.isUsedByHeapUserSpace(ptr));
Assert.assertFalse(MemoryManager.isUsedByStackUserSpace(ptr));
Assert.assertFalse(MemoryManager.isUsedByStaticDataUserSpace(ptr));
Assert.assertTrue(MemoryManager.indexInAllocationList(ptr) >= 0);

MemoryManager.GC();

Assert.assertTrue(MemoryManager.isUsedAsCallback(ptr));
Assert.assertFalse(MemoryManager.isUsedByHeapUserSpace(ptr));
Assert.assertFalse(MemoryManager.isUsedByStackUserSpace(ptr));
Assert.assertFalse(MemoryManager.isUsedByStaticDataUserSpace(ptr));
Assert.assertTrue(MemoryManager.indexInAllocationList(ptr) >= 0);
}
}
2 changes: 1 addition & 1 deletion maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
<version>[24.1.1,)</version>
</dependency>

<dependency>
Expand Down

0 comments on commit 857bbe3

Please sign in to comment.