mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fixes stack overflow in certain cases
This commit is contained in:
parent
27291367b7
commit
f892748174
|
@ -51,11 +51,10 @@ public class GraphIndexer {
|
|||
byte[] state = new byte[sz];
|
||||
int lastIndex = 0;
|
||||
int lastVisitIndex = 0;
|
||||
int[] stack = new int[sz * 2];
|
||||
int stackSize = 0;
|
||||
stack[stackSize++] = loopGraph.loopAt(0) != null ? loopGraph.loopAt(0).getHead() : 0;
|
||||
while (stackSize > 0) {
|
||||
int node = stack[--stackSize];
|
||||
IntegerStack stack = new IntegerStack(sz * 2);
|
||||
stack.push(loopGraph.loopAt(0) != null ? loopGraph.loopAt(0).getHead() : 0);
|
||||
while (!stack.isEmpty()) {
|
||||
int node = stack.pop();
|
||||
switch (state[node]) {
|
||||
case VISITING: {
|
||||
state[node] = VISITED;
|
||||
|
@ -65,7 +64,7 @@ public class GraphIndexer {
|
|||
case NONE: {
|
||||
visitIndex[node] = lastVisitIndex++;
|
||||
state[node] = VISITING;
|
||||
stack[stackSize++] = node;
|
||||
stack.push(node);
|
||||
int[] successors = graph.outgoingEdges(node);
|
||||
LoopEntrance[] edges = new LoopEntrance[successors.length];
|
||||
for (int i = 0; i < edges.length; ++i) {
|
||||
|
@ -87,7 +86,7 @@ public class GraphIndexer {
|
|||
int next = edge.follower;
|
||||
switch (state[next]) {
|
||||
case NONE:
|
||||
stack[stackSize++] = next;
|
||||
stack.push(next);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -15,10 +15,7 @@
|
|||
*/
|
||||
package org.teavm.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -81,19 +78,18 @@ public class LoopGraph implements Graph {
|
|||
walkIndexes = new int[sz];
|
||||
LoopImpl[] createdLoops = new LoopImpl[sz];
|
||||
LoopFrame[] frames = new LoopFrame[sz];
|
||||
LoopFrame[] stack = new LoopFrame[sz * 4];
|
||||
int stackSize = 0;
|
||||
Deque<LoopFrame> stack = new ArrayDeque<>(sz * 4);
|
||||
LoopFrame rootFrame = new LoopFrame();
|
||||
stack[stackSize++] = rootFrame;
|
||||
stack.push(rootFrame);
|
||||
int walkIndex = 0;
|
||||
int lastSortIndex = sz - 1;
|
||||
int loopSetSize = 0;
|
||||
while (stackSize > 0) {
|
||||
LoopFrame frame = stack[--stackSize];
|
||||
while (!stack.isEmpty()) {
|
||||
LoopFrame frame = stack.pop();
|
||||
if (frames[frame.index] == null) {
|
||||
frames[frame.index] = frame;
|
||||
frame.walkIndex = walkIndex++;
|
||||
stack[stackSize++] = frame;
|
||||
stack.push(frame);
|
||||
int[] targetEdges = graph.outgoingEdges(frame.index);
|
||||
for (int i = 0; i < targetEdges.length; ++i) {
|
||||
int next = targetEdges[i];
|
||||
|
@ -101,7 +97,7 @@ public class LoopGraph implements Graph {
|
|||
if (nextFrame == null) {
|
||||
nextFrame = new LoopFrame();
|
||||
nextFrame.index = next;
|
||||
stack[stackSize++] = nextFrame;
|
||||
stack.push(nextFrame);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user