B4J Question How to calculate the "bytecode size" of a subroutine?

Mashiane

Expert
Licensed User
Longtime User
Hi there

There is a Java limit of 64kb of bytecode per method.

I'd like to run an analysis on my code, I'm managing well to split large subs into smaller pieces but then wondering if its possible just to take the string of your sub, pass it to some "bytecode calculator" which will tell you the size of "bytecode"? I guess this way I can easily target large subs, or rather count the number of lines of my subs?

#JustWondering
 

emexes

Expert
Licensed User
The size of generated files under the project's Object\bin folder might be a good first estimate.

Also, I vaguely recall using a Java decompiler to work out wtf was going on when diagnosing a similar problem a couple of years back.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
If you even think you need to do this your Subs are too large. Many small Subs are better than a few large ones - easier to understand and easier to maintain.

Historically Smalltalk is a famous example - a Smalltalk image contains thousands of methods, many being only two or three lines of code!
 
Upvote 0
Top