Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
a5a284b3
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a5a284b3
编写于
9月 17, 2014
作者:
V
vlivanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8058626: Missing part of 8057656 in 8u40 compared to 9
Reviewed-by: psandoz
上级
fd9d69e3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
61 addition
and
35 deletion
+61
-35
src/share/classes/java/lang/invoke/MethodHandles.java
src/share/classes/java/lang/invoke/MethodHandles.java
+5
-2
src/share/classes/java/lang/invoke/MethodType.java
src/share/classes/java/lang/invoke/MethodType.java
+56
-33
未找到文件。
src/share/classes/java/lang/invoke/MethodHandles.java
浏览文件 @
a5a284b3
...
...
@@ -2024,8 +2024,11 @@ return invoker;
*/
public
static
MethodHandle
explicitCastArguments
(
MethodHandle
target
,
MethodType
newType
)
{
if
(!
target
.
type
().
isCastableTo
(
newType
))
{
throw
new
WrongMethodTypeException
(
"cannot explicitly cast "
+
target
+
" to "
+
newType
);
MethodType
oldType
=
target
.
type
();
// use the asTypeCache when possible:
if
(
oldType
==
newType
)
return
target
;
if
(
oldType
.
explicitCastEquivalentToAsType
(
newType
))
{
return
target
.
asType
(
newType
);
}
return
MethodHandleImpl
.
makePairwiseConvert
(
target
,
newType
,
false
);
}
...
...
src/share/classes/java/lang/invoke/MethodType.java
浏览文件 @
a5a284b3
...
...
@@ -827,26 +827,6 @@ class MethodType implements java.io.Serializable {
return
true
;
}
/*non-public*/
boolean
isCastableTo
(
MethodType
newType
)
{
MethodTypeForm
oldForm
=
this
.
form
();
MethodTypeForm
newForm
=
newType
.
form
();
if
(
oldForm
==
newForm
)
// same parameter count, same primitive/object mix
return
true
;
int
argc
=
parameterCount
();
if
(
argc
!=
newType
.
parameterCount
())
return
false
;
// Corner case: boxing (primitive-to-reference) must have a plausible target type
// Therefore, we may have to return false for a boxing operation.
if
(!
canCast
(
returnType
(),
newType
.
returnType
()))
return
false
;
if
(
newForm
.
primitiveParameterCount
()
==
0
)
return
true
;
// no primitive sources to mess things up
if
(
oldForm
.
erasedType
==
this
)
return
true
;
// no funny target references to mess things up
return
canCastParameters
(
newType
.
ptypes
,
ptypes
);
}
/*non-public*/
boolean
isConvertibleTo
(
MethodType
newType
)
{
MethodTypeForm
oldForm
=
this
.
form
();
MethodTypeForm
newForm
=
newType
.
form
();
...
...
@@ -877,15 +857,68 @@ class MethodType implements java.io.Serializable {
return
canConvertParameters
(
srcTypes
,
dstTypes
);
}
private
boolean
canCastParameters
(
Class
<?>[]
srcTypes
,
Class
<?>[]
dstTypes
)
{
for
(
int
i
=
0
;
i
<
srcTypes
.
length
;
i
++)
{
if
(!
canCast
(
srcTypes
[
i
],
dstTypes
[
i
]))
{
/** Returns true if MHs.explicitCastArguments produces the same result as MH.asType.
* If the type conversion is impossible for either, the result should be false.
*/
/*non-public*/
boolean
explicitCastEquivalentToAsType
(
MethodType
newType
)
{
if
(
this
==
newType
)
return
true
;
if
(!
explicitCastEquivalentToAsType
(
rtype
,
newType
.
rtype
))
{
return
false
;
}
Class
<?>[]
srcTypes
=
newType
.
ptypes
;
Class
<?>[]
dstTypes
=
ptypes
;
if
(
dstTypes
==
srcTypes
)
{
return
true
;
}
if
(
dstTypes
.
length
!=
srcTypes
.
length
)
{
return
false
;
}
for
(
int
i
=
0
;
i
<
dstTypes
.
length
;
i
++)
{
if
(!
explicitCastEquivalentToAsType
(
srcTypes
[
i
],
dstTypes
[
i
]))
{
return
false
;
}
}
return
true
;
}
/** Reports true if the src can be converted to the dst, by both asType and MHs.eCE,
* and with the same effect.
* MHs.eCA has the following "upgrades" to MH.asType:
* 1. interfaces are unchecked (that is, treated as if aliased to Object)
* Therefore, {@code Object->CharSequence} is possible in both cases but has different semantics
* 2. the full matrix of primitive-to-primitive conversions is supported
* Narrowing like {@code long->byte} and basic-typing like {@code boolean->int}
* are not supported by asType, but anything supported by asType is equivalent
* with MHs.eCE.
* 3a. unboxing conversions can be followed by the full matrix of primitive conversions
* 3b. unboxing of null is permitted (creates a zero primitive value)
* Most unboxing conversions, like {@code Object->int}, has potentially
* different behaviors for asType vs. MHs.eCE, because the dynamic value
* might be a wrapper of a type that requires narrowing, like {@code (Object)1L->byte}.
* The equivalence is only certain if the static src type is a wrapper,
* and the conversion will be a widening one.
* Other than interfaces, reference-to-reference conversions are the same.
* Boxing primitives to references is the same for both operators.
*/
private
static
boolean
explicitCastEquivalentToAsType
(
Class
<?>
src
,
Class
<?>
dst
)
{
if
(
src
==
dst
||
dst
==
Object
.
class
||
dst
==
void
.
class
)
return
true
;
if
(
src
.
isPrimitive
())
{
// Could be a prim/prim conversion, where casting is a strict superset.
// Or a boxing conversion, which is always to an exact wrapper class.
return
canConvert
(
src
,
dst
);
}
else
if
(
dst
.
isPrimitive
())
{
Wrapper
dw
=
Wrapper
.
forPrimitiveType
(
dst
);
// Watch out: If src is Number or Object, we could get dynamic narrowing conversion.
// The conversion is known to be widening only if the wrapper type is statically visible.
return
(
Wrapper
.
isWrapperType
(
src
)
&&
dw
.
isConvertibleFrom
(
Wrapper
.
forWrapperType
(
src
)));
}
else
{
// R->R always works, but we have to avoid a check-cast to an interface.
return
!
dst
.
isInterface
()
||
dst
.
isAssignableFrom
(
src
);
}
}
private
boolean
canConvertParameters
(
Class
<?>[]
srcTypes
,
Class
<?>[]
dstTypes
)
{
for
(
int
i
=
0
;
i
<
srcTypes
.
length
;
i
++)
{
if
(!
canConvert
(
srcTypes
[
i
],
dstTypes
[
i
]))
{
...
...
@@ -895,16 +928,6 @@ class MethodType implements java.io.Serializable {
return
true
;
}
private
static
boolean
canCast
(
Class
<?>
src
,
Class
<?>
dst
)
{
if
(
src
.
isPrimitive
()
&&
!
dst
.
isPrimitive
())
{
if
(
dst
==
Object
.
class
||
dst
.
isInterface
())
return
true
;
// Here is the corner case that is not castable. Example: int -> String
Wrapper
sw
=
Wrapper
.
forPrimitiveType
(
src
);
return
dst
.
isAssignableFrom
(
sw
.
wrapperType
());
}
return
true
;
}
/*non-public*/
static
boolean
canConvert
(
Class
<?>
src
,
Class
<?>
dst
)
{
// short-circuit a few cases:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录