Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
941f953a
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看板
提交
941f953a
编写于
9月 29, 2017
作者:
D
dbuck
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8174962: Better interface invocations
Reviewed-by: jrose, coleenp, ahgross, acorn, vlivanov
上级
4ca79a53
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
10 deletion
+49
-10
src/share/classes/java/lang/invoke/DirectMethodHandle.java
src/share/classes/java/lang/invoke/DirectMethodHandle.java
+49
-10
未找到文件。
src/share/classes/java/lang/invoke/DirectMethodHandle.java
浏览文件 @
941f953a
/*
* Copyright (c) 2008, 201
3
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 201
7
, 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
...
...
@@ -75,13 +75,20 @@ class DirectMethodHandle extends MethodHandle {
mtype
=
mtype
.
insertParameterTypes
(
0
,
receiver
);
}
if
(!
member
.
isField
())
{
if
(
refKind
==
REF_invokeSpecial
)
{
member
=
member
.
asSpecial
();
LambdaForm
lform
=
preparedLambdaForm
(
member
);
return
new
Special
(
mtype
,
lform
,
member
);
}
else
{
LambdaForm
lform
=
preparedLambdaForm
(
member
);
return
new
DirectMethodHandle
(
mtype
,
lform
,
member
);
switch
(
refKind
)
{
case
REF_invokeSpecial:
{
member
=
member
.
asSpecial
();
LambdaForm
lform
=
preparedLambdaForm
(
member
);
return
new
Special
(
mtype
,
lform
,
member
);
}
case
REF_invokeInterface:
{
LambdaForm
lform
=
preparedLambdaForm
(
member
);
return
new
Interface
(
mtype
,
lform
,
member
,
receiver
);
}
default
:
{
LambdaForm
lform
=
preparedLambdaForm
(
member
);
return
new
DirectMethodHandle
(
mtype
,
lform
,
member
);
}
}
}
else
{
LambdaForm
lform
=
preparedFieldLambdaForm
(
member
);
...
...
@@ -191,6 +198,7 @@ class DirectMethodHandle extends MethodHandle {
private
static
LambdaForm
makePreparedLambdaForm
(
MethodType
mtype
,
int
which
)
{
boolean
needsInit
=
(
which
==
LF_INVSTATIC_INIT
);
boolean
doesAlloc
=
(
which
==
LF_NEWINVSPECIAL
);
boolean
needsReceiverCheck
=
(
which
==
LF_INVINTERFACE
);
String
linkerName
,
lambdaName
;
switch
(
which
)
{
case
LF_INVVIRTUAL:
linkerName
=
"linkToVirtual"
;
lambdaName
=
"DMH.invokeVirtual"
;
break
;
...
...
@@ -218,6 +226,7 @@ class DirectMethodHandle extends MethodHandle {
int
nameCursor
=
ARG_LIMIT
;
final
int
NEW_OBJ
=
(
doesAlloc
?
nameCursor
++
:
-
1
);
final
int
GET_MEMBER
=
nameCursor
++;
final
int
CHECK_RECEIVER
=
(
needsReceiverCheck
?
nameCursor
++
:
-
1
);
final
int
LINKER_CALL
=
nameCursor
++;
Name
[]
names
=
arguments
(
nameCursor
-
ARG_LIMIT
,
mtype
.
invokerType
());
assert
(
names
.
length
==
nameCursor
);
...
...
@@ -232,6 +241,10 @@ class DirectMethodHandle extends MethodHandle {
}
assert
(
findDirectMethodHandle
(
names
[
GET_MEMBER
])
==
names
[
DMH_THIS
]);
Object
[]
outArgs
=
Arrays
.
copyOfRange
(
names
,
ARG_BASE
,
GET_MEMBER
+
1
,
Object
[].
class
);
if
(
needsReceiverCheck
)
{
names
[
CHECK_RECEIVER
]
=
new
Name
(
Lazy
.
NF_checkReceiver
,
names
[
DMH_THIS
],
names
[
ARG_BASE
]);
outArgs
[
0
]
=
names
[
CHECK_RECEIVER
];
}
assert
(
outArgs
[
outArgs
.
length
-
1
]
==
names
[
GET_MEMBER
]);
// look, shifted args!
int
result
=
LAST_RESULT
;
if
(
doesAlloc
)
{
...
...
@@ -375,6 +388,29 @@ class DirectMethodHandle extends MethodHandle {
}
}
/** This subclass represents invokeinterface instructions. */
static
class
Interface
extends
DirectMethodHandle
{
private
final
Class
<?>
refc
;
private
Interface
(
MethodType
mtype
,
LambdaForm
form
,
MemberName
member
,
Class
<?>
refc
)
{
super
(
mtype
,
form
,
member
);
assert
refc
.
isInterface
()
:
refc
;
this
.
refc
=
refc
;
}
@Override
MethodHandle
copyWith
(
MethodType
mt
,
LambdaForm
lf
)
{
return
new
Interface
(
mt
,
lf
,
member
,
refc
);
}
Object
checkReceiver
(
Object
recv
)
{
if
(!
refc
.
isInstance
(
recv
))
{
String
msg
=
String
.
format
(
"Class %s does not implement the requested interface %s"
,
recv
.
getClass
().
getName
(),
refc
.
getName
());
throw
new
IncompatibleClassChangeError
(
msg
);
}
return
recv
;
}
}
/** This subclass handles constructor references. */
static
class
Constructor
extends
DirectMethodHandle
{
final
MemberName
initMethod
;
...
...
@@ -657,7 +693,8 @@ class DirectMethodHandle extends MethodHandle {
NF_staticOffset
,
NF_checkCast
,
NF_allocateInstance
,
NF_constructorMethod
;
NF_constructorMethod
,
NF_checkReceiver
;
static
{
try
{
NamedFunction
nfs
[]
=
{
...
...
@@ -680,7 +717,9 @@ class DirectMethodHandle extends MethodHandle {
NF_allocateInstance
=
new
NamedFunction
(
DirectMethodHandle
.
class
.
getDeclaredMethod
(
"allocateInstance"
,
Object
.
class
)),
NF_constructorMethod
=
new
NamedFunction
(
DirectMethodHandle
.
class
.
getDeclaredMethod
(
"constructorMethod"
,
Object
.
class
))
.
getDeclaredMethod
(
"constructorMethod"
,
Object
.
class
)),
NF_checkReceiver
=
new
NamedFunction
(
new
MemberName
(
Interface
.
class
.
getDeclaredMethod
(
"checkReceiver"
,
Object
.
class
)))
};
for
(
NamedFunction
nf
:
nfs
)
{
// Each nf must be statically invocable or we get tied up in our bootstraps.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录