Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some jar files fail with "Invalid bytecode found: 20 at location 0 in method main()" #15

Closed
texadactyl opened this issue Aug 18, 2022 · 12 comments
Assignees

Comments

@texadactyl
Copy link
Contributor

Built a simple .jar file from a manifest and 3 small class files.

++ java -jar specrel.jar

t_deltaAtRest: 10.0, x_lengthAtRest: 42.0
v: 0.1 * c, Time(s): 10.0 --> 10.05037815259212
	Length(m): 42.0 --> 41.78947235847804
v: 0.2 * c, Time(s): 10.0 --> 10.206207261596576
	Length(m): 42.0 --> 41.151427678757386
v: 0.30000000000000004 * c, Time(s): 10.0 --> 10.482848367219182
	Length(m): 42.0 --> 40.06544645951172
v: 0.4 * c, Time(s): 10.0 --> 10.910894511799619
	Length(m): 42.0 --> 38.49363583762906
v: 0.5 * c, Time(s): 10.0 --> 11.547005383792516
	Length(m): 42.0 --> 36.37306695894642
v: 0.6 * c, Time(s): 10.0 --> 12.5
	Length(m): 42.0 --> 33.6
v: 0.7 * c, Time(s): 10.0 --> 14.002800840280099
	Length(m): 42.0 --> 29.993999399879968
v: 0.7999999999999999 * c, Time(s): 10.0 --> 16.666666666666664
	Length(m): 42.0 --> 25.200000000000003
v: 0.8999999999999999 * c, Time(s): 10.0 --> 22.94157338705617
	Length(m): 42.0 --> 18.307375562870835


++ jacobin -jar specrel.jar

Invalid bytecode found: 20 at location 0 in method main() of class specrel/CommandLine

Error: could not find or load class specrel/Lorentz.
Error: could not find or load class specrel/Formulae.

See README.txt in the attached ZIP file for tree layout (small), bash scripts, and Java source files.

tinyjar.zip

@texadactyl
Copy link
Contributor Author

texadactyl commented Aug 18, 2022

With -verbose:finest,
lastlog.txt

javac --version
javac 11.0.16

java --version
openjdk 11.0.16 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)

@texadactyl
Copy link
Contributor Author

Looking at run.go, I can see that the opcode entries between 0x12 (ldc) and iload (0x15) are missing, namely:

  • ldc_w (0x13) - Push item from run-time constant pool (wide index)
  • ldc2_w (0x14) - Push long or double from run-time constant pool (wide index)

The 0x14 (20) is what was diagnosed in the default case of the switch statement in func runFrame. Maybe this is still a work in progress.

@platypusguy
Copy link
Owner

Thanks for this report, Richard. The interpreter is still very much in development and there are instructions, such as the one you ran into, that are unimplemented. We'll get to them all!

@platypusguy platypusguy self-assigned this Aug 27, 2022
@platypusguy
Copy link
Owner

Those missing instructions have been added and should be working correctly now.

@texadactyl
Copy link
Contributor Author

texadactyl commented Dec 13, 2022

Project tinyjar (no changes) proceeds further and then runs into another missing bytecode .....

compile.sh
++ javac -O -g -Xlint:unchecked specrel/CommandLine.java specrel/Formulae.java specrel/Lorentz.java
++ jar cfmv specrel.jar Manifest.txt specrel/CommandLine.class specrel/Formulae.class specrel/Lorentz.class
added manifest
adding: specrel/CommandLine.class(in = 1950) (out= 1096)(deflated 43%)
adding: specrel/Formulae.class(in = 486) (out= 306)(deflated 37%)
adding: specrel/Lorentz.class(in = 465) (out= 338)(deflated 27%)
++ jar tvf specrel.jar
     0 Tue Dec 13 11:22:02 CST 2022 META-INF/
    88 Tue Dec 13 11:22:02 CST 2022 META-INF/MANIFEST.MF
  1950 Tue Dec 13 11:22:02 CST 2022 specrel/CommandLine.class
   486 Tue Dec 13 11:22:02 CST 2022 specrel/Formulae.class
   465 Tue Dec 13 11:22:02 CST 2022 specrel/Lorentz.class
 run.sh
++ jacobin -trace -jar specrel.jar
[  0.178s] class: specrel/CommandLine, meth: main, pc: 0, inst: LDC2_W, tos: -1
[  0.178s] class: specrel/CommandLine, meth: main, pc: 3, inst: DSTORE_1, tos: 1
Invalid bytecode found: 72 at location 3 in method main() of class specrel/CommandLine

Bytecode 72 (0x48) : store a double into local variable 1
reference: https://en.wikipedia.org/wiki/List_of_Java_bytecode_instructions

@texadactyl
Copy link
Contributor Author

texadactyl commented Dec 13, 2022

I also saw that FNEG (negate a float i.e. 0x76) is commented out. Pending work on floating point in general?

		// case FNEG: //	0x76	(negate a float)
		// 	val := float64(pop(f))
		// 	val = val * (-1.0)
		// 	push(f, val) // CURR: resume here

Why val = val * (-1.0) and not val = -val?

@texadactyl
Copy link
Contributor Author

texadactyl commented Dec 13, 2022

Okay, it looks like you haven't gotten around to floating point operations. All in good time.

@platypusguy
Copy link
Owner

Thanks for staying with this. @suresk is working on floating-point and I'm helping him out (I think!).

To avoid you having to run the file each time we update and run into an instruction we're still implementing, maybe consider running javap -v on the file and send us the listing and we can prioritize the bytecodes you need.

Either way, thanks for your continued support!

@suresk
Copy link
Collaborator

suresk commented Dec 17, 2022

I actually have the jar and am using it as a rough test case. The opcodes we are missing are:

DADD
DMUL
DSTORE_* methods
INVOKEDYNAMIC
DDIV
INVOKESPECIAL
DLOAD_* methods
DSUB

All of the double ones should be easy and I will have implemented shortly, but the invoke ones are a bit more.

@texadactyl
Copy link
Contributor Author

texadactyl commented Dec 19, 2022

@suresk You have the zip file too? That has the source and the scripts for building the jar. The whole tree, actually.

@texadactyl
Copy link
Contributor Author

texadactyl commented Dec 19, 2022

tinyjar.zip is a subset of the desired project: https://github.com/texadactyl/scimark2.java

Scimark ver 2 will be an interesting scientific app performance comparison between java and jacobin.

@texadactyl
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants