View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0022807||FPC||Compiler||public||2012-09-05 23:12||2013-02-28 23:45|
|Reporter||Seva Alekseyev||Assigned To||Jonas Maebe|
|Fixed in Version||3.0.0|
|Summary||0022807: Really long if/loop statements cause Java assembly error|
|Description||When compiling Free Pascal to JVM, the compiler emits "goto" assembly statements for Pascal if statements and loops. The goto statement in Java is a near jump - it's limited to offsets of 32KB. When the body of the loop/if is large, the target of the goto can become more than 32KB of bytecode away from the point of goto. When the Jasmin assembler encounters that, it errors out with the message like this:|
MyFile.j:50599: JAS Error: reference from line 10039 exceed size for short.
where the second number refers to the line in the generated .j file that's after the failed goto line.
For branch command that can work beyond the 32KB boundary, use the goto_w Java assembly command.
|Steps To Reproduce||Install the FPC for Java from the following link:|
as taken from http://wiki.freepascal.org/FPC_JVM
Compile the attached file with the following command:
ppcjvm -XP a.pas
See the error message.
|Tags||No tags attached.|
|Fixed in Revision||22347|
a.pas (247,599 bytes)
The bug itself is actually fixed in Jasmin, it will now automatically replace goto with goto_w when required (just like it does with ldc/ldc_w etc). You can get a new jasmin.jar from ftp://ftp.freepascal.org/pub/fpc/contrib/jvm/fpcjvmutilities.zip
Note that your program is still invalid, because a Java method can maximally contain 64KB of Java bytecode, and your source code compiles to 260kb of bytecode. The compiler cannot check this because it has no idea about the size of the generated code (since the JVM byte code is variable length and since the compiler relies on the assembler to automatically select between regular and wide versions of opcodes, this would more or less require integrating the assembler into the compiler, in which I'm not interested). And the Jasmin assembler apparently also does not check for this. So you'll only get a verification error from the JVM in that case.
|2012-09-05 23:12||Seva Alekseyev||New Issue|
|2012-09-05 23:12||Seva Alekseyev||File Added: a.pas|
|2012-09-05 23:54||Jonas Maebe||Status||new => assigned|
|2012-09-05 23:54||Jonas Maebe||Assigned To||=> Jonas Maebe|
|2012-09-06 20:53||Jonas Maebe||Fixed in Revision||=> 22347|
|2012-09-06 20:53||Jonas Maebe||Status||assigned => resolved|
|2012-09-06 20:53||Jonas Maebe||Fixed in Version||=> 2.7.1|
|2012-09-06 20:53||Jonas Maebe||Resolution||open => fixed|
|2012-09-06 20:53||Jonas Maebe||Note Added: 0062148|