HaxeFoundation / HaxeFoundation/haxe

[jvm] Unexpected/Broken behavior when working with public properties in class from external Jar

Open
#10,080 6 comments 0 reactions 1 assignee Claimed by @Simn View on GitHub
platform-jvm
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

So, this is a pretty odd issue that I recently stumbled upon.

I am working with [JOML](https://github.com/JOML-CI/JOML) Vectors and I have found that trying to access public properties (x,y,z,w) gives me some weird errors.

For example when working with [Vector3f](https://github.com/JOML-CI/JOML/blob/abcec058398032b62353cf28c60d98009927ff4c/src/org/joml/Vector3f.java#L52)

`trace(vector.x)` gives me the following:
```
_ArcBallCameraDemo.ArcBallCameraDemo_Fields_$Vector3f_x@d4a2a0ad
```

`trace(cast(vector.x, Float))` gives me:
```
_ArcBallCameraDemo.ArcBallCameraDemo_Fields_$Vector3f_x incompatible with java.lang.Number
```

`trace(vector.x())` works as expected giving me:
```
0.0
```

`trace(vector.x() * -1)` gives me -0.0, which shouldn't be possible.
```
-0.0
```

`trace(-vector.x())` gives me the following with AdoptOpenJDK OpenJ9 15.0.1:
```
Error: Unable to initialize main class _ArcBallCameraDemo.ArcBallCameraDemo_Fields_
Caused by: java.lang.VerifyError: JVMVRFY012 stack shape inconsistent; class=_ArcBallCameraDemo/ArcBallCameraDemo_Fields_, method=loop()V, pc=101; Type Mismatch, argument 0 in signature haxe/jvm/Jvm.opNeg:(Ljava/lang/Object;)Ljava/lang/Object; does not match
Exception Details:
Location:
_ArcBallCameraDemo/ArcBallCameraDemo_Fields_.loop()V @101: JBinvokestatic
Reason:
Type float (current frame, stack[1]) is not assignable to 'java/lang/Object'
Current Frame:
bci: @101
flags: { }
locals: { 'org/joml/Matrix4f', 'java/nio/FloatBuffer' }
stack: { 'haxe/jvm/Function', float }
Stackmap Table:
append_frame(@14,Object[#74],Object[#78])
same_frame(@23)
same_frame_extended(@235)
Error: Command failed with error 1
```

`trace(-vector.x())` gives me the following with AdoptOpenJDK Hotspot 15.0.0:
```
Error: Unable to initialize main class _ArcBallCameraDemo.ArcBallCameraDemo_Fields_
Caused by: java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
_ArcBallCameraDemo/ArcBallCameraDemo_Fields_.loop()V @101: invokestatic
Reason:
Type float (current frame, stack[1]) is not assignable to 'java/lang/Object'
Current Frame:
bci: @101
flags: { }
locals: { 'org/joml/Matrix4f', 'java/nio/FloatBuffer' }
stack: { 'haxe/jvm/Function', float }
Bytecode:
0000000: bb00 d659 b700 d84b 1010 b800 de4c b200
0000010: 5eb8 00e4 9a00 d703 03b2 004b b200 4eb8
0000020: 00e8 b200 ebb2 00ee 80b8 00f1 b200 f4b8
0000030: 00f7 2a14 00f8 b200 fe6b 1400 ff6f 90b2
0000040: 004b 87b2 004e 876f 9013 0101 1064 86b6
0000050: 0105 2bb6 0109 b801 0db2 0113 c000 6ab2
0000060: 0116 b601 1cb8 0121 b801 25bb 0127 5913
0000070: 0129 1301 2b10 7213 012d b701 30b6 0134
0000080: 2a03 8603 86b2 0137 7790 b601 3bb2 013e
0000090: 90b6 0142 b201 4590 b601 48b2 0116 b601
00000a0: 1c02 866a b201 16b6 014b 0286 6ab2 0116
00000b0: b601 4e02 866a b601 5157 b201 54b8 00f7
00000c0: 2a2b b601 09b8 010d b801 572a b201 16c0
00000d0: 0159 b601 5c2b b601 09b8 010d b801 5fb2
00000e0: 005e b801 62b8 0165 a7ff 26b1
Stackmap Table:
append_frame(@14,Object[#214],Object[#224])
same_frame(@23)
same_frame_extended(@235)

Error: Command failed with error 1
```

I would expect to be able to just do `-vector.x` and not `-vector.x()` or `vector.x() * -1`.

I found this issue with my code here:

https://github.com/davidbruce/haxe-lwjgl-examples/blob/9aa172bc0ef35cb5ed704646982d1818fc3bdab4/src/ArcBallCameraDemo.hx#L117

I'm getting the JOML jars from my project [here](https://github.com/davidbruce/haxe-joml) and LWJGL [here](https://github.com/davidbruce/haxe-lwjgl)

I am on OSX using Haxe version `4.2.0-rc.1+5145ddb` from the build on 2021-01-16

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.