From 87b6cb421f1a4b4f8d45cf894b72f779f2e3f793 Mon Sep 17 00:00:00 2001 From: Steve Hannah Date: Wed, 14 Feb 2018 13:23:12 -0800 Subject: [PATCH 1/5] Fixed BC_DUP2_X2 and BC_DUP_X2 bytecode instructions in ParparVM to support all permutations of types of the stack. Previously both instructions were being routed to the same macro, for DUP2_X2, but it was only properly dealing with 2 of the possible 6 scenarios. This fixes https://github.com/codenameone/CodenameOne/issues/2277 and likely fixes other issues in the queue. Will be testing shortly with other iOS issues. --- vm/ByteCodeTranslator/src/cn1_globals.h | 37 +++++----- vm/ByteCodeTranslator/src/cn1_globals.m | 72 +++++++++++++++++++ .../bytecodes/BasicInstruction.java | 2 +- 3 files changed, 92 insertions(+), 19 deletions(-) diff --git a/vm/ByteCodeTranslator/src/cn1_globals.h b/vm/ByteCodeTranslator/src/cn1_globals.h index 9320297485..f4316ad6c5 100644 --- a/vm/ByteCodeTranslator/src/cn1_globals.h +++ b/vm/ByteCodeTranslator/src/cn1_globals.h @@ -535,27 +535,28 @@ if(SP[-1].type == CN1_TYPE_LONG || SP[-1].type == CN1_TYPE_DOUBLE) {\ SP++; \ } +struct elementStruct* BC_DUP2_X2_DD(struct elementStruct* SP); +struct elementStruct* BC_DUP2_X2_DSS(struct elementStruct* SP); +struct elementStruct* BC_DUP2_X2_SSD(struct elementStruct* SP); +struct elementStruct* BC_DUP2_X2_SSSS(struct elementStruct* SP); +struct elementStruct* BC_DUP_X2_SD(struct elementStruct* SP); +struct elementStruct* BC_DUP_X2_SSS(struct elementStruct* SP); + +#define IS_DOUBLE_WORD(offset) (SP[offset].type == CN1_TYPE_LONG || SP[offset].type == CN1_TYPE_DOUBLE) + +#define BC_DUP_X2() {\ + if (IS_DOUBLE_WORD(-2)) SP=BC_DUP_X2_SD(SP);\ + else SP=BC_DUP_X2_SSS(SP);\ +} + #define BC_DUP2_X2() { \ - if (SP[-2].type == CN1_TYPE_LONG || SP[-2].type == CN1_TYPE_DOUBLE) {\ - (*SP).data.l = SP[-1].data.l; \ - SP[-1].data.l = SP[-2].data.l; \ - SP[-2].data.l = (*SP).data.l; \ - (*SP).type = SP[-1].type; \ - SP[-1].type = SP[-2].type; \ - SP[-2].type = (*SP).type; \ - } else {\ - (*SP).data.l = SP[-1].data.l; \ - SP[-1].data.l = SP[-2].data.l; \ - SP[-2].data.l = SP[-3].data.l; \ - SP[-3].data.l = (*SP).data.l; \ - (*SP).type = SP[-1].type; \ - SP[-1].type = SP[-2].type; \ - SP[-2].type = SP[-3].type; \ - SP[-3].type = (*SP).type; \ - }\ - SP++; \ + if (IS_DOUBLE_WORD(-2)) SP=BC_DUP2_X2_DD(SP);\ +else if (IS_DOUBLE_WORD(-1)) SP=BC_DUP2_X2_DSS(SP);\ + else if (IS_DOUBLE_WORD(-3)) SP=BC_DUP2_X2_SSD(SP);\ + else SP=BC_DUP2_X2_SSSS(SP);\ } + #define BC_I2B() SP[-1].data.i = ((SP[-1].data.i << 24) >> 24) #define BC_I2S() SP[-1].data.i = ((SP[-1].data.i << 16) >> 16) diff --git a/vm/ByteCodeTranslator/src/cn1_globals.m b/vm/ByteCodeTranslator/src/cn1_globals.m index 43afa0b278..13643dab83 100644 --- a/vm/ByteCodeTranslator/src/cn1_globals.m +++ b/vm/ByteCodeTranslator/src/cn1_globals.m @@ -136,6 +136,78 @@ void popMany(CODENAME_ONE_THREAD_STATE, int count, struct elementStruct** SP) { JAVA_OBJECT* constantPoolObjects = 0; +struct elementStruct* BC_DUP2_X2_DD(struct elementStruct* SP) { + (*SP).data.l = SP[-1].data.l; + SP[-1].data.l = SP[-2].data.l; + SP[-2].data.l = (*SP).data.l; + (*SP).type = SP[-1].type; + SP[-1].type = SP[-2].type; + SP[-2].type = (*SP).type; + return (struct elementStruct*)(SP+1); +} +struct elementStruct* BC_DUP2_X2_DSS(struct elementStruct* SP) { + SP[0].data.l = SP[-1].data.l; + SP[-1].data.l = SP[-2].data.l; + SP[-2].data.l = SP[-3].data.l; + SP[-3].data.l = SP[0].data.l; + SP[0].type = SP[-1].type; + SP[-1].type = SP[-2].type; + SP[-2].type = SP[-3].type; + SP[-3].type = SP[0].type; + return SP+1; +} +struct elementStruct*BC_DUP2_X2_SSD(struct elementStruct* SP) { + SP[1].data.l = SP[-1].data.l; + SP[0].data.l = SP[-2].data.l; + SP[-1].data.l = SP[-3].data.l; + SP[-2].data.l = SP[1].data.l; + SP[-3].data.l = SP[0].data.l; + SP[1].type = SP[-1].type; + SP[0].type = SP[-2].type; + SP[-1].type = SP[-3].type; + SP[-2].type = SP[1].type; + SP[-3].type = SP[0].type; + return SP+2; +} +struct elementStruct* BC_DUP2_X2_SSSS(struct elementStruct* SP) { + SP[1].data.l = SP[-1].data.l; + SP[0].data.l = SP[-2].data.l; + SP[-1].data.l = SP[-3].data.l; + SP[-2].data.l = SP[-4].data.l; + SP[-3].data.l = SP[1].data.l; + SP[-4].data.l = SP[0].data.l; + SP[1].type = SP[-1].type; + SP[0].type = SP[-2].type; + SP[-1].type = SP[-3].type; + SP[-2].type = SP[-4].type; + SP[-3].type = SP[1].type; + SP[-4].type = SP[0].type; + return SP+2; +} + +struct elementStruct* BC_DUP_X2_SD(struct elementStruct* SP) { + SP[0].data.l = SP[-1].data.l; + SP[-1].data.l = SP[-2].data.l; + SP[-2].data.l = SP[0].data.l; + SP[0].type = SP[-1].type; + SP[-1].type = SP[-2].type; + SP[-2].type = SP[0].type; + return SP+1; +} + +struct elementStruct* BC_DUP_X2_SSS(struct elementStruct* SP) { + SP[0].data.l = SP[-1].data.l; + SP[-1].data.l = SP[-2].data.l; + SP[-2].data.l = SP[-3].data.l; + SP[-3].data.l = SP[0].data.l; + SP[0].type = SP[-1].type; + SP[-1].type = SP[-2].type; + SP[-2].type = SP[-3].type; + SP[-3].type = SP[0].type; + return SP+1; +} + + int instanceofFunction(int sourceClass, int destId) { if(sourceClass == destId) { return JAVA_TRUE; diff --git a/vm/ByteCodeTranslator/src/com/codename1/tools/translator/bytecodes/BasicInstruction.java b/vm/ByteCodeTranslator/src/com/codename1/tools/translator/bytecodes/BasicInstruction.java index 00e5bb0ffe..9bb00c0184 100644 --- a/vm/ByteCodeTranslator/src/com/codename1/tools/translator/bytecodes/BasicInstruction.java +++ b/vm/ByteCodeTranslator/src/com/codename1/tools/translator/bytecodes/BasicInstruction.java @@ -291,7 +291,7 @@ public void appendInstruction(StringBuilder b, List instructions) { break; case Opcodes.DUP_X2: - b.append(" BC_DUP2_X2(); /* DUP_X2 */\n"); + b.append(" BC_DUP_X2(); /* DUP_X2 */\n"); break; case Opcodes.DUP2_X2: From 0cd7003e31c4debd1d3f0a5afb0ff8213fdefd40 Mon Sep 17 00:00:00 2001 From: Steve Hannah Date: Wed, 14 Feb 2018 13:25:17 -0800 Subject: [PATCH 2/5] Fixed typo from previous commit. --- vm/ByteCodeTranslator/src/cn1_globals.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/ByteCodeTranslator/src/cn1_globals.m b/vm/ByteCodeTranslator/src/cn1_globals.m index 13643dab83..b7f7456f5c 100644 --- a/vm/ByteCodeTranslator/src/cn1_globals.m +++ b/vm/ByteCodeTranslator/src/cn1_globals.m @@ -156,7 +156,7 @@ void popMany(CODENAME_ONE_THREAD_STATE, int count, struct elementStruct** SP) { SP[-3].type = SP[0].type; return SP+1; } -struct elementStruct*BC_DUP2_X2_SSD(struct elementStruct* SP) { +struct elementStruct* BC_DUP2_X2_SSD(struct elementStruct* SP) { SP[1].data.l = SP[-1].data.l; SP[0].data.l = SP[-2].data.l; SP[-1].data.l = SP[-3].data.l; From 65bfc02d8fbcce549f4e66428d0869249a14c04d Mon Sep 17 00:00:00 2001 From: Steve Hannah Date: Wed, 14 Feb 2018 15:18:15 -0800 Subject: [PATCH 3/5] Fixed issue with strings encoding control characters, including the null character. Fixes https://github.com/codenameone/CodenameOne/issues/1742 --- .../src/com/codename1/tools/translator/Parser.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/ByteCodeTranslator/src/com/codename1/tools/translator/Parser.java b/vm/ByteCodeTranslator/src/com/codename1/tools/translator/Parser.java index 007e42f247..d4531df141 100644 --- a/vm/ByteCodeTranslator/src/com/codename1/tools/translator/Parser.java +++ b/vm/ByteCodeTranslator/src/com/codename1/tools/translator/Parser.java @@ -346,12 +346,12 @@ private static String encodeStringSlashU(String str) { char[] chr = str.toCharArray(); for(int iter = 0 ; iter < len ; iter++) { char c = chr[iter]; - if(c > 127) { + if(c > 127 || c < 32) { // needs encoding... Verify there are no more characters to encode StringBuilder d = new StringBuilder(); for(int internal = 0 ; internal < len ; internal++) { c = chr[internal]; - if(c > 127) { + if(c > 127 || c < 32) { d.append("~~u"); d.append(fourChars(Integer.toHexString(c))); } else { From efba4c39fa83ee98b51ec0c41e3bde48e2dfbbb1 Mon Sep 17 00:00:00 2001 From: Steve Hannah Date: Thu, 15 Feb 2018 06:59:11 -0800 Subject: [PATCH 4/5] Fixed regression that caused crashing on splash screen in iOS < 8.2. New font behaviour from https://github.com/codenameone/CodenameOne/commit/3793c3165aaf0fc80087f70bcd3c3c79eaf30cd1#diff-68868771f872460be4c496d3112d0a07 uses constants that are only available in 8.2 and later. This fix has been tested on iPhone 4S running iOS 6. --- Ports/iOSPort/nativeSources/CodenameOne_GLViewController.m | 7 +++++++ Ports/iOSPort/nativeSources/IOSNative.m | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Ports/iOSPort/nativeSources/CodenameOne_GLViewController.m b/Ports/iOSPort/nativeSources/CodenameOne_GLViewController.m index 999c954847..90854ef1d5 100644 --- a/Ports/iOSPort/nativeSources/CodenameOne_GLViewController.m +++ b/Ports/iOSPort/nativeSources/CodenameOne_GLViewController.m @@ -217,6 +217,7 @@ int isIPad() { #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) int cn1IsIOS8 = -1; +int cn1IsIOS8_2 = -1; BOOL isIOS8() { if (cn1IsIOS8 < 0) { @@ -224,6 +225,12 @@ BOOL isIOS8() { } return cn1IsIOS8 > 0; } +BOOL isIOS8_2() { + if (cn1IsIOS8_2 < 0) { + cn1IsIOS8_2 = !SYSTEM_VERSION_LESS_THAN(@"8.2") ? 1:0; + } + return cn1IsIOS8_2 > 0; +} BOOL isVKBAlwaysOpen() { if(vkbAlwaysOpen) { diff --git a/Ports/iOSPort/nativeSources/IOSNative.m b/Ports/iOSPort/nativeSources/IOSNative.m index 932e8c1690..89b9dc5df9 100644 --- a/Ports/iOSPort/nativeSources/IOSNative.m +++ b/Ports/iOSPort/nativeSources/IOSNative.m @@ -243,6 +243,7 @@ JAVA_OBJECT fromNSString(NSString* str) extern int isIPad(); extern int isIOS7(); extern int isIOS8(); +extern int isIOS8_2(); NSString* fixFilePath(NSString* ns) { if([ns hasPrefix:@"file:"]) { @@ -4906,7 +4907,7 @@ JAVA_LONG com_codename1_impl_ios_IOSNative_createTruetypeFont___java_lang_String NSString* str = toNSString(CN1_THREAD_STATE_PASS_ARG name); UIFont* fnt; - if([str hasPrefix:@"HelveticaNeue"]) { + if(isIOS8_2() && [str hasPrefix:@"HelveticaNeue"]) { if([str isEqualToString:@"HelveticaNeue-UltraLight"]) { fnt = [UIFont systemFontOfSize:pSize weight:UIFontWeightUltraLight]; } else { From 352d42e64ac05296cff866b5c826bafc6ec94185 Mon Sep 17 00:00:00 2001 From: Robert Edelmann Date: Thu, 15 Feb 2018 17:30:27 +0100 Subject: [PATCH 5/5] fix background color regression in RoundRectBorder --- CodenameOne/src/com/codename1/ui/plaf/RoundRectBorder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/CodenameOne/src/com/codename1/ui/plaf/RoundRectBorder.java b/CodenameOne/src/com/codename1/ui/plaf/RoundRectBorder.java index db82610790..a9e2f3b9b5 100644 --- a/CodenameOne/src/com/codename1/ui/plaf/RoundRectBorder.java +++ b/CodenameOne/src/com/codename1/ui/plaf/RoundRectBorder.java @@ -327,6 +327,7 @@ private Image createTargetImage(Component c, int w, int h, boolean fast) { byte bgt = c.getStyle().getBgTransparency(); if(bgt != 0) { tg.setAlpha(bgt &0xff); + tg.setColor(s.getBgColor()); tg.fillShape(gp); } if(this.stroke != null && strokeOpacity > 0 && strokeThickness > 0) {