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

[jvm] castledb vs. JVM #8872

Closed
Simn opened this issue Oct 12, 2019 · 2 comments
Assignees
Labels
Milestone

Comments

@Simn
Copy link
Member

@Simn Simn commented Oct 12, 2019

Exception in thread "main" java.lang.VerifyError: Inconsistent stackmap frames at branch target 689
Exception Details:
  Location:
    cdb/Parser.save(Ljava/lang/Object;)Ljava/lang/String; @689: invokevirtual
  Reason:
    Type 'java/lang/Integer' (current frame, stack[1]) is not assignable to 'java/lang/String' (stack map, stack[1])
  Current Frame:
    bci: @684
    flags: { }
    locals: { 'java/lang/Object', 'haxe/root/Array', 'haxe/root/Array', integer, 'haxe/root/Array', 'java/lang/Object', 'java/lang/String', 'haxe/root/Array', integer, 'haxe/ds/StringMap', 'haxe/root/Array', integer, 'haxe/root/Array', integer, 'java/lang/String' }
    stack: { 'haxe/root/Array', 'java/lang/Integer' }
  Stackmap Frame:
    bci: @689
    flags: { }
    locals: { 'java/lang/Object', 'haxe/root/Array', 'haxe/root/Array', integer, 'haxe/root/Array', 'java/lang/Object', 'java/lang/String', 'haxe/root/Array', integer, 'haxe/ds/StringMap', 'haxe/root/Array', integer, 'haxe/root/Array', integer, 'java/lang/String' }
    stack: { 'haxe/root/Array', 'java/lang/String' }

Didn't investigate yet, but it's probably some nasty Dynamic situation.

@Simn Simn added the platform-jvm label Oct 12, 2019
@RealyUniqueName RealyUniqueName added this to the Bugs milestone Oct 18, 2019
@Simn Simn self-assigned this Oct 31, 2019
@Simn

This comment has been minimized.

Copy link
Member Author

@Simn Simn commented Oct 31, 2019

Reduced to this unholy mess:

class Main {
	static public function main() {
		var d:Array<Dynamic> = [];
		d.push(Math.random() > 0.5 ? (0 : Dynamic) : ("foo" : Dynamic));
	}
}

Dump seems fine:

@:used
class Main {

	@:keep
	public static function main[Function:Void -> Void]
		[Block:Int]
			[Var d(3162):Array<Dynamic>] [ArrayDecl:Array<Dynamic>]
			[Call:Int]
				[Field:(x : Dynamic) -> Int]
					[Local d(3162):Array<Dynamic>:Array<Dynamic>]
					[FInstance:(x : Dynamic) -> Int]
						Array<Dynamic>
						push:(x : Array.T) -> Int
				[If:Dynamic]
					[Parenthesis:Bool]
						[Binop:Bool]
							[Call:Float]
								[Field:Void -> Float]
									[TypeExpr java.lang.Math:Class<Math>]
									[FStatic:Void -> Float]
										java.lang.Math
										random:Void -> Float
							>
							[Const:Float] 0.5
					[Then:Dynamic] [Cast:Dynamic] [Const:Int] 0
					[Else:Dynamic] [Cast:Dynamic] [Const:java.lang.String] "foo"
}

Generated code:

       0: iconst_0
       1: anewarray     #6                  // class java/lang/Object
       4: invokestatic  #12                 // Method haxe/root/Array.ofNative:([Ljava/lang/Object;)Lhaxe/root/Array;
       7: astore_0
       8: aload_0
       9: invokestatic  #18                 // Method java/lang/Math.random:()D
      12: ldc2_w        #19                 // double 0.5d
      15: dcmpl
      16: ifle          26
      19: iconst_0
      20: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      23: goto          28
      26: ldc           #28                 // String foo
      28: invokevirtual #34                 // Method haxe/root/Array.push:(Ljava/lang/Object;)I
      31: pop
      32: return

Both branches have to cast to Object I guess.

@Simn Simn closed this in 425cee9 Oct 31, 2019
@Simn

This comment has been minimized.

Copy link
Member Author

@Simn Simn commented Oct 31, 2019

This change doesn't actually affect the generated code because genjvm never generates a cast to Object due to this code:

		| TObject(path1,_),TObject(path2,_) ->
			if path1 = object_path then begin
				(* We should never need a checkcast to Object, but we should adjust the stack so stack maps are wide enough *)
				ignore(code#get_stack#pop);
				code#get_stack#push object_sig
			end else
				code#checkcast path1;

This means that it adjusts the stack to hold Object instead of the narrower type, which I "think" is correct.

RealyUniqueName added a commit that referenced this issue Oct 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.