Bug 35405 - Branch target offset too large for short
Summary: Branch target offset too large for short
Status: CLOSED INVALID
Alias: None
Product: BCEL - Now in Jira
Classification: Unclassified
Component: Main (show other bugs)
Version: 5.1
Hardware: Other Windows 2000
: P1 blocker
Target Milestone: ---
Assignee: issues@commons.apache.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-18 01:30 UTC by JavaPursuit
Modified: 2005-07-19 02:18 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description JavaPursuit 2005-06-18 01:30:36 UTC
We are using bcel library for code generation. And for some particualr scenarios
our method size is exceeding the method size limit defined by java (65535 bytes)
and we get the following error,

org.apache.bcel.generic.ClassGenException: Branch target offset too large for short
	at org.apache.bcel.generic.BranchInstruction.dump(BranchInstruction.java:100)
	at org.apache.bcel.generic.InstructionList.getByteCode(InstructionList.java:980)
	at org.apache.bcel.generic.MethodGen.getMethod(MethodGen.java:616)
When the method size limit is defined in java as 65535, why does the BCEL gives
an error for 32767, in
org.apache.bcel.generic.BranchInstruction.dump(DataOutputStream out) the check
is for,

if(Math.abs(index) >= 32767) // too large for short
      throw new ClassGenException("Branch target offset too large for short");

why not instead have the if(Math.abs(index) >= 65535)

I tried this and then my application works fine, I want to be sure if thats the
right approach.
Comment 1 Dave Brosius 2005-07-17 03:13:30 UTC
From Java class specification for 

if_icmp<cond>


If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 are used 
to construct a signed 16-bit offset, where the offset is calculated to be 
(branchbyte1 << 8) | branchbyte2