Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7f0a6e8
Add StackOverflowError and stack overflow test
shai-almog Jan 25, 2026
e118b5e
Ensure StackOverflowError is emitted in native builds
shai-almog Jan 25, 2026
07b93de
Fix stack overflow test string concatenation
shai-almog Jan 25, 2026
4671519
Avoid native stack overflow in stack overflow test
shai-almog Jan 25, 2026
5b05177
Simplify stack overflow integration test
shai-almog Jan 25, 2026
529042a
Throw StackOverflowError before native stack exhaustion
shai-almog Jan 25, 2026
b2be761
Lower stack overflow depth limit
shai-almog Jan 25, 2026
d154515
Improve stack overflow test diagnostics
shai-almog Jan 26, 2026
db664bc
Add source-level asserts to stack overflow test
shai-almog Jan 26, 2026
f1ae59d
Expand stack overflow test diagnostics
shai-almog Jan 26, 2026
6d58242
Lower stack overflow depth limit further
shai-almog Jan 26, 2026
68ea77f
Revert overflow limit and add smoke run diagnostics
shai-almog Jan 26, 2026
1585541
Fix smoke output string building
shai-almog Jan 26, 2026
4aaed11
Expand stack overflow smoke diagnostics
shai-almog Jan 26, 2026
a46a3bc
Add smoke-phase markers to stack overflow test
shai-almog Jan 26, 2026
dba622c
Add probe run before smoke in stack overflow test
shai-almog Jan 27, 2026
138402f
Add probe markers for stack overflow test
shai-almog Jan 28, 2026
34f15d4
Assert probe output from native constant report
shai-almog Jan 28, 2026
f074c1f
Avoid string args in stack overflow test modes
shai-almog Jan 28, 2026
c19ba93
Refine smoke assertions for stack overflow test
shai-almog Jan 28, 2026
9fa04f3
Simplify smoke path to native markers
shai-almog Jan 29, 2026
ab5388f
Clarify smoke probe marker failure
shai-almog Jan 29, 2026
53e2bdb
Print smoke probe markers in a single native call
shai-almog Jan 29, 2026
9d84555
Differentiate smoke probe markers
shai-almog Jan 30, 2026
3085dad
Trying to cleanup the messy test
shai-almog Feb 4, 2026
a965a9a
Removed redundant code
shai-almog Feb 6, 2026
3d72958
Guard ASTORE optimizations to avoid non-object assignments (#4496)
shai-almog Feb 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions vm/ByteCodeTranslator/src/cn1_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ struct TryBlock {
};

#define CN1_MAX_STACK_CALL_DEPTH 1024
#define CN1_STACK_OVERFLOW_CALL_DEPTH_LIMIT CN1_MAX_STACK_CALL_DEPTH
#define CN1_MAX_OBJECT_STACK_DEPTH 16536

#define PER_THREAD_ALLOCATION_COUNT 4096
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ public static void markDependencies(List<ByteCodeClass> lst, String[] nativeSour
bc.markDependent(lst);
continue;
}
if(bc.clsName.equals("java_lang_StackOverflowError")) {
bc.markDependent(lst);
continue;
}
if(bc.clsName.equals("java_text_DateFormat")) {
bc.markDependent(lst);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,8 @@ public boolean assignTo(String varName, StringBuilder sb) {
sb.append(b);
return true;
}

public boolean isObject() {
return loadInstruction != null && loadInstruction.getOpcode() == Opcodes.AALOAD;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public boolean assignFrom(AssignableExpression ex, StringBuilder b) {
case Opcodes.DSTORE:
return ex.assignTo("dlocals_"+var+"_", b);
case Opcodes.ASTORE: {
if (!isObjectAssignable(ex)) {
return false;
}
if(getMethod() != null && getMethod().isBarebone()) {
if (!getMethod().isStatic() && var == 0) {
return ex.assignTo("__cn1ThisObject", b);
Expand All @@ -140,6 +143,37 @@ public boolean assignFrom(AssignableExpression ex, StringBuilder b) {
b.append("\n");
return false;
}

private boolean isObjectAssignable(AssignableExpression ex) {
if (ex instanceof Field) {
return ((Field) ex).isObject();
}
if (ex instanceof VarOp) {
return ((VarOp) ex).getOpcode() == Opcodes.ALOAD;
}
if (ex instanceof Ldc) {
Object value = ((Ldc) ex).getValue();
if (value instanceof Number) {
return false;
}
return value instanceof String
|| value instanceof org.objectweb.asm.Type
|| value instanceof org.objectweb.asm.Handle;
}
if (ex instanceof BasicInstruction) {
return ((BasicInstruction) ex).getOpcode() == Opcodes.ACONST_NULL;
}
if (ex instanceof ArrayLoadExpression) {
return ((ArrayLoadExpression) ex).isObject();
}
if (ex instanceof DupExpression) {
return true;
}
if (ex instanceof ArithmeticExpression) {
return false;
}
return false;
}

public boolean assignFrom(CustomInvoke ex, StringBuilder b) {
b.append(" /* VarOp.assignFrom */ ");
Expand Down
6 changes: 5 additions & 1 deletion vm/ByteCodeTranslator/src/nativeMethods.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "java_lang_NullPointerException.h"
#include "java_lang_Class.h"
#include "java_lang_System.h"
#include "java_lang_StackOverflowError.h"

#if defined(__APPLE__) && defined(__OBJC__)
#import <Foundation/Foundation.h>
Expand Down Expand Up @@ -1550,9 +1551,12 @@ void initMethodStack(CODENAME_ONE_THREAD_STATE, JAVA_OBJECT __cn1ThisObject, int
THROW_NULL_POINTER_EXCEPTION();
}
#endif
if (threadStateData->callStackOffset >= CN1_STACK_OVERFLOW_CALL_DEPTH_LIMIT - 1) {
throwException(threadStateData, __NEW_INSTANCE_java_lang_StackOverflowError(threadStateData));
return;
}
memset(&threadStateData->threadObjectStack[threadStateData->threadObjectStackOffset], 0, sizeof(struct elementStruct) * (localsStackSize + stackSize));
threadStateData->threadObjectStackOffset += localsStackSize + stackSize;
CODENAME_ONE_ASSERT(threadStateData->callStackOffset < CN1_MAX_STACK_CALL_DEPTH - 1);
threadStateData->callStackClass[threadStateData->callStackOffset] = classNameId;
threadStateData->callStackMethod[threadStateData->callStackOffset] = methodNameId;
threadStateData->callStackOffset++;
Expand Down
44 changes: 44 additions & 0 deletions vm/JavaAPI/src/java/lang/StackOverflowError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2012, Codename One and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if you
* need additional information or have any questions.
*/

package java.lang;
/**
* Thrown when a stack overflow occurs because an application recurses too deeply.
* Since: JDK1.0, CLDC 1.0
*/
public class StackOverflowError extends java.lang.VirtualMachineError{
/**
* Constructs a StackOverflowError with no detail message.
*/
public StackOverflowError(){
}

/**
* Constructs a StackOverflowError with the specified detail message.
* s - the detail message.
*/
public StackOverflowError(java.lang.String s){
super(s);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.codename1.tools.translator;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -16,6 +19,7 @@
* Helper class to manage external JDK compilers.
*/
public class CompilerHelper {
private static String lastErrorLog;

private static final Map<String, Path> availableJdks = new TreeMap<>();

Expand Down Expand Up @@ -157,11 +161,27 @@ public static int compile(Path jdkHome, List<String> args) throws IOException, I

ProcessBuilder pb = new ProcessBuilder(command);
// Inherit IO so we see errors in the log
pb.inheritIO();
pb.redirectErrorStream(true);
Process p = pb.start();
lastErrorLog = "";
try (InputStream is = p.getInputStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream()) {

byte[] data = new byte[8192]; // 8 KB buffer
int n;
while ((n = is.read(data)) != -1) {
buffer.write(data, 0, n);
}

lastErrorLog = buffer.toString("UTF-8");
}
return p.waitFor();
}

public static String getLastErrorLog() {
return lastErrorLog;
}

public static class CompilerConfig {
public final String jdkVersion;
public final Path jdkHome;
Expand Down
Loading
Loading