Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2562e5a
Add StackOverflowError and stack overflow test
shai-almog Jan 25, 2026
8bd4305
Ensure StackOverflowError is emitted in native builds
shai-almog Jan 25, 2026
3e5fc92
Fix stack overflow test string concatenation
shai-almog Jan 25, 2026
2c68593
Avoid native stack overflow in stack overflow test
shai-almog Jan 25, 2026
f09c9e0
Simplify stack overflow integration test
shai-almog Jan 25, 2026
0b04243
Throw StackOverflowError before native stack exhaustion
shai-almog Jan 25, 2026
526bbd6
Lower stack overflow depth limit
shai-almog Jan 25, 2026
0889899
Improve stack overflow test diagnostics
shai-almog Jan 26, 2026
623762e
Add source-level asserts to stack overflow test
shai-almog Jan 26, 2026
a4cde1c
Expand stack overflow test diagnostics
shai-almog Jan 26, 2026
c116ec5
Lower stack overflow depth limit further
shai-almog Jan 26, 2026
e95a039
Revert overflow limit and add smoke run diagnostics
shai-almog Jan 26, 2026
e1f8382
Fix smoke output string building
shai-almog Jan 26, 2026
7adec9c
Expand stack overflow smoke diagnostics
shai-almog Jan 26, 2026
2a56269
Add smoke-phase markers to stack overflow test
shai-almog Jan 26, 2026
300b782
Add probe run before smoke in stack overflow test
shai-almog Jan 27, 2026
6bea1e8
Add probe markers for stack overflow test
shai-almog Jan 28, 2026
e0967db
Assert probe output from native constant report
shai-almog Jan 28, 2026
3746a1a
Avoid string args in stack overflow test modes
shai-almog Jan 28, 2026
5a05a69
Refine smoke assertions for stack overflow test
shai-almog Jan 28, 2026
0788d4c
Simplify smoke path to native markers
shai-almog Jan 29, 2026
8e273f1
Clarify smoke probe marker failure
shai-almog Jan 29, 2026
1f5616f
Print smoke probe markers in a single native call
shai-almog Jan 29, 2026
5fc47c2
Differentiate smoke probe markers
shai-almog Jan 30, 2026
fb3ec1a
Trying to cleanup the messy test
shai-almog Feb 4, 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
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