Skip to content

Commit 99a3925

Browse files
committed
Fix error in stack management, all primitives now share single stack
1 parent 375bbde commit 99a3925

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

net.tascalate.javaflow.api/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
3434
<attributes>
3535
<attribute name="maven.pomderived" value="true"/>
36+
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
3637
</attributes>
3738
</classpathentry>
3839
<classpathentry kind="output" path="target/classes"/>

net.tascalate.javaflow.api/.project

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@
55
This project is based on completely re-worked Apache Jakarta Commons JavaFlow library. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
66
<projects/>
77
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
10+
</buildCommand>
811
<buildCommand>
912
<name>org.eclipse.jdt.core.javabuilder</name>
1013
</buildCommand>
14+
<buildCommand>
15+
<name>org.eclipse.wst.validation.validationbuilder</name>
16+
</buildCommand>
1117
<buildCommand>
1218
<name>org.eclipse.m2e.core.maven2Builder</name>
1319
</buildCommand>
1420
</buildSpec>
1521
<natures>
22+
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
23+
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
1624
<nature>org.eclipse.m2e.core.maven2Nature</nature>
1725
<nature>org.eclipse.jdt.core.javanature</nature>
26+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
1827
</natures>
1928
</projectDescription>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
23
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
34
org.eclipse.jdt.core.compiler.compliance=1.5
5+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
47
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
58
org.eclipse.jdt.core.compiler.source=1.5

net.tascalate.javaflow.api/src/main/java/org/apache/commons/javaflow/core/Stack.java

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,20 @@ public class Stack implements Serializable {
3636
private static final Log log = LogFactory.getLog(Stack.class);
3737
private static final long serialVersionUID = 3L;
3838

39-
private int[] istack;
4039
private long[] pstack;
4140
private Object[] ostack;
4241
private Object[] rstack;
43-
private int iTop, fTop, dTop, lTop, oTop, rTop;
42+
private int dTop, fTop, lTop, iTop, oTop, rTop;
4443
protected Runnable runnable;
4544

4645
Stack(Runnable pRunnable) {
47-
istack = new int[8];
4846
pstack = new long[8];
4947
ostack = new Object[8];
5048
rstack = new Object[4];
5149
runnable = pRunnable;
5250
}
5351

5452
Stack(final Stack pParent) {
55-
istack = new int[pParent.istack.length];
5653
pstack = new long[pParent.pstack.length];
5754
ostack = new Object[pParent.ostack.length];
5855
rstack = new Object[pParent.rstack.length];
@@ -62,8 +59,7 @@ public class Stack implements Serializable {
6259
lTop = pParent.lTop;
6360
oTop = pParent.oTop;
6461
rTop = pParent.rTop;
65-
System.arraycopy(pParent.istack, 0, istack, 0, iTop);
66-
System.arraycopy(pParent.pstack, 0, pstack, 0, dTop + fTop + lTop);
62+
System.arraycopy(pParent.pstack, 0, pstack, 0, dTop + fTop + lTop + iTop);
6763
System.arraycopy(pParent.ostack, 0, ostack, 0, oTop);
6864
System.arraycopy(pParent.rstack, 0, rstack, 0, rTop);
6965
runnable = pParent.runnable;
@@ -78,8 +74,8 @@ public final double popDouble() {
7874
throw new EmptyStackException("pop double");
7975
}
8076

81-
final double d = Double.longBitsToDouble(popPrimitive());
8277
--dTop;
78+
final double d = Double.longBitsToDouble(popPrimitive());
8379
if (log.isDebugEnabled()) {
8480
log.debug("pop double " + d + " " + getStats());
8581
}
@@ -95,8 +91,8 @@ public final float popFloat() {
9591
throw new EmptyStackException("pop float");
9692
}
9793

98-
final float f = Float.intBitsToFloat((int)popPrimitive());
9994
--fTop;
95+
final float f = Float.intBitsToFloat((int)popPrimitive());
10096
if (log.isDebugEnabled()) {
10197
log.debug("pop float " + f + " " + getStats());
10298
}
@@ -112,8 +108,8 @@ public final long popLong() {
112108
throw new EmptyStackException("pop long");
113109
}
114110

115-
final long l = popPrimitive();
116111
--lTop;
112+
final long l = popPrimitive();
117113
if (log.isDebugEnabled()) {
118114
log.debug("pop long " + l + " " + getStats());
119115
}
@@ -129,7 +125,8 @@ public final int popInt() {
129125
throw new EmptyStackException("pop int");
130126
}
131127

132-
final int i = istack[--iTop];
128+
--iTop;
129+
final int i = (int)popPrimitive();
133130
if (log.isDebugEnabled()) {
134131
log.debug("pop int " + i + " " + getStats());
135132
}
@@ -208,14 +205,11 @@ public final void pushInt(int i) {
208205
if (log.isDebugEnabled()) {
209206
log.debug("push int " + i + " " + getStats());
210207
}
211-
if (iTop == istack.length) {
212-
int[] hlp = new int[Math.max(8, istack.length * 2)];
213-
System.arraycopy(istack, 0, hlp, 0, istack.length);
214-
istack = hlp;
215-
}
216-
istack[iTop++] = i;
208+
ensurePrimitivesStackSize();
209+
pushPrimitive(i);
210+
iTop++;
217211
}
218-
212+
219213
public final void pushObject(Object o) {
220214
if (log.isDebugEnabled()) {
221215
log.debug("push object " + ReflectionUtils.descriptionOfObject(o) + " " + getStats());
@@ -305,32 +299,32 @@ public String toString() {
305299
return getContent();
306300
}
307301

302+
private final int pTop() {
303+
return dTop + fTop + lTop + iTop;
304+
}
305+
308306
private final void pushPrimitive(long value) {
309-
pstack[dTop + fTop + lTop] = value;
307+
pstack[pTop()] = value;
310308
}
311309

312310
private final long popPrimitive() {
313-
return pstack[dTop + fTop + lTop];
311+
return pstack[pTop()];
314312
}
315313

316314
private final void ensurePrimitivesStackSize() {
317-
if (dTop + fTop + lTop == pstack.length) {
315+
if (pTop() == pstack.length) {
318316
long[] hlp = new long[Math.max(8, pstack.length * 2)];
319317
System.arraycopy(pstack, 0, hlp, 0, pstack.length);
320318
pstack = hlp;
321319
}
322320
}
323321

324322
private void writeObject(ObjectOutputStream s) throws IOException {
325-
s.writeInt(iTop);
326-
for (int i = 0; i < iTop; i++) {
327-
s.writeInt(istack[i]);
328-
}
329-
330323
s.writeInt(dTop);
331324
s.writeInt(fTop);
332325
s.writeInt(lTop);
333-
int pTop = dTop + fTop + lTop;
326+
s.writeInt(iTop);
327+
int pTop = pTop();
334328
for (int i = 0; i < pTop; i++) {
335329
s.writeLong(pstack[i]);
336330
}
@@ -349,16 +343,11 @@ private void writeObject(ObjectOutputStream s) throws IOException {
349343
}
350344

351345
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
352-
iTop = s.readInt();
353-
istack = new int[iTop];
354-
for (int i = 0; i < iTop; i++) {
355-
istack[i] = s.readInt();
356-
}
357-
358346
dTop = s.readInt();
359347
fTop = s.readInt();
360348
lTop = s.readInt();
361-
int pTop = dTop + fTop + lTop;
349+
iTop = s.readInt();
350+
int pTop = pTop();
362351
pstack = new long[pTop];
363352
for (int i = 0; i < pTop; i++) {
364353
pstack[i] = s.readLong();

0 commit comments

Comments
 (0)