Discussion:
"Uncaught translation error" when transforming Kawa-compiled classes with dex
Kay Zheng
2017-08-29 17:10:26 UTC
Permalink
Hi Per,

I tried building a simple skeleton Android app against the master
branch, targeting Android API level 21 (Android 5.0). The compilation
went well, but there's this ambiguous error when classes are being
transformed to dex files:

Uncaught translation error: com.android.dx.cf.code.SimException:
local variable type mismatch: attempt to set or access a value of type
int using a local variable of type gnu.mapping.CallContext. This is
symptomatic of .class transformation tools that ignore local variable
information.

I don't really understand this error message, but since
gnu.mapping.CallContext is part of Kawa, I'd try and post it in this
mailing list.

The source code for the skeleton app is on
https://github.com/l04m33/KawaAndroidTemplate

And here's how I built Kawa (I didn't install JDK 6, and used OpenJDK
8 instead, thus the explicit JAVACFLAGS):

$ cat rebuild-kawa-latest-android.sh
#!/bin/sh

cd ./Kawa-latest-android

if [ -f 'Makefile' ]; then
make clean
make distclean
fi

git checkout -- .
git apply ../kawa-javacflags.patch

./autogen.sh
export JAVACFLAGS="-g -source 1.6 -target 1.6"
./configure
--with-android=/home/user/android_sdk/platforms/android-21/android.jar
\
--disable-xquery \
--disable-jemacs \
--with-java-source=6
make

And the content of kawa-javacflags.patch:

$ cat kawa-javacflags.patch
diff --git a/Makefile.am b/Makefile.am
index da9e490..a0df1a3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -372,10 +372,10 @@ $(srcdir)/patch-source-list: $(top_srcdir)/configure
| sed -e 's|./||' | sort > $@

kawa/Version.class: kawa/Version.java
- $(JAVAC) -d . $^
+ $(JAVAC) -d . $(JAVACFLAGS) $^

gnu/kawa/util/PreProcess.class: gnu/kawa/util/PreProcess.java
- $(JAVAC) -d . $^
+ $(JAVAC) -d . $(JAVACFLAGS) $^

JAVA_PREPROCESS_OPTIONS = @JAVA_SOURCE_SELECTOR@
$(PREPROCESS_HTTPSERVER) $(PREPROCESS_XML) $(PREPROCESS_JLINE3)
$(PREPROCESS_AWT)

P.S.: I think this is an separate issue with hairy details, so I made
a new thread.

Regards,
Kay Z.
Sonny To
2017-08-29 17:12:52 UTC
Permalink
try using jdk 1.7
i had strange errors too when i compiled for jdk1.8
Post by Kay Zheng
Hi Per,
I tried building a simple skeleton Android app against the master
branch, targeting Android API level 21 (Android 5.0). The compilation
went well, but there's this ambiguous error when classes are being
local variable type mismatch: attempt to set or access a value of type
int using a local variable of type gnu.mapping.CallContext. This is
symptomatic of .class transformation tools that ignore local variable
information.
I don't really understand this error message, but since
gnu.mapping.CallContext is part of Kawa, I'd try and post it in this
mailing list.
The source code for the skeleton app is on
https://github.com/l04m33/KawaAndroidTemplate
And here's how I built Kawa (I didn't install JDK 6, and used OpenJDK
$ cat rebuild-kawa-latest-android.sh
#!/bin/sh
cd ./Kawa-latest-android
if [ -f 'Makefile' ]; then
make clean
make distclean
fi
git checkout -- .
git apply ../kawa-javacflags.patch
./autogen.sh
export JAVACFLAGS="-g -source 1.6 -target 1.6"
./configure
--with-android=/home/user/android_sdk/platforms/android-21/android.jar
\
--disable-xquery \
--disable-jemacs \
--with-java-source=6
make
$ cat kawa-javacflags.patch
diff --git a/Makefile.am b/Makefile.am
index da9e490..a0df1a3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -372,10 +372,10 @@ $(srcdir)/patch-source-list: $(top_srcdir)/configure
kawa/Version.class: kawa/Version.java
- $(JAVAC) -d . $^
+ $(JAVAC) -d . $(JAVACFLAGS) $^
gnu/kawa/util/PreProcess.class: gnu/kawa/util/PreProcess.java
- $(JAVAC) -d . $^
+ $(JAVAC) -d . $(JAVACFLAGS) $^
$(PREPROCESS_HTTPSERVER) $(PREPROCESS_XML) $(PREPROCESS_JLINE3)
$(PREPROCESS_AWT)
P.S.: I think this is an separate issue with hairy details, so I made
a new thread.
Regards,
Kay Z.
Kay Zheng
2017-08-29 17:30:49 UTC
Permalink
Hi Sonny,

Thanks for the suggestion.

I carelessly left out an important fact, that I've compiled the same
app against the 2.4 branch this way and it worked well, so I'd suspect
it's some changes in Kawa that caused this error. Not necessarily a
bug, though.

Regards,
Kay Z.
Post by Sonny To
try using jdk 1.7
i had strange errors too when i compiled for jdk1.8
Post by Kay Zheng
Hi Per,
I tried building a simple skeleton Android app against the master
branch, targeting Android API level 21 (Android 5.0). The compilation
went well, but there's this ambiguous error when classes are being
local variable type mismatch: attempt to set or access a value of type
int using a local variable of type gnu.mapping.CallContext. This is
symptomatic of .class transformation tools that ignore local variable
information.
I don't really understand this error message, but since
gnu.mapping.CallContext is part of Kawa, I'd try and post it in this
mailing list.
The source code for the skeleton app is on
https://github.com/l04m33/KawaAndroidTemplate
And here's how I built Kawa (I didn't install JDK 6, and used OpenJDK
$ cat rebuild-kawa-latest-android.sh
#!/bin/sh
cd ./Kawa-latest-android
if [ -f 'Makefile' ]; then
make clean
make distclean
fi
git checkout -- .
git apply ../kawa-javacflags.patch
./autogen.sh
export JAVACFLAGS="-g -source 1.6 -target 1.6"
./configure
--with-android=/home/user/android_sdk/platforms/android-21/android.jar
\
--disable-xquery \
--disable-jemacs \
--with-java-source=6
make
$ cat kawa-javacflags.patch
diff --git a/Makefile.am b/Makefile.am
index da9e490..a0df1a3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -372,10 +372,10 @@ $(srcdir)/patch-source-list: $(top_srcdir)/configure
kawa/Version.class: kawa/Version.java
- $(JAVAC) -d . $^
+ $(JAVAC) -d . $(JAVACFLAGS) $^
gnu/kawa/util/PreProcess.class: gnu/kawa/util/PreProcess.java
- $(JAVAC) -d . $^
+ $(JAVAC) -d . $(JAVACFLAGS) $^
$(PREPROCESS_HTTPSERVER) $(PREPROCESS_XML) $(PREPROCESS_JLINE3)
$(PREPROCESS_AWT)
P.S.: I think this is an separate issue with hairy details, so I made
a new thread.
Regards,
Kay Z.
Per Bothner
2017-08-29 18:01:45 UTC
Permalink
Post by Kay Zheng
I tried building a simple skeleton Android app against the master
branch, targeting Android API level 21 (Android 5.0). The compilation
went well, but there's this ambiguous error when classes are being
local variable type mismatch: attempt to set or access a value of type
int using a local variable of type gnu.mapping.CallContext. This is
symptomatic of .class transformation tools that ignore local variable
information.
Hm. It would be helpful if the error message would say what class and
method it were complaining about.

A work-around for Java code would be to Compile with -g:lines (-g:none) to
suppress of the LocalVariableTable attribute, since that is what dex seems
to be complaining about. Unfortunately, Kawa doesn't have a comparable option
for Scheme code. It shouldn't be hard to add.
Post by Kay Zheng
$ cat kawa-javacflags.patch
diff --git a/Makefile.am b/Makefile.am
index da9e490..a0df1a3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -372,10 +372,10 @@ $(srcdir)/patch-source-list: $(top_srcdir)/configure
kawa/Version.class: kawa/Version.java
- $(JAVAC) -d . $^
+ $(JAVAC) -d . $(JAVACFLAGS) $^
gnu/kawa/util/PreProcess.class: gnu/kawa/util/PreProcess.java
- $(JAVAC) -d . $^
+ $(JAVAC) -d . $(JAVACFLAGS) $^
$(PREPROCESS_HTTPSERVER) $(PREPROCESS_XML) $(PREPROCESS_JLINE3)
$(PREPROCESS_AWT)
Thanks - I fixed this in my sources. I'll check it in after I've tested it.
--
--Per Bothner
***@bothner.com http://per.bothner.com/
Kay Zheng
2017-08-29 20:13:22 UTC
Permalink
Hi Per,

Indeed it had something to do with local variable info. I added the
following snippet to the android section in build.gradle based on your
assertion, and the error went away:

dexOptions {
additionalParameters '--no-locals'
}

I also enabled the debug logs in the dx command, and here goes the
full error message (long lines, hopefully the text won't get messed
up):

Uncaught translation error:
com.android.dx.cf.code.SimException: local variable type mismatch:
attempt to set or access a value of type int using a local variable of
ty$
e gnu.mapping.CallContext. This is symptomatic of .class
transformation tools that ignore local variable information.
at com.android.dx.cf.code.BaseMachine.throwLocalMismatch(BaseMachine.java:575)
at com.android.dx.cf.code.Simulator$SimVisitor.visitLocal(Simulator.java:584)
at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:458)
at com.android.dx.cf.code.Simulator.simulate(Simulator.java:94)
at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:787)
at com.android.dx.cf.code.Ropper.doit(Ropper.java:742)
at com.android.dx.cf.code.Ropper.convert(Ropper.java:349)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:285)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:141)
at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:95)
at com.android.dx.command.dexer.Main.translateClass(Main.java:799)
at com.android.dx.command.dexer.Main.access$2800(Main.java:88)
at com.android.dx.command.dexer.Main$ClassTranslatorTask.call(Main.java:1863)
at com.android.dx.command.dexer.Main$ClassTranslatorTask.call(Main.java:1848)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
...at bytecode offset 00000152
locals[0000]: Ljava/lang/Object;
locals[0001]: Lgnu/lists/LList;
locals[0002]: Ljava/lang/Object;
locals[0003]: Ljava/lang/Object;
locals[0004]: Lgnu/math/IntNum;
locals[0005]: Ljava/lang/Boolean;
locals[0006]: Ljava/lang/Object;
locals[0007]: <invalid>
locals[0008]: Ljava/lang/Object;
stack[top0]: I
...while working on block 0152
[26/1937]
...while working on method
stringConcatenateReverse$SlShared$V:(Ljava/lang/Object;Lgnu/lists/LList;)Ljava/lang/Object;
...while processing stringConcatenateReverse$SlShared$V
(Ljava/lang/Object;Lgnu/lists/LList;)Ljava/lang/Object;
...while processing gnu/kawa/slib/srfi13.class
Uncaught translation error:
com.android.dx.cf.code.SimException: local variable type mismatch:
attempt to set or access a value of type int using a local variable of
typ
e gnu.mapping.CallContext. This is symptomatic of .class
transformation tools that ignore local variable information.
at com.android.dx.cf.code.BaseMachine.throwLocalMismatch(BaseMachine.java:575)
at com.android.dx.cf.code.Simulator$SimVisitor.visitLocal(Simulator.java:584)
at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:458)
at com.android.dx.cf.code.Simulator.simulate(Simulator.java:94)
at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:787)
at com.android.dx.cf.code.Ropper.doit(Ropper.java:742)
at com.android.dx.cf.code.Ropper.convert(Ropper.java:349)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:285)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:141)
at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:95)
at com.android.dx.command.dexer.Main.translateClass(Main.java:799)
at com.android.dx.command.dexer.Main.access$2800(Main.java:88)
at com.android.dx.command.dexer.Main$ClassTranslatorTask.call(Main.java:1863)
at com.android.dx.command.dexer.Main$ClassTranslatorTask.call(Main.java:1848)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
...at bytecode offset 00000122
locals[0000]: Lgnu/expr/ApplyExp;
[0/1937]
locals[0001]: Lgnu/expr/InlineCalls;
locals[0002]: Lgnu/bytecode/Type;
locals[0003]: Lgnu/mapping/Procedure;
locals[0004]: <invalid>
locals[0005]: Ljava/lang/String;
locals[0006]: I
locals[0007]: Lgnu/kawa/functions/NumberCompare;
locals[0008]: I
locals[0009]: <invalid>
locals[000a]: <invalid>
locals[000b]: <invalid>
locals[000c]: <invalid>
stack[top0]: int{0x00000000 / 0}
...while working on block 011f
...while working on method
charCompareValidateApply:(Lgnu/expr/ApplyExp;Lgnu/expr/InlineCalls;Lgnu/bytecode/Type;Lgnu/mapping/Procedure;)Lgn$
/expr/Expression;
...while processing charCompareValidateApply
(Lgnu/expr/ApplyExp;Lgnu/expr/InlineCalls;Lgnu/bytecode/Type;Lgnu/mapping/Procedure;)Lgnu/expr/$
xpression;
...while processing kawa/lib/compile_misc.class
2 errors; aborting

================== the error message ends here ==================

Regards,
Kay Z.
Post by Per Bothner
Post by Kay Zheng
I tried building a simple skeleton Android app against the master
branch, targeting Android API level 21 (Android 5.0). The compilation
went well, but there's this ambiguous error when classes are being
local variable type mismatch: attempt to set or access a value of type
int using a local variable of type gnu.mapping.CallContext. This is
symptomatic of .class transformation tools that ignore local variable
information.
Hm. It would be helpful if the error message would say what class and
method it were complaining about.
A work-around for Java code would be to Compile with -g:lines (-g:none) to
suppress of the LocalVariableTable attribute, since that is what dex seems
to be complaining about. Unfortunately, Kawa doesn't have a comparable option
for Scheme code. It shouldn't be hard to add.
Post by Kay Zheng
$ cat kawa-javacflags.patch
diff --git a/Makefile.am b/Makefile.am
index da9e490..a0df1a3 100644
--- a/Makefile.am
+++ b/Makefile.am
$(top_srcdir)/configure
kawa/Version.class: kawa/Version.java
- $(JAVAC) -d . $^
+ $(JAVAC) -d . $(JAVACFLAGS) $^
gnu/kawa/util/PreProcess.class: gnu/kawa/util/PreProcess.java
- $(JAVAC) -d . $^
+ $(JAVAC) -d . $(JAVACFLAGS) $^
$(PREPROCESS_HTTPSERVER) $(PREPROCESS_XML) $(PREPROCESS_JLINE3)
$(PREPROCESS_AWT)
Thanks - I fixed this in my sources. I'll check it in after I've tested it.
--
--Per Bothner
Per Bothner
2017-08-29 20:30:51 UTC
Permalink
Post by Kay Zheng
attempt to set or access a value of type int using a local variable of
ty$
e gnu.mapping.CallContext. This is symptomatic of .class
transformation tools that ignore local variable information.
at com.android.dx.cf.code.BaseMachine.throwLocalMismatch(BaseMachine.java:575)
at com.android.dx.cf.code.Simulator$SimVisitor.visitLocal(Simulator.java:584)
at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:458)
at com.android.dx.cf.code.Simulator.simulate(Simulator.java:94)
at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:787)
at com.android.dx.cf.code.Ropper.doit(Ropper.java:742)
at com.android.dx.cf.code.Ropper.convert(Ropper.java:349)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:285)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:141)
at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:95)
at com.android.dx.command.dexer.Main.translateClass(Main.java:799)
at com.android.dx.command.dexer.Main.access$2800(Main.java:88)
at com.android.dx.command.dexer.Main$ClassTranslatorTask.call(Main.java:1863)
at com.android.dx.command.dexer.Main$ClassTranslatorTask.call(Main.java:1848)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
...
...while working on method
stringConcatenateReverse$SlShared$V:(Ljava/lang/Object;Lgnu/lists/LList;)Ljava/lang/Object;
...while processing stringConcatenateReverse$SlShared$V
(Ljava/lang/Object;Lgnu/lists/LList;)Ljava/lang/Object;
I do see a problem. The method stringConcatenateReverse$SlShared$V in srfi13.class has
the following:

Attribute "LocalVariableTable", length:92, count: 9
slot#0: name: string-list, type: java.lang.Object (pc: 0 length: 662)
slot#1: name: maybe-final+end, type: gnu.lists.LList (pc: 0 length: 662)
slot#2: name: final, type: java.lang.Object (pc: 23 length: 639)
slot#3: name: end, type: java.lang.Object (pc: 124 length: 538)
slot#4: name: len, type: java.lang.Object (pc: 300 length: 247)
slot#5: name: nzlist, type: java.lang.Object (pc: 300 length: 247)
slot#6: name: lis, type: java.lang.Object (pc: 300 length: 247)
slot#7: name: $ctx, type: gnu.mapping.CallContext (pc: 300 length: 247)
slot#7: name: slen, type: int (pc: 340 length: 67)

Notice slot 7 is used for two different variables, of different types - and their
PC ranges overlap. Hm.
--
--Per Bothner
***@bothner.com http://per.bothner.com/
Per Bothner
2017-08-30 00:39:36 UTC
Permalink
I do see a problem.  The method stringConcatenateReverse$SlShared$V in srfi13.class has
Attribute "LocalVariableTable", length:92, count: 9
  slot#0: name: string-list, type: java.lang.Object (pc: 0 length: 662)
  slot#1: name: maybe-final+end, type: gnu.lists.LList (pc: 0 length: 662)
  slot#2: name: final, type: java.lang.Object (pc: 23 length: 639)
  slot#3: name: end, type: java.lang.Object (pc: 124 length: 538)
  slot#4: name: len, type: java.lang.Object (pc: 300 length: 247)
  slot#5: name: nzlist, type: java.lang.Object (pc: 300 length: 247)
  slot#6: name: lis, type: java.lang.Object (pc: 300 length: 247)
  slot#7: name: $ctx, type: gnu.mapping.CallContext (pc: 300 length: 247)
  slot#7: name: slen, type: int (pc: 340 length: 67)
Notice slot 7 is used for two different variables, of different types - and their
PC ranges overlap.  Hm.
I checked in a fix for this. Please try again.
--
--Per Bothner
***@bothner.com http://per.bothner.com/
Kay Zheng
2017-08-30 05:33:58 UTC
Permalink
Thank you! I think the fix worked, and the APK was built successfully.

The app failed to run though. A ClassNotFound exception regarding my
main activity, much like what Sonny To reported in another thread a
while ago. But this is most likely a separate issue, not necessarily
relevant to Kawa. I'll try digging around and see if I can find
anything.
Thank you! I think the fix worked, and the APK was built successfully.
The APK failed to run though. A ClassNotFound exception regarding my main
activity, much like what Sonny To reported in another thread a while ago.
But this is most likely a separate issue, not necessarily relevant to Kawa.
I'll try digging around and see if I can find anything.
Post by Per Bothner
Post by Per Bothner
I do see a problem. The method stringConcatenateReverse$SlShared$V in srfi13.class has
Attribute "LocalVariableTable", length:92, count: 9
slot#0: name: string-list, type: java.lang.Object (pc: 0 length: 662)
slot#1: name: maybe-final+end, type: gnu.lists.LList (pc: 0 length: 662)
slot#2: name: final, type: java.lang.Object (pc: 23 length: 639)
slot#3: name: end, type: java.lang.Object (pc: 124 length: 538)
slot#4: name: len, type: java.lang.Object (pc: 300 length: 247)
slot#5: name: nzlist, type: java.lang.Object (pc: 300 length: 247)
slot#6: name: lis, type: java.lang.Object (pc: 300 length: 247)
slot#7: name: $ctx, type: gnu.mapping.CallContext (pc: 300 length: 247)
slot#7: name: slen, type: int (pc: 340 length: 67)
Notice slot 7 is used for two different variables, of different types - and their
PC ranges overlap. Hm.
I checked in a fix for this. Please try again.
--
--Per Bothner
Loading...