-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjamvm-amiga-openjdk.patch
More file actions
3182 lines (2946 loc) · 119 KB
/
Copy pathjamvm-amiga-openjdk.patch
File metadata and controls
3182 lines (2946 loc) · 119 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 87c87fbe99dc7a6c185c6eb16b177ff0ddd105a4 Mon Sep 17 00:00:00 2001
From: Richard Gibbs <wofderfs@googlemail.com>
Date: Tue, 9 Jun 2026 22:30:57 +0100
Subject: [PATCH 01/13] Amiga OS4 / clib4 port + OpenJDK 8 classlib bring-up
JAmiga JamVM revival on ppc-amigaos-gcc 11.5 + clib4, plus OpenJDK 8
(Temurin 8 rt.jar) class-library integration:
- clib4 migration of os/amiga (dlopen natives, drop JAmiga pthread/signal shim)
- openjdk classlib fixes: Amiga flat java.home, Thread.name char[]->String,
loadLibrary statMode "./", CDS JVM_GetResourceLookupCacheURLs/KnownToNotExist
stubs, NULL-safe boot-path accessors
- cooperative VM exit (vm_exiting/terminateVMThreads), -Xbootclasspath handlers,
USE_ZIP malloc-read, [EXC] detailMessage diagnostic
- runs `java -version`, headless HelloWorld, and a 25/25 conformance probe
(collections, threads, regex, reflection, lambdas/streams, zip, text/date)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---
.gitignore | 8 +
src/alloc.c | 31 ++++
src/arch.h | 139 +++++++++++++++
src/class.c | 83 ++++++++-
src/classlib/gnuclasspath/natives.c | 4 +
src/classlib/openjdk/class.c | 4 +
src/classlib/openjdk/classlib.h | 5 +
src/classlib/openjdk/dll.c | 9 +-
src/classlib/openjdk/jvm.c | 23 ++-
src/classlib/openjdk/properties.c | 30 ++++
src/classlib/openjdk/thread.c | 8 +
src/dll.c | 2 +
src/excep.c | 36 ++++
src/init.c | 93 +++++++---
src/jam.c | 48 +++++-
src/os/amiga/baseline_glue.c | 28 ++++
src/os/amiga/os.c | 252 ++++++----------------------
src/os/amiga/powerpc/init.c | 33 ++++
src/os/amiga/pthread.h | 130 --------------
src/os/amiga/sched.h | 5 -
src/os/amiga/signal.h | 89 ----------
src/os/amiga/stdlib.h | 30 ----
src/os/amiga/time.h | 20 ---
src/thread.c | 53 +++++-
src/zip.c | 43 ++++-
25 files changed, 690 insertions(+), 516 deletions(-)
create mode 100644 .gitignore
create mode 100644 src/arch.h
create mode 100644 src/os/amiga/baseline_glue.c
delete mode 100644 src/os/amiga/pthread.h
delete mode 100644 src/os/amiga/sched.h
delete mode 100644 src/os/amiga/signal.h
delete mode 100644 src/os/amiga/stdlib.h
delete mode 100644 src/os/amiga/time.h
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..976d81c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+
+# Build-generated (copied into src/ by tools/build-jamvm-*.sh per classlib variant)
+/src/classlib.h
+/src/classlib-defs.h
+/src/classlib-excep.h
+/src/classlib-symbol.h
+# Shelved JAmiga shim headers (backups)
+*.jamiga-shim-bak
diff --git a/src/alloc.c b/src/alloc.c
index 536c720..a1d972d 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -191,6 +191,12 @@ static VMLock registered_refs_lock;
static VMWaitLock run_finaliser_lock;
static VMWaitLock reference_lock;
+/* Cooperative VM-thread shutdown (AmigaOS/clib4 can't async-stop threads via
+ signals). Set TRUE by terminateVMThreads(); the finalizer / reference-handler
+ loops check it after each condvar wait and exit, so clib4 exit() -- which waits
+ for all threads -- can complete instead of hanging on the never-ending daemons. */
+volatile int vm_exiting = FALSE;
+
/* A pointer to the finalizer thread. */
static Thread *finalizer_thread;
@@ -1788,6 +1794,13 @@ void asyncGCThreadLoop(Thread *self) {
for(;;) { \
waitVMWaitLock(list##_lock, self); \
\
+ /* VM is shutting down: exit the loop so the thread terminates \
+ (cooperative shutdown -- see vm_exiting / terminateVMThreads). */ \
+ if(vm_exiting) { \
+ unlockVMWaitLock(list##_lock, self); \
+ break; \
+ } \
+ \
if((list##_start == list##_size) && (list##_end == 0)) \
continue; \
\
@@ -1846,6 +1859,24 @@ void referenceHandlerThreadLoop(Thread *self) {
"<GC: enqueuing %d references>\n", self, &self);
}
+/* Cooperative VM-thread shutdown. Signal the finalizer and reference-handler
+ daemon threads to exit their loops (they wait on a condvar, so a normal notify
+ wakes them -- no signals needed), letting clib4 exit() complete. Called from
+ the exit hook before the process terminates. */
+void terminateVMThreads() {
+ Thread *self = threadSelf();
+
+ vm_exiting = TRUE;
+
+ lockVMWaitLock(run_finaliser_lock, self);
+ notifyAllVMWaitLock(run_finaliser_lock, self);
+ unlockVMWaitLock(run_finaliser_lock, self);
+
+ lockVMWaitLock(reference_lock, self);
+ notifyAllVMWaitLock(reference_lock, self);
+ unlockVMWaitLock(reference_lock, self);
+}
+
int initialiseGC(InitArgs *args) {
/* Pre-allocate an OutOfMemoryError exception object - we throw it
* when we're really low on heap space, and can create FA... */
diff --git a/src/arch.h b/src/arch.h
new file mode 100644
index 0000000..0d2fe78
--- /dev/null
+++ b/src/arch.h
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012
+ * Robert Lougher <rob@jamvm.org.uk>.
+ *
+ * This file is part of JamVM.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#define OS_ARCH "ppc"
+
+#define HANDLER_TABLE_T static const void
+#define DOUBLE_1_BITS 0x3ff0000000000000LL
+
+#define READ_DBL(v,p,l) v = ((u8)p[0]<<56)|((u8)p[1]<<48)|((u8)p[2]<<40) \
+ |((u8)p[3]<<32)|((u8)p[4]<<24)|((u8)p[5]<<16) \
+ |((u8)p[6]<<8)|(u8)p[7]; p+=8
+
+/* Needed for i386 -- empty here */
+#define FPU_HACK
+
+#define COMPARE_AND_SWAP_32(addr, old_val, new_val) \
+({ \
+ int result, read_val; \
+ __asm__ __volatile__ (" \
+ li %0,0\n \
+ 1: lwarx %1,0,%2\n \
+ cmpw %3,%1\n \
+ bne- 2f\n \
+ stwcx. %4,0,%2\n \
+ bne- 1b\n \
+ li %0,1\n \
+ 2:" \
+ : "=&r" (result), "=&r" (read_val) \
+ : "r" (addr), "r" (old_val), "r" (new_val) \
+ : "cc", "memory"); \
+ result; \
+})
+
+#ifdef __ppc64__
+#define COMPARE_AND_SWAP_64(addr, old_val, new_val) \
+({ \
+ int result, read_val; \
+ __asm__ __volatile__ (" \
+ li %0,0\n \
+ 1: ldarx %1,0,%2\n \
+ cmpd %3,%1\n \
+ bne- 2f\n \
+ stdcx. %4,0,%2\n \
+ bne- 1b\n \
+ li %0,1\n \
+ 2:" \
+ : "=&r" (result), "=&r" (read_val) \
+ : "r" (addr), "r" (old_val), "r" (new_val) \
+ : "cc", "memory"); \
+ result; \
+})
+
+#define COMPARE_AND_SWAP(addr, old_val, new_val) \
+ COMPARE_AND_SWAP_64(addr, old_val, new_val)
+#else
+#define COMPARE_AND_SWAP(addr, old_val, new_val) \
+ COMPARE_AND_SWAP_32(addr, old_val, new_val)
+#endif
+
+#define LOCKWORD_READ(addr) *addr
+#define LOCKWORD_WRITE(addr, value) *addr = value
+#define LOCKWORD_COMPARE_AND_SWAP(addr, old_val, new_val) \
+ COMPARE_AND_SWAP(addr, old_val, new_val)
+
+#define CACHE_LINE_LEN 32
+
+#define FLUSH_CACHE(addr, length) \
+{ \
+ uintptr_t end = ((uintptr_t) (addr)) + length; \
+ uintptr_t start = ((uintptr_t) (addr)) \
+ & ~(CACHE_LINE_LEN - 1); \
+ uintptr_t i; \
+ \
+ for(i = start; i < end; i += CACHE_LINE_LEN) \
+ __asm__ ("dcbst 0, %0" :: "r" (i)); \
+ \
+ __asm__ ("sync"); \
+ \
+ for(i = start; i < end; i += CACHE_LINE_LEN) \
+ __asm__ ("icbi 0, %0" :: "r" (i)); \
+ \
+ __asm__ ("sync; isync"); \
+}
+
+#define GEN_REL_JMP(target_addr, patch_addr, patch_size) \
+({ \
+ int patched = FALSE; \
+ \
+ if(patch_size >= 4) { \
+ /* The check is done in two parts to ensure the \
+ result is always positive, to guard against \
+ the pointer difference being larger than the \
+ signed range */ \
+ if(target_addr > patch_addr) { \
+ uintptr_t offset = (target_addr) - (patch_addr); \
+ \
+ if(offset < 1<<25) { \
+ *(int*)(patch_addr) = offset & 0x3ffffff \
+ | 0x48000000; \
+ patched = TRUE; \
+ } \
+ } else { \
+ uintptr_t offset = (patch_addr) - (target_addr); \
+ \
+ if(offset <= 1<<25) { \
+ *(int*)(patch_addr) = -offset & 0x3ffffff \
+ | 0x48000000; \
+ patched = TRUE; \
+ } \
+ } \
+ } \
+ patched; \
+})
+
+#define MBARRIER() __asm__ __volatile__ ("sync" ::: "memory")
+#define JMM_LOCK_MBARRIER() __asm__ __volatile__ ("isync" ::: "memory")
+#ifdef __NO_LWSYNC__
+#define JMM_UNLOCK_MBARRIER() __asm__ __volatile__ ("sync" ::: "memory")
+#else
+#define JMM_UNLOCK_MBARRIER() __asm__ __volatile__ ("lwsync" ::: "memory")
+#endif
diff --git a/src/class.c b/src/class.c
index af81530..e0f4873 100644
--- a/src/class.c
+++ b/src/class.c
@@ -1480,6 +1480,10 @@ unlock:
objectUnlock(class);
}
+#ifdef __amigaos4__
+#include <proto/exec.h>
+#endif
+
Class *initClass(Class *class) {
ClassBlock *cb = CLASS_CB(class);
ConstantPool *cp = &cb->constant_pool;
@@ -1549,8 +1553,51 @@ Class *initClass(Class *class) {
if((excep = exceptionOccurred())) {
Class *error;
+#ifdef __amigaos4__
+ {
+ /* detailMessage/vmState are inherited from java.lang.Throwable, so use
+ lookupField (searches superclasses), NOT findField (own fields only). */
+ FieldBlock *msgfb = lookupField(excep->class, newUtf8("detailMessage"),
+ newUtf8("Ljava/lang/String;"));
+ Object *msg = msgfb ? INST_DATA(excep, Object*, msgfb->u.offset)
+ : NULL;
+ if(msg != NULL) {
+ char *c = String2Cstr(msg);
+ DebugPrintF("[CLINIT] %s <clinit> threw %s: %s\n",
+ CLASS_CB(class)->name,
+ CLASS_CB(excep->class)->name, c);
+ sysFree(c);
+ } else
+ DebugPrintF("[CLINIT] %s <clinit> threw %s (no message)\n",
+ CLASS_CB(class)->name, CLASS_CB(excep->class)->name);
+
+ /* Dump the stack trace: Throwable.vmState (VMThrowable) -> backtrace,
+ an int[] of (MethodBlock*, pc) pairs (see classlib .../excep.c). */
+ {
+ FieldBlock *vmsfb = lookupField(excep->class, newUtf8("vmState"),
+ newUtf8("Ljava/lang/VMThrowable;"));
+ Object *vmt = vmsfb ? INST_DATA(excep, Object*, vmsfb->u.offset)
+ : NULL;
+ FieldBlock *btfb = vmt ? findField(vmt->class, SYMBOL(backtrace),
+ newUtf8("[I")) : NULL;
+ Object *bt = btfb ? INST_DATA(vmt, Object*, btfb->u.offset) : NULL;
+ if(bt != NULL) {
+ uintptr_t *d = ARRAY_DATA(bt, uintptr_t);
+ int i, len = ARRAY_LEN(bt);
+ for(i = 0; i < len && i < 24; i += 2) {
+ MethodBlock *m = (MethodBlock*)d[i];
+ if(m == NULL) break;
+ DebugPrintF("[CLINIT] at %s.%s\n",
+ CLASS_CB(m->class)->name, m->name);
+ }
+ } else
+ DebugPrintF("[CLINIT] (no backtrace: vmt=%p btfb=%p)\n",
+ vmt, btfb);
+ }
+ }
+#endif
- clearException();
+ clearException();
/* Don't wrap exceptions of type java.lang.Error... */
error = findSystemClass0(SYMBOL(java_lang_Error));
@@ -2135,6 +2182,10 @@ void freeClassLoaderData(Object *class_loader) {
}
}
+#ifdef __amigaos4__
+#include <proto/exec.h>
+#endif
+
void parseBootClassPath() {
char *cp, *pntr, *start;
int i, j, len, max = 0;
@@ -2142,6 +2193,9 @@ void parseBootClassPath() {
cp = sysMalloc(strlen(bootpath)+1);
strcpy(cp, bootpath);
+#ifdef __amigaos4__
+ DebugPrintF("[BCP] bootpath='%s'\n", bootpath);
+#endif
for(i = 0, start = pntr = cp; *pntr; pntr++) {
if(*pntr == ':') {
@@ -2164,16 +2218,26 @@ void parseBootClassPath() {
start = pntr;
pntr += (len = strlen(pntr))+1;
- if(stat(start, &info) == 0) {
+ {
+ int _sr = stat(start, &info);
+#ifdef __amigaos4__
+ DebugPrintF("[BCP] entry='%s' stat=%d\n", start, _sr);
+#endif
+ if(_sr == 0) {
if(S_ISDIR(info.st_mode)) {
bootclasspath[j].zip = NULL;
if(len > max)
max = len;
} else
- if((bootclasspath[j].zip = processArchive(start)) == NULL)
+ if((bootclasspath[j].zip = processArchive(start)) == NULL) {
+#ifdef __amigaos4__
+ DebugPrintF("[BCP] processArchive FAILED '%s'\n", start);
+#endif
continue;
+ }
bootclasspath[j++].path = start;
}
+ }
}
max_cp_element_len = max;
@@ -2182,8 +2246,19 @@ void parseBootClassPath() {
void setClassPath(InitArgs *args) {
char *env;
- classpath = args->classpath ? args->classpath :
+#ifdef __amigaos4__
+ /* Default to an EMPTY app classpath, not "." -- on AmigaOS "." canonicalises
+ to the volume path (e.g. "AmigaOS:Test"), which sun.misc.Launcher's
+ URLClassPath then mangles (':' = path.separator vs Amiga "volume:") /
+ mis-converts to a URL ("volume:" looks like a scheme). An empty
+ java.class.path gives the AppClassLoader no entries to choke on; the app
+ class is supplied on -Xbootclasspath and found via bootstrap delegation. */
+ classpath = args->classpath ? args->classpath :
+ ((env = getenv("CLASSPATH")) ? env : "");
+#else
+ classpath = args->classpath ? args->classpath :
((env = getenv("CLASSPATH")) ? env : ".");
+#endif
}
char *getClassPath() {
diff --git a/src/classlib/gnuclasspath/natives.c b/src/classlib/gnuclasspath/natives.c
index ca95e00..f99f293 100644
--- a/src/classlib/gnuclasspath/natives.c
+++ b/src/classlib/gnuclasspath/natives.c
@@ -39,6 +39,10 @@
#include "reflect.h"
#include "gnuclasspath.h"
+#ifdef __amigaos4__
+#include <proto/exec.h>
+#endif
+
static int pd_offset;
int classlibInitialiseNatives() {
diff --git a/src/classlib/openjdk/class.c b/src/classlib/openjdk/class.c
index 3206ed0..09fc556 100644
--- a/src/classlib/openjdk/class.c
+++ b/src/classlib/openjdk/class.c
@@ -130,6 +130,10 @@ char *classlibDefaultBootClassPath() {
char *path, *pntr;
int i, j, len = 0;
+ /* Pre-init (java -version), getJavaHome() is NULL -- avoid sprintf("%s",NULL). */
+ if(java_home == NULL)
+ return NULL;
+
for(i = 0; entries[i] != NULL; i++)
len += strlen(entries[i]);
diff --git a/src/classlib/openjdk/classlib.h b/src/classlib/openjdk/classlib.h
index 054afe4..8e85682 100644
--- a/src/classlib/openjdk/classlib.h
+++ b/src/classlib/openjdk/classlib.h
@@ -35,7 +35,12 @@ extern Object *classlibMarkThreadTerminated(Object *jThread);
#define classlibThreadIdName() SYMBOL(tid)
#define classlibAddThreadName() SYMBOL(add)
+#if OPENJDK_VERSION >= 8
+/* OpenJDK 8 changed java.lang.Thread.name from char[] to String. */
+#define classlibThreadNameType() SYMBOL(sig_java_lang_String)
+#else
#define classlibThreadNameType() SYMBOL(array_C)
+#endif
#define classlibRemoveThreadName() SYMBOL(removeThreadName)
#define classlibExceptionHandlerName() SYMBOL(uncaughtExceptionHandler)
diff --git a/src/classlib/openjdk/dll.c b/src/classlib/openjdk/dll.c
index 1d9cc9c..bd9a8b8 100644
--- a/src/classlib/openjdk/dll.c
+++ b/src/classlib/openjdk/dll.c
@@ -43,8 +43,15 @@ int classlibInitialiseDll() {
char *classlibDefaultBootDllPath() {
char *java_home = getJavaHome();
- char *dll_path = sysMalloc(strlen(java_home) + sizeof("/lib/"OS_ARCH));
+ char *dll_path;
+ /* java.home is only set during initVM; showVersionAndCopyright() (java
+ -version) calls this pre-init, when getJavaHome() returns NULL. Return
+ NULL rather than strlen(NULL)-crashing -- the caller handles it. */
+ if(java_home == NULL)
+ return NULL;
+
+ dll_path = sysMalloc(strlen(java_home) + sizeof("/lib/"OS_ARCH));
return strcat(strcpy(dll_path, java_home), "/lib/"OS_ARCH);
}
diff --git a/src/classlib/openjdk/jvm.c b/src/classlib/openjdk/jvm.c
index 971ac75..bfbbb93 100644
--- a/src/classlib/openjdk/jvm.c
+++ b/src/classlib/openjdk/jvm.c
@@ -3034,7 +3034,28 @@ jint JVM_FindSignal(const char *name) {
TRACE("JVM_FindSignal(name=%s)", name);
- for(i = 0; signals[i].name != NULL && strcmp(signals[i].name, name); i++);
+ for(i = 0; signals[i].name != NULL && strcmp(signals[i].name, name); i++);
return signals[i].number;
}
+
+/* Class-Data-Sharing (CDS) shared class-path lookup cache. JamVM has no CDS, so
+ report "no cache": getLookupCacheURLs returning NULL makes sun.misc.URLClassPath
+ disable the cache cleanly (URLClassPath.java:322->331). These JVM_* were missing
+ from the classlib -- libjava.so's sun/misc/URLClassPath.c calls them, so the
+ unresolved symbols crashed sun.misc.Launcher init on AmigaOS. */
+jobjectArray JVM_GetResourceLookupCacheURLs(JNIEnv *env, jobject loader) {
+ TRACE("JVM_GetResourceLookupCacheURLs(loader=%p)", loader);
+ return NULL;
+}
+
+jintArray JVM_GetResourceLookupCache(JNIEnv *env, jobject loader,
+ const char *resource_name) {
+ TRACE("JVM_GetResourceLookupCache(loader=%p, name=%s)", loader, resource_name);
+ return NULL;
+}
+
+jboolean JVM_KnownToNotExist(JNIEnv *env, jobject loader, const char *classname) {
+ TRACE("JVM_KnownToNotExist(loader=%p, name=%s)", loader, classname);
+ return JNI_FALSE;
+}
diff --git a/src/classlib/openjdk/properties.c b/src/classlib/openjdk/properties.c
index 2391e61..481963b 100644
--- a/src/classlib/openjdk/properties.c
+++ b/src/classlib/openjdk/properties.c
@@ -21,6 +21,35 @@
#include <string.h>
#include "jam.h"
+#ifdef __amigaos4__
+/* On AmigaOS the runtime layout is FLAT -- libjvm.so, libjava.so and the boot
+ jars all live in one directory (e.g. SYS:Test/), not the Unix
+ <java.home>/lib/<arch>/<vmtype>/libjvm.so tree. So java.home is simply the
+ directory containing libjvm.so (strip the trailing filename after the last
+ '/' or ':' volume separator). Boot class/library paths are supplied
+ explicitly via -Xbootclasspath and -Dsun.boot.library.path, so they don't
+ depend on the (Unix-shaped) java.home/lib/... derivation. */
+char *classlibDefaultJavaHome() {
+ char *path = nativeJVMPath();
+ char *pntr, *home;
+
+ if(path == NULL)
+ return NULL;
+
+ pntr = path + strlen(path);
+ while(pntr > path && pntr[-1] != '/' && pntr[-1] != ':')
+ pntr--;
+ if(pntr > path && pntr[-1] == '/') /* keep volume ':' but drop dir '/' */
+ pntr--;
+
+ home = sysMalloc(pntr - path + 1);
+ memcpy(home, path, pntr - path);
+ home[pntr - path] = '\0';
+ sysFree(path);
+
+ return home;
+}
+#else
char *classlibDefaultJavaHome() {
char *path = nativeJVMPath();
char *pntr = path + strlen(path);
@@ -42,4 +71,5 @@ char *classlibDefaultJavaHome() {
return home;
}
+#endif
diff --git a/src/classlib/openjdk/thread.c b/src/classlib/openjdk/thread.c
index 71fc8aa..8a7c303 100644
--- a/src/classlib/openjdk/thread.c
+++ b/src/classlib/openjdk/thread.c
@@ -160,6 +160,13 @@ void classlibSetThreadState(Thread *thread, int state) {
void classlibThreadName2Buff(Object *jThread, char *buffer, int buff_len) {
Object *name = INST_DATA(jThread, Object*, name_offset);
+#if OPENJDK_VERSION >= 8
+ /* OpenJDK 8: Thread.name is a String, not a char[]. */
+ if(name == NULL)
+ buffer[0] = '\0';
+ else
+ String2Buff(name, buffer, buff_len);
+#else
unsigned short *unicode = ARRAY_DATA(name, unsigned short);
int i, len = ARRAY_LEN(name) < buff_len ? ARRAY_LEN(name)
: buff_len - 1;
@@ -168,6 +175,7 @@ void classlibThreadName2Buff(Object *jThread, char *buffer, int buff_len) {
buffer[i] = unicode[i];
buffer[len] = '\0';
+#endif
}
static sem_t signal_sem;
diff --git a/src/dll.c b/src/dll.c
index 3604fcf..654c63c 100644
--- a/src/dll.c
+++ b/src/dll.c
@@ -224,6 +224,8 @@ uintptr_t *resolveNativeWrapper(Class *class, MethodBlock *mb,
NativeMethod method = resolveNativeMethod(mb);
if(method == NULL) {
+ jam_fprintf(stderr, "[UNSATISFIED] %s.%s %s\n",
+ CLASS_CB(mb->class)->name, mb->name, mb->type);
signalException(java_lang_UnsatisfiedLinkError, mb->name);
return ostack;
}
diff --git a/src/excep.c b/src/excep.c
index bf88d59..c663143 100644
--- a/src/excep.c
+++ b/src/excep.c
@@ -151,10 +151,46 @@ Object *exceptionEnumToException(int excep_enum) {
return exceptions[excep_enum];
}
+#ifdef __amigaos4__
+#include <proto/exec.h>
+#endif
+
void printException() {
ExecEnv *ee = getExecEnv();
Object *excep = ee->exception;
+#ifdef __amigaos4__
+ /* clib4 bring-up: Java printStackTrace fails when System.err isn't set up,
+ hiding the real cause. Dump the exception chain (class names) to serial. */
+ if(excep != NULL) {
+ Object *e = excep;
+ int d;
+ for(d = 0; e != NULL && d < 8; d++) {
+ FieldBlock *fb;
+ Object *c;
+ DebugPrintF("[EXC] %d: %s\n", d, CLASS_CB(e->class)->name);
+ {
+ FieldBlock *mfb = findField(e->class, newUtf8("detailMessage"),
+ newUtf8("Ljava/lang/String;"));
+ Object *msg = mfb ? INST_DATA(e, Object*, mfb->u.offset) : NULL;
+ if(msg != NULL) {
+ char *m = String2Cstr(msg);
+ DebugPrintF("[EXC] msg: %s\n", m);
+ sysFree(m);
+ }
+ }
+ fb = findField(e->class, newUtf8("cause"),
+ newUtf8("Ljava/lang/Throwable;"));
+ if(fb == NULL)
+ break;
+ c = INST_DATA(e, Object*, fb->u.offset);
+ if(c == NULL || c == e)
+ break;
+ e = c;
+ }
+ }
+#endif
+
if(excep != NULL) {
MethodBlock *mb = lookupMethod(excep->class, SYMBOL(printStackTrace),
SYMBOL(___V));
diff --git a/src/init.c b/src/init.c
index 32539cf..0ca5ee1 100644
--- a/src/init.c
+++ b/src/init.c
@@ -26,7 +26,8 @@
#include "jam.h"
-static int VM_initing = TRUE;
+/* Not static: os/amiga/scanprocess.c references VM_initing via `extern int`. */
+int VM_initing = TRUE;
extern void initialisePlatform();
unsigned long clampHeapLimit(long long limit) {
@@ -34,6 +35,36 @@ unsigned long clampHeapLimit(long long limit) {
return (unsigned long)MIN(clamp, MAX_MAX_HEAP);
}
+/* clib4 bring-up: route all JamVM messages (args->vfprintf) to the serial
+ debug log, since AmigaDOS stderr isn't easily captured. Remove once stable. */
+#ifdef __amigaos4__
+#include <proto/exec.h>
+#include <unistd.h>
+static int amiga_vfprintf(FILE *stream, const char *fmt, va_list ap) {
+ char buf[1024];
+ int n = vsnprintf(buf, sizeof(buf), fmt, ap);
+ (void)stream;
+ DebugPrintF("%s", buf);
+ return n;
+}
+
+/* clib4 exit() HANGS during VM shutdown: it waits for all threads to terminate
+ before tearing down the shared clib4 context, but JamVM's daemon threads loop
+ forever and can't be async-stopped (clib4 pthread_kill only Signal()s a raw
+ Exec bit, never running the sigaction handler). Cooperative fix: tell the
+ finalizer/reference-handler threads to exit (terminateVMThreads notifies their
+ condvars; vm_exiting makes the loops return), and skip the signal-handler thread
+ entirely on AmigaOS (see thread.c). With the daemons exiting, clib4 exit() can
+ complete cleanly. Output already went out via raw write() syscalls. */
+extern void terminateVMThreads(void);
+static void amiga_exit(int status) {
+ DebugPrintF("[EXIT] amiga_exit(%d): terminating VM threads\n", status);
+ terminateVMThreads();
+ DebugPrintF("[EXIT] amiga_exit: calling exit()\n");
+ exit(status);
+}
+#endif
+
/* Setup default values for command line args */
void setDefaultInitArgs(InitArgs *args) {
@@ -65,9 +96,17 @@ void setDefaultInitArgs(InitArgs *args) {
args->props_count = 0;
+#ifdef __amigaos4__
+ args->vfprintf = amiga_vfprintf;
+#else
args->vfprintf = vfprintf;
+#endif
args->abort = abort;
+#ifdef __amigaos4__
+ args->exit = amiga_exit;
+#else
args->exit = exit;
+#endif
#ifdef INLINING
args->replication_threshold = 10;
@@ -89,34 +128,46 @@ int VMInitialising() {
return VM_initing;
}
+/* Temporary clib4 bring-up tracing: emit each initVM stage to the serial
+ debug log (DebugPrintF) so the last printed stage identifies a failing one.
+ Remove once Hello World runs. */
+#ifdef __amigaos4__
+#include <proto/exec.h>
+#define JVTRACE(s) DebugPrintF("[JV] %s\n", (s))
+#else
+#define JVTRACE(s)
+#endif
+
int initVM(InitArgs *args) {
int status;
/* Perform platform dependent initialisation */
+ JVTRACE("initialisePlatform");
initialisePlatform();
/* Initialise the VM modules -- ordering is important! */
- status = initialiseHooks(args) &&
- initialiseProperties(args) &&
- initialiseAlloc(args) &&
- initialiseThreadStage1(args) &&
- initialiseUtf8() &&
- initialiseSymbol() &&
- initialiseClassStage1(args) &&
- initialiseDll(args) &&
- initialiseMonitor() &&
- initialiseString() &&
- initialiseException() &&
- initialiseNatives() &&
- initialiseAccess() &&
- initialiseFrame() &&
- initialiseJNI() &&
- initialiseInterpreter(args) &&
- initialiseClassStage2() &&
- initialiseThreadStage2(args) &&
- initialiseGC(args);
-
+ status = (JVTRACE("hooks"), initialiseHooks(args)) &&
+ (JVTRACE("properties"), initialiseProperties(args)) &&
+ (JVTRACE("alloc"), initialiseAlloc(args)) &&
+ (JVTRACE("threadStage1"), initialiseThreadStage1(args)) &&
+ (JVTRACE("utf8"), initialiseUtf8()) &&
+ (JVTRACE("symbol"), initialiseSymbol()) &&
+ (JVTRACE("classStage1"), initialiseClassStage1(args)) &&
+ (JVTRACE("dll"), initialiseDll(args)) &&
+ (JVTRACE("monitor"), initialiseMonitor()) &&
+ (JVTRACE("string"), initialiseString()) &&
+ (JVTRACE("exception"), initialiseException()) &&
+ (JVTRACE("natives"), initialiseNatives()) &&
+ (JVTRACE("access"), initialiseAccess()) &&
+ (JVTRACE("frame"), initialiseFrame()) &&
+ (JVTRACE("jni"), initialiseJNI()) &&
+ (JVTRACE("interpreter"), initialiseInterpreter(args)) &&
+ (JVTRACE("classStage2"), initialiseClassStage2()) &&
+ (JVTRACE("threadStage2"), initialiseThreadStage2(args)) &&
+ (JVTRACE("gc"), initialiseGC(args));
+
+ JVTRACE("initVM done");
VM_initing = FALSE;
return status;
}
diff --git a/src/jam.c b/src/jam.c
index 052f84a..2951d20 100644
--- a/src/jam.c
+++ b/src/jam.c
@@ -107,15 +107,25 @@ void showVersionAndCopyright() {
printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
printf("GNU General Public License for more details.\n");
- printf("\nBuild information:\n\nExecution Engine: %s\n",
- getExecutionEngineName());
+ {
+ /* These classlib accessors can return NULL before the VM is initialised
+ (the openjdk classlib derives them from java.home/VM state set up in
+ initVM, but -version is handled here in parseCommandLine, pre-init).
+ printf("%s", NULL) crashes clib4's vfprintf, so guard them. */
+ char *engine = getExecutionEngineName();
+ char *boot_dll = classlibDefaultBootDllPath();
+ char *boot_cp = classlibDefaultBootClassPath();
+
+ printf("\nBuild information:\n\nExecution Engine: %s\n",
+ engine ? engine : "(unknown)");
#if defined(__GNUC__) && defined(__VERSION__)
- printf("Compiled with: gcc %s\n", __VERSION__);
+ printf("Compiled with: gcc %s\n", __VERSION__);
#endif
- printf("\nBoot Library Path: %s\n", classlibDefaultBootDllPath());
- printf("Boot Class Path: %s\n", classlibDefaultBootClassPath());
+ printf("\nBoot Library Path: %s\n", boot_dll ? boot_dll : "(unset)");
+ printf("Boot Class Path: %s\n", boot_cp ? boot_cp : "(unset)");
+ }
}
void showFullVersion() {
@@ -212,6 +222,18 @@ int parseCommandLine(int argc, char *argv[], InitArgs *args) {
} else if(strncmp(argv[i], "-Xbootclasspath/v:", 18) == 0) {
args->bootpath_v = argv[i] + 18;
+ /* These plain/append/prepend forms were missing in the JAmiga
+ fork, so -Xbootclasspath: was silently ignored and the VM
+ fell back to the (non-existent) default JAmiga: boot path. */
+ } else if(strncmp(argv[i], "-Xbootclasspath/a:", 18) == 0) {
+ args->bootpath_a = argv[i] + 18;
+
+ } else if(strncmp(argv[i], "-Xbootclasspath/p:", 18) == 0) {
+ args->bootpath_p = argv[i] + 18;
+
+ } else if(strncmp(argv[i], "-Xbootclasspath:", 16) == 0) {
+ args->bootpath = argv[i] + 16;
+
/* Compatibility options */
} else if(strcmp(argv[i], "-client") == 0 ||
strcmp(argv[i], "-server") == 0) {
@@ -251,10 +273,24 @@ int main(int argc, char *argv[]) {
exit(1);
}
- if((system_loader = getSystemClassLoader()) == NULL)
+#ifdef __amigaos4__
+ /* The OpenJDK system classloader (sun.misc.Launcher) now INITIALISES cleanly
+ on AmigaOS -- the hard crash in getSystemClassLoader was the missing CDS
+ JVM_GetResourceLookupCacheURLs/JVM_KnownToNotExist (libjava.so called the
+ unresolved symbols); those are now stubbed (return NULL/FALSE) in jvm.c.
+ HOWEVER running the app class THROUGH the system loader still has a latent
+ bug (HelloWorld loads + main returns but produces no output; a heisenbug
+ that the [NM] debug trace masked -> suspect memory corruption / GC on the
+ much larger Launcher/URLClassPath code path). So for now keep the reliable
+ BOOTSTRAP path (app class on -Xbootclasspath). TODO(Phase 3): debug the
+ system-loader run path + Amiga path->URL for real -classpath. */
+ system_loader = NULL;
+#else
+ if((system_loader = getSystemClassLoader()) == NULL)
goto error;
mainThreadSetContextClassLoader(system_loader);
+#endif
for(cpntr = argv[class_arg]; *cpntr; cpntr++)
if(*cpntr == '.')
diff --git a/src/os/amiga/baseline_glue.c b/src/os/amiga/baseline_glue.c
new file mode 100644
index 0000000..c15dc04
--- /dev/null
+++ b/src/os/amiga/baseline_glue.c
@@ -0,0 +1,28 @@
+/*
+ * baseline_glue.c -- small definitions needed to complete the newlib baseline
+ * link of JAmiga JamVM that are absent from the 2016 Amiga port / the current
+ * SDK. Keep these together so they are easy to find and remove/replace as the
+ * real implementations land (clib4 migration, JNI native loading, etc.).
+ * See docs/revival-notes.md.
+ */
+#include <stdint.h>
+
+/* init.c uses this for default heap sizing. bsd/darwin os.c return 0 ("TBD");
+ * the Amiga os.c never defined it. 0 keeps JamVM on its built-in defaults. */
+long long nativePhysicalMemory(void) {
+ return 0;
+}
+
+/* interp.c (executeJava: tableswitch/lookupswitch) calls ntohl to read
+ * big-endian bytecode operands. <arpa/inet.h> declares it but no impl is
+ * linked under newlib. AmigaOS 4 PPC is big-endian, so these are identities. */
+uint32_t ntohl(uint32_t x) { return x; }
+uint16_t ntohs(uint16_t x) { return x; }
+uint32_t htonl(uint32_t x) { return x; }
+uint16_t htons(uint16_t x) { return x; }
+
+/* scanprocess.c calls this at shutdown to unload boot-classloader native libs.
+ * Not defined in the JAmiga tree; stub for the baseline (native lib loading is
+ * itself stubbed via proto/nativelib.h until restored). */
+void unloadBootClassLoaderDlls(void) {
+}
diff --git a/src/os/amiga/os.c b/src/os/amiga/os.c
index 5561c20..aa1237b 100644
--- a/src/os/amiga/os.c
+++ b/src/os/amiga/os.c
@@ -19,241 +19,95 @@
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+/*
+ * AmigaOS 4 os layer, clib4 variant.
+ *
+ * Reworked for the clib4 migration: native library loading now uses standard
+ * clib4 dlopen/dlsym (ELF .so), replacing JAmiga's lost nativelib.library ABI.
+ * Threads/signals/mmap/scandir are provided by clib4 directly (the JAmiga
+ * pthread.c/signal.c/scandir.c/memory.c shims are no longer built). This mirrors
+ * JamVM's os/linux/os.c.
+ */
+
#include "jamvm_rev.h"
#undef VERSION
#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
#define USE_MALLOC 1
#define JA_TARGETOS JA_AMIGAOS4
#include "../../jam.h"
-//#include "MemGuardian.h"
#include <proto/exec.h>
-#include <proto/utility.h>
#include <proto/dos.h>
-#include <proto/nativelib.h>
-#define VERSIONTAG VERSTAG" AmigaOS 4 build of "PACKAGE" "VERSION" "
-STRPTR USED ver = (STRPTR)VERSIONTAG;
-
-/**
- * Struct from JAmiga JNI library definition.
- */
-struct JNINativeMethod {
- char *className;
- char *methodName;
- char *methodDescriptor;
- void *fnPtr;
- int flags;
-};
-
-struct JNINativeLibrary {
- char *name;
- int version;
- int numberOfMethods;
- struct JNINativeMethod *methods;
-};
+#define __USE_GNU
+#include <dlfcn.h>
+#include <pthread.h>
-/**
- * Internal struct for native methods
- * with mangled symbol name.
- */
-struct JamNativeMethodSymbol {
- char *symbolName;
- void *fnPtr;
-};
-
+#define VERSIONTAG VERSTAG" AmigaOS 4 build of "PACKAGE" "VERSION" "
+STRPTR USED ver = (STRPTR)VERSIONTAG;
-/**
- * Internal struct for list of native methods
- * with mangled symbol names.
- */
-struct JamLibraryInfo {
- char *name;
- int numberOfMethods;
- //
- struct JamNativeMethodSymbol * nativeMethods;
- struct Library *osLib;
-#if (JA_TARGETOS==JA_AMIGAOS4)
- struct Interface *osIFace;
-#endif
-} JamLibraryInfo ;
+long long nativePhysicalMemory() {
+ /* Report a modest figure so the default heap (phys/4) stays small: clib4's
+ mmap currently fails for very large MAP_ANON regions (a multi-hundred-MB
+ default heap from reporting true RAM aborts initialiseAlloc). 64 MB ->
+ 16 MB default max heap, which clib4 mmap handles. -Xmx overrides this.
+ TODO: investigate clib4 large-mmap limit and raise this. */
+ return 64LL * 1024 * 1024;
+}
void *nativeStackBase() {
- DebugPrintF("Native stack base\n");
+ /* No portable pthread_getattr_np in clib4; let JamVM fall back (as the
+ uclibc path does). Revisit if main-thread GC root scanning needs it. */
return NULL;
}
int nativeAvailableProcessors() {
- DebugPrintF("Native avail processorn");
return 1;
}