Skip to content

Commit b0766aa

Browse files
shai-almogclaude
andcommitted
JavaAPI: add Thread.setDaemon/isDaemon (the real missing-wrapper cause)
The interactive demo's undefined virtual_java_lang_Thread_setDaemon was not a reachability/devirtualization quirk: the JavaAPI java.lang.Thread simply had no setDaemon method, so when an app reaches the port's capturePhoto path (the demo's camera button does; the suite never does) the translator has no body to emit -> undefined symbol. Any minimal app using camera/the async port paths would hit this. Add setDaemon(boolean)/isDaemon() (store the flag) -- verified locally that java_lang_Thread.c now emits both the body and the virtual wrapper, and LinuxImplementation.c now includes the header. Drop the demo-launcher force. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9d92594 commit b0766aa

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

vm/JavaAPI/src/java/lang/Thread.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class Thread implements java.lang.Runnable{
5454
private String name;
5555
private int priority = NORM_PRIORITY;
5656
private long nativeThreadId;
57+
private boolean daemon;
5758
private static int activeThreads = 0;
5859

5960
/**
@@ -97,6 +98,21 @@ public static int activeCount() {
9798
return activeThreads;
9899
}
99100

101+
/**
102+
* Marks this thread as either a daemon thread or a user thread. Stored for
103+
* API compatibility; the concurrent GC tracks lightweight threads regardless.
104+
*/
105+
public final void setDaemon(boolean on) {
106+
this.daemon = on;
107+
}
108+
109+
/**
110+
* Tests whether this thread is a daemon thread.
111+
*/
112+
public final boolean isDaemon() {
113+
return daemon;
114+
}
115+
100116
/**
101117
* Returns a reference to the currently executing Thread object.
102118
*/

vm/tests/src/test/java/com/codename1/tools/translator/CleanTargetLinuxIntegrationTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ static String linuxDemoLauncherSource() {
108108
" static Form home;\n" +
109109
" public static void main(String[] args) {\n" +
110110
" Display.init(null);\n" +
111-
// The port creates daemon worker threads via Thread.setDaemon -- a
112-
// *virtual* wrapper this minimal app would not otherwise reach. Force
113-
// it through a receiver whose runtime type the translator cannot pin
114-
// down (currentThread()), so it cannot devirtualize to a direct call
115-
// and must emit the virtual wrapper. The branch never runs.
116-
" if (args != null && args.length < 0) { Thread.currentThread().setDaemon(true); }\n" +
117111
" Display.getInstance().callSerially(new Runnable(){ public void run(){ build(); } });\n" +
118112
" LinuxImplementation.runMainEventLoop();\n" +
119113
" }\n" +

0 commit comments

Comments
 (0)