Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
2d125391
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看板
提交
2d125391
编写于
9月 10, 2014
作者:
V
vlivanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8050884: Intrinsify ValueConversions.identity() functions
Reviewed-by: vlivanov, psandoz Contributed-by: john.r.rose@oracle.com
上级
b1cb58f0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
66 addition
and
118 deletion
+66
-118
src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
...re/classes/java/lang/invoke/InvokerBytecodeGenerator.java
+4
-0
src/share/classes/java/lang/invoke/MethodHandleImpl.java
src/share/classes/java/lang/invoke/MethodHandleImpl.java
+11
-8
src/share/classes/java/lang/invoke/MethodHandles.java
src/share/classes/java/lang/invoke/MethodHandles.java
+24
-8
src/share/classes/java/lang/invoke/MethodType.java
src/share/classes/java/lang/invoke/MethodType.java
+26
-0
src/share/classes/sun/invoke/util/ValueConversions.java
src/share/classes/sun/invoke/util/ValueConversions.java
+1
-94
test/sun/invoke/util/ValueConversionsTest.java
test/sun/invoke/util/ValueConversionsTest.java
+0
-8
未找到文件。
src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
浏览文件 @
2d125391
...
@@ -664,6 +664,10 @@ class InvokerBytecodeGenerator {
...
@@ -664,6 +664,10 @@ class InvokerBytecodeGenerator {
case
ARRAY_STORE:
case
ARRAY_STORE:
emitArrayStore
(
name
);
emitArrayStore
(
name
);
continue
;
continue
;
case
IDENTITY:
assert
(
name
.
arguments
.
length
==
1
);
emitPushArguments
(
name
);
continue
;
case
NONE:
case
NONE:
// no intrinsic associated
// no intrinsic associated
break
;
break
;
...
...
src/share/classes/java/lang/invoke/MethodHandleImpl.java
浏览文件 @
2d125391
...
@@ -303,14 +303,6 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
...
@@ -303,14 +303,6 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
return
new
ClassCastException
(
"Cannot cast "
+
obj
.
getClass
().
getName
()
+
" to "
+
t
.
getName
());
return
new
ClassCastException
(
"Cannot cast "
+
obj
.
getClass
().
getName
()
+
" to "
+
t
.
getName
());
}
}
static
MethodHandle
makeReferenceIdentity
(
Class
<?>
refType
)
{
MethodType
lambdaType
=
MethodType
.
genericMethodType
(
1
).
invokerType
();
Name
[]
names
=
arguments
(
1
,
lambdaType
);
names
[
names
.
length
-
1
]
=
new
Name
(
ValueConversions
.
identity
(),
names
[
1
]);
LambdaForm
form
=
new
LambdaForm
(
"identity"
,
lambdaType
.
parameterCount
(),
names
);
return
SimpleMethodHandle
.
make
(
MethodType
.
methodType
(
refType
,
refType
),
form
);
}
static
Object
[]
computeValueConversions
(
MethodType
srcType
,
MethodType
dstType
,
static
Object
[]
computeValueConversions
(
MethodType
srcType
,
MethodType
dstType
,
boolean
strict
,
boolean
monobox
)
{
boolean
strict
,
boolean
monobox
)
{
final
int
INARG_COUNT
=
srcType
.
parameterCount
();
final
int
INARG_COUNT
=
srcType
.
parameterCount
();
...
@@ -1061,6 +1053,7 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
...
@@ -1061,6 +1053,7 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
NEW_ARRAY
,
NEW_ARRAY
,
ARRAY_LOAD
,
ARRAY_LOAD
,
ARRAY_STORE
,
ARRAY_STORE
,
IDENTITY
,
NONE
// no intrinsic associated
NONE
// no intrinsic associated
}
}
...
@@ -1098,6 +1091,16 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
...
@@ -1098,6 +1091,16 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
return
super
.
internalProperties
()
+
return
super
.
internalProperties
()
+
"\n& Intrinsic="
+
intrinsicName
;
"\n& Intrinsic="
+
intrinsicName
;
}
}
@Override
public
MethodHandle
asCollector
(
Class
<?>
arrayType
,
int
arrayLength
)
{
if
(
intrinsicName
==
Intrinsic
.
IDENTITY
)
{
MethodType
resultType
=
type
().
asCollectorType
(
arrayType
,
arrayLength
);
MethodHandle
newArray
=
MethodHandleImpl
.
varargsArray
(
arrayType
,
arrayLength
);
return
newArray
.
asType
(
resultType
);
}
return
super
.
asCollector
(
arrayType
,
arrayLength
);
}
}
}
static
MethodHandle
makeIntrinsic
(
MethodHandle
target
,
Intrinsic
intrinsicName
)
{
static
MethodHandle
makeIntrinsic
(
MethodHandle
target
,
Intrinsic
intrinsicName
)
{
...
...
src/share/classes/java/lang/invoke/MethodHandles.java
浏览文件 @
2d125391
...
@@ -41,6 +41,7 @@ import sun.security.util.SecurityConstants;
...
@@ -41,6 +41,7 @@ import sun.security.util.SecurityConstants;
import
java.lang.invoke.LambdaForm.BasicType
;
import
java.lang.invoke.LambdaForm.BasicType
;
import
static
java
.
lang
.
invoke
.
LambdaForm
.
BasicType
.*;
import
static
java
.
lang
.
invoke
.
LambdaForm
.
BasicType
.*;
import
static
java
.
lang
.
invoke
.
MethodHandleStatics
.*;
import
static
java
.
lang
.
invoke
.
MethodHandleStatics
.*;
import
static
java
.
lang
.
invoke
.
MethodHandleImpl
.
Intrinsic
;
import
static
java
.
lang
.
invoke
.
MethodHandleNatives
.
Constants
.*;
import
static
java
.
lang
.
invoke
.
MethodHandleNatives
.
Constants
.*;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
...
@@ -2199,14 +2200,29 @@ assert((int)twice.invokeExact(21) == 42);
...
@@ -2199,14 +2200,29 @@ assert((int)twice.invokeExact(21) == 42);
*/
*/
public
static
public
static
MethodHandle
identity
(
Class
<?>
type
)
{
MethodHandle
identity
(
Class
<?>
type
)
{
if
(
type
==
void
.
class
)
Wrapper
btw
=
(
type
.
isPrimitive
()
?
Wrapper
.
forPrimitiveType
(
type
)
:
Wrapper
.
OBJECT
);
throw
newIllegalArgumentException
(
"void type"
);
int
pos
=
btw
.
ordinal
();
else
if
(
type
==
Object
.
class
)
MethodHandle
ident
=
IDENTITY_MHS
[
pos
];
return
ValueConversions
.
identity
();
if
(
ident
==
null
)
{
else
if
(
type
.
isPrimitive
())
ident
=
setCachedMethodHandle
(
IDENTITY_MHS
,
pos
,
makeIdentity
(
btw
.
primitiveType
()));
return
ValueConversions
.
identity
(
Wrapper
.
forPrimitiveType
(
type
));
}
else
if
(
ident
.
type
().
returnType
()
==
type
)
return
MethodHandleImpl
.
makeReferenceIdentity
(
type
);
return
ident
;
// something like identity(Foo.class); do not bother to intern these
assert
(
btw
==
Wrapper
.
OBJECT
);
return
makeIdentity
(
type
);
}
private
static
final
MethodHandle
[]
IDENTITY_MHS
=
new
MethodHandle
[
Wrapper
.
values
().
length
];
private
static
MethodHandle
makeIdentity
(
Class
<?>
ptype
)
{
MethodType
mtype
=
MethodType
.
methodType
(
ptype
,
ptype
);
LambdaForm
lform
=
LambdaForm
.
identityForm
(
BasicType
.
basicType
(
ptype
));
return
MethodHandleImpl
.
makeIntrinsic
(
mtype
,
lform
,
Intrinsic
.
IDENTITY
);
}
synchronized
private
static
MethodHandle
setCachedMethodHandle
(
MethodHandle
[]
cache
,
int
pos
,
MethodHandle
value
)
{
// Simulate a CAS, to avoid racy duplication of results.
MethodHandle
prev
=
cache
[
pos
];
if
(
prev
!=
null
)
return
prev
;
return
cache
[
pos
]
=
value
;
}
}
/**
/**
...
...
src/share/classes/java/lang/invoke/MethodType.java
浏览文件 @
2d125391
...
@@ -509,6 +509,32 @@ class MethodType implements java.io.Serializable {
...
@@ -509,6 +509,32 @@ class MethodType implements java.io.Serializable {
return
ptype
;
return
ptype
;
}
}
/** Delete the last parameter type and replace it with arrayLength copies of the component type of arrayType.
* @param arrayType any array type
* @param arrayLength the number of parameter types to insert
* @return the resulting type
*/
/*non-public*/
MethodType
asCollectorType
(
Class
<?>
arrayType
,
int
arrayLength
)
{
assert
(
parameterCount
()
>=
1
);
assert
(
lastParameterType
().
isAssignableFrom
(
arrayType
));
MethodType
res
;
if
(
arrayType
==
Object
[].
class
)
{
res
=
genericMethodType
(
arrayLength
);
if
(
rtype
!=
Object
.
class
)
{
res
=
res
.
changeReturnType
(
rtype
);
}
}
else
{
Class
<?>
elemType
=
arrayType
.
getComponentType
();
assert
(
elemType
!=
null
);
res
=
methodType
(
rtype
,
Collections
.
nCopies
(
arrayLength
,
elemType
));
}
if
(
ptypes
.
length
==
1
)
{
return
res
;
}
else
{
return
res
.
insertParameterTypes
(
0
,
parameterList
().
subList
(
0
,
ptypes
.
length
-
1
));
}
}
/**
/**
* Finds or creates a method type with some parameter types omitted.
* Finds or creates a method type with some parameter types omitted.
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
...
...
src/share/classes/sun/invoke/util/ValueConversions.java
浏览文件 @
2d125391
...
@@ -395,69 +395,11 @@ public class ValueConversions {
...
@@ -395,69 +395,11 @@ public class ValueConversions {
throw
new
IllegalArgumentException
(
"cannot find zero constant for "
+
wrap
);
throw
new
IllegalArgumentException
(
"cannot find zero constant for "
+
wrap
);
}
}
/// Converting references to references.
private
static
final
MethodHandle
CAST_REFERENCE
,
IGNORE
,
EMPTY
;
/**
* Identity function.
* @param x an arbitrary reference value
* @return the same value x
*/
static
<
T
>
T
identity
(
T
x
)
{
return
x
;
}
static
<
T
>
T
[]
identity
(
T
[]
x
)
{
return
x
;
}
/**
* Identity function on ints.
* @param x an arbitrary int value
* @return the same value x
*/
static
int
identity
(
int
x
)
{
return
x
;
}
static
byte
identity
(
byte
x
)
{
return
x
;
}
static
short
identity
(
short
x
)
{
return
x
;
}
static
boolean
identity
(
boolean
x
)
{
return
x
;
}
static
char
identity
(
char
x
)
{
return
x
;
}
/**
* Identity function on longs.
* @param x an arbitrary long value
* @return the same value x
*/
static
long
identity
(
long
x
)
{
return
x
;
}
static
float
identity
(
float
x
)
{
return
x
;
}
static
double
identity
(
double
x
)
{
return
x
;
}
private
static
final
MethodHandle
IDENTITY
,
CAST_REFERENCE
,
IGNORE
,
EMPTY
;
static
{
static
{
try
{
try
{
MethodType
idType
=
MethodType
.
genericMethodType
(
1
);
MethodType
idType
=
MethodType
.
genericMethodType
(
1
);
MethodType
ignoreType
=
idType
.
changeReturnType
(
void
.
class
);
MethodType
ignoreType
=
idType
.
changeReturnType
(
void
.
class
);
IDENTITY
=
IMPL_LOOKUP
.
findStatic
(
THIS_CLASS
,
"identity"
,
idType
);
CAST_REFERENCE
=
IMPL_LOOKUP
.
findVirtual
(
Class
.
class
,
"cast"
,
idType
);
CAST_REFERENCE
=
IMPL_LOOKUP
.
findVirtual
(
Class
.
class
,
"cast"
,
idType
);
IGNORE
=
IMPL_LOOKUP
.
findStatic
(
THIS_CLASS
,
"ignore"
,
ignoreType
);
IGNORE
=
IMPL_LOOKUP
.
findStatic
(
THIS_CLASS
,
"ignore"
,
ignoreType
);
EMPTY
=
IMPL_LOOKUP
.
findStatic
(
THIS_CLASS
,
"empty"
,
ignoreType
.
dropParameterTypes
(
0
,
1
));
EMPTY
=
IMPL_LOOKUP
.
findStatic
(
THIS_CLASS
,
"empty"
,
ignoreType
.
dropParameterTypes
(
0
,
1
));
...
@@ -470,41 +412,6 @@ public class ValueConversions {
...
@@ -470,41 +412,6 @@ public class ValueConversions {
return
IGNORE
;
return
IGNORE
;
}
}
public
static
MethodHandle
identity
()
{
return
IDENTITY
;
}
public
static
MethodHandle
identity
(
Class
<?>
type
)
{
if
(!
type
.
isPrimitive
())
// Reference identity has been moved into MethodHandles:
return
MethodHandles
.
identity
(
type
);
return
identity
(
Wrapper
.
findPrimitiveType
(
type
));
}
public
static
MethodHandle
identity
(
Wrapper
wrap
)
{
WrapperCache
cache
=
CONSTANT_FUNCTIONS
[
1
];
MethodHandle
mh
=
cache
.
get
(
wrap
);
if
(
mh
!=
null
)
{
return
mh
;
}
// slow path
MethodType
type
=
MethodType
.
methodType
(
wrap
.
primitiveType
());
if
(
wrap
!=
Wrapper
.
VOID
)
type
=
type
.
appendParameterTypes
(
wrap
.
primitiveType
());
try
{
mh
=
IMPL_LOOKUP
.
findStatic
(
THIS_CLASS
,
"identity"
,
type
);
}
catch
(
ReflectiveOperationException
ex
)
{
mh
=
null
;
}
if
(
mh
==
null
&&
wrap
==
Wrapper
.
VOID
)
{
mh
=
EMPTY
;
// #(){} : #()void
}
if
(
mh
!=
null
)
{
return
cache
.
put
(
wrap
,
mh
);
}
throw
new
IllegalArgumentException
(
"cannot find identity for "
+
wrap
);
}
/** Return a method that casts its second argument (an Object) to the given type (a Class). */
/** Return a method that casts its second argument (an Object) to the given type (a Class). */
public
static
MethodHandle
cast
()
{
public
static
MethodHandle
cast
()
{
return
CAST_REFERENCE
;
return
CAST_REFERENCE
;
...
...
test/sun/invoke/util/ValueConversionsTest.java
浏览文件 @
2d125391
...
@@ -157,14 +157,6 @@ public class ValueConversionsTest {
...
@@ -157,14 +157,6 @@ public class ValueConversionsTest {
}
}
}
}
@Test
public
void
testIdentity
()
throws
Throwable
{
MethodHandle
id
=
ValueConversions
.
identity
();
Object
expResult
=
"foo"
;
Object
result
=
id
.
invokeExact
(
expResult
);
assertEquals
(
expResult
,
result
);
}
@Test
@Test
public
void
testConvert
()
throws
Throwable
{
public
void
testConvert
()
throws
Throwable
{
for
(
long
tval
=
0
,
ctr
=
0
;;)
{
for
(
long
tval
=
0
,
ctr
=
0
;;)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录