View Issue Details

IDProjectCategoryView StatusLast Update
0022807FPCCompilerpublic2013-02-28 23:45
ReporterSeva Alekseyev Assigned ToJonas Maebe  
PrioritynormalSeveritymajorReproducibilitysometimes
Status resolvedResolutionfixed 
PlatformJVMOSWindows 
Product Version2.7.1 
Fixed in Version3.0.0 
Summary0022807: Really long if/loop statements cause Java assembly error
DescriptionWhen 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 ReproduceInstall the FPC for Java from the following link:
http://sourceforge.net/projects/freepascal/files/JVM/2.7.1-r19830-snapshot3/fpcjvmwin32-snapshot3.zip/download

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.
TagsNo tags attached.
Fixed in Revision22347
FPCOldBugId
FPCTarget
Attached Files

Activities

2012-09-05 23:12

 

a.pas (247,599 bytes)

Jonas Maebe

2012-09-06 20:53

manager   ~0062148

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.

Issue History

Date Modified Username Field Change
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