8299183: Invokers.checkExactType passes parameters to create WMTE in opposite order

Reviewed-by: iris, jpai
This commit is contained in:
Mandy Chung 2023-01-10 17:05:33 +00:00
parent 8b0133f276
commit a86b6f6fde
4 changed files with 102 additions and 18 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -494,8 +494,7 @@ class Invokers {
@Hidden
static MethodHandle checkVarHandleGenericType(VarHandle handle, VarHandle.AccessDescriptor ad) {
if (handle.hasInvokeExactBehavior() && handle.accessModeType(ad.type) != ad.symbolicMethodTypeExact) {
throw new WrongMethodTypeException("expected " + handle.accessModeType(ad.type) + " but found "
+ ad.symbolicMethodTypeExact);
throw newWrongMethodTypeException(handle.accessModeType(ad.type), ad.symbolicMethodTypeExact);
}
// Test for exact match on invoker types
// TODO match with erased types and add cast of return value to lambda form
@ -518,18 +517,18 @@ class Invokers {
}
/*non-public*/
static WrongMethodTypeException newWrongMethodTypeException(MethodType actual, MethodType expected) {
static WrongMethodTypeException newWrongMethodTypeException(MethodType targetType, MethodType callSiteType) {
// FIXME: merge with JVM logic for throwing WMTE
return new WrongMethodTypeException("expected "+expected+" but found "+actual);
return new WrongMethodTypeException("handle's method type " + targetType + " but found " + callSiteType);
}
/** Static definition of MethodHandle.invokeExact checking code. */
@ForceInline
/*non-public*/
static void checkExactType(MethodHandle mh, MethodType expected) {
MethodType actual = mh.type();
if (actual != expected)
throw newWrongMethodTypeException(expected, actual);
MethodType targetType = mh.type();
if (targetType != expected)
throw newWrongMethodTypeException(targetType, expected);
}
/** Static definition of MethodHandle.invokeGeneric checking code.

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -2083,8 +2083,8 @@ public abstract sealed class VarHandle implements Constable
@DontInline
private final void throwWrongMethodTypeException(VarHandle.AccessDescriptor ad) {
throw new WrongMethodTypeException("expected " + accessModeType(ad.type) + " but found "
+ ad.symbolicMethodTypeExact);
throw new WrongMethodTypeException("handle's method type " + accessModeType(ad.type)
+ " but found " + ad.symbolicMethodTypeExact);
}
@ForceInline