Skip to content

Commit b7c74b8

Browse files
committed
Fix clean target runtime stubs for StampedLock
1 parent 414a3c9 commit b7c74b8

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

vm/ByteCodeTranslator/src/cn1_globals.m

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
#if defined(__APPLE__) && defined(__OBJC__)
2424
#import <mach/mach.h>
2525
#import <mach/mach_host.h>
26+
#define CN1_LOG(fmt, ...) NSLog(@fmt, ##__VA_ARGS__)
2627
#else
2728
#include <time.h>
28-
#define NSLog(...) printf(__VA_ARGS__); printf("\n")
29+
#include <stdio.h>
30+
#define CN1_LOG(fmt, ...) printf(fmt "\n", ##__VA_ARGS__)
2931
#endif
3032

3133
// The amount of memory allocated between GC cycle checks (generally 30 seconds)
@@ -591,8 +593,8 @@ void codenameOneGCMark() {
591593
{ long later = time(0)-now;
592594
if(later>10000)
593595
{
594-
NSLog(@"GC trapped for %d seconds waiting for thread %d in slot %d (%d)",
595-
(int)(later/1000),(int)t->threadId,iter,t->threadKilled);
596+
CN1_LOG("GC trapped for %d seconds waiting for thread %d in slot %d (%d)",
597+
(int)(later/1000),(int)t->threadId,iter,t->threadKilled);
596598
}
597599
}
598600
}
@@ -627,7 +629,7 @@ void codenameOneGCMark() {
627629
}
628630
if (CN1_EDT_THREAD_ID == t->threadId && agressiveAllocator) {
629631
long freeMemory = get_free_memory();
630-
NSLog(@"[GC] Blocking EDT as aggressive allocator, free memory=%lld", freeMemory);
632+
CN1_LOG("[GC] Blocking EDT as aggressive allocator, free memory=%lld", freeMemory);
631633

632634
}
633635

@@ -717,7 +719,7 @@ void printObjectsPostSweep(CODENAME_ONE_THREAD_STATE) {
717719
}
718720
}
719721
int actualTotalMemory = 0;
720-
NSLog(@"\n\n**** There are %i - %i = %i nulls available entries out of %i objects in heap which take up %i, sweep saved %i ****", nullSpaces, nullSpacesPreSweep, nullSpaces - nullSpacesPreSweep, t, totalAllocatedHeap, preSweepRam - totalAllocatedHeap);
722+
CN1_LOG("\n\n**** There are %i - %i = %i nulls available entries out of %i objects in heap which take up %i, sweep saved %i ****", nullSpaces, nullSpacesPreSweep, nullSpaces - nullSpacesPreSweep, t, totalAllocatedHeap, preSweepRam - totalAllocatedHeap);
721723
for(int iter = 0 ; iter < cn1_array_3_id_java_util_Vector ; iter++) {
722724
if(classTypeCount[iter] > 0) {
723725
if(classTypeCountPreSweep[iter] - classTypeCount[iter] > 0) {
@@ -736,7 +738,7 @@ void printObjectsPostSweep(CODENAME_ONE_THREAD_STATE) {
736738
}
737739
}
738740
//NSLog(@"Actual ram = %i vs total mallocs = %i", actualTotalMemory, totalAllocatedHeap);
739-
NSLog(@"**** GC cycle complete ****");
741+
CN1_LOG("**** GC cycle complete ****");
740742

741743
free(arrayOfNames);
742744
#if defined(__APPLE__) && defined(__OBJC__)
@@ -774,7 +776,7 @@ void printObjectTypesInHeap(CODENAME_ONE_THREAD_STATE) {
774776
}
775777
}
776778
int actualTotalMemory = 0;
777-
NSLog(@"There are %i null available entries out of %i objects in heap which take up %i", nullSpaces, t, totalAllocatedHeap);
779+
CN1_LOG("There are %i null available entries out of %i objects in heap which take up %i", nullSpaces, t, totalAllocatedHeap);
778780
for(int iter = 0 ; iter < cn1_array_3_id_java_util_Vector ; iter++) {
779781
if(classTypeCount[iter] > 0) {
780782
float f = ((float)classTypeCount[iter]) / ((float)t) * 100.0f;
@@ -792,7 +794,7 @@ void printObjectTypesInHeap(CODENAME_ONE_THREAD_STATE) {
792794
actualTotalMemory += sizeInHeapForType[iter];
793795
}
794796
}
795-
NSLog(@"Actual ram = %i vs total mallocs = %i", actualTotalMemory, totalAllocatedHeap);
797+
CN1_LOG("Actual ram = %i vs total mallocs = %i", actualTotalMemory, totalAllocatedHeap);
796798

797799
free(arrayOfNames);
798800
#if defined(__APPLE__) && defined(__OBJC__)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ static void writeRuntimeStubs(Path srcRoot) throws IOException {
300300
"struct clazz class_array1__JAVA_BYTE = {0};\n" +
301301
"struct clazz class_array1__JAVA_SHORT = {0};\n" +
302302
"struct clazz class_array1__JAVA_LONG = {0};\n" +
303+
"struct clazz class_array1__java_lang_String = {0};\n" +
304+
"struct clazz class_array2__java_lang_String = {0};\n" +
303305
"\n" +
304306
"static JAVA_OBJECT allocArrayInternal(CODENAME_ONE_THREAD_STATE, int length, struct clazz* type, int primitiveSize, int dim) {\n" +
305307
" struct JavaArrayPrototype* arr = (struct JavaArrayPrototype*)calloc(1, sizeof(struct JavaArrayPrototype));\n" +

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ private void writeMockJavaClasses(Path sourceDir) throws Exception {
144144
" private int count;\n" +
145145
" public String(char[] v) { value = v; count=v.length; }\n" +
146146
" public static String valueOf(Object obj) { return obj == null ? \"null\" : obj.toString(); }\n" +
147+
" public byte[] getBytes(String charset) { return new byte[0]; }\n" +
147148
"}\n").getBytes(StandardCharsets.UTF_8));
148149

149150
// java.lang.StringBuilder
@@ -236,7 +237,10 @@ private void writeMockJavaClasses(Path sourceDir) throws Exception {
236237
// java.lang.System
237238
Files.write(lang.resolve("System.java"), ("package java.lang;\n" +
238239
"public final class System {\n" +
239-
" public static native long currentTimeMillis();\n" +
240+
" public static long currentTimeMillis() { return 0L; }\n" +
241+
" public static void gc() {}\n" +
242+
" public static void startGCThread() {}\n" +
243+
" public static Thread gcThreadInstance;\n" +
240244
"}\n").getBytes(StandardCharsets.UTF_8));
241245

242246
// Exceptions

0 commit comments

Comments
 (0)