Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
58647136
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看板
提交
58647136
编写于
5月 22, 2013
作者:
C
chegar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8014737: java/lang/invoke/7196190/MHProxyTest.java fails after 8009424
Reviewed-by: twisti
上级
2e4a8cb2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
0 addition
and
181 deletion
+0
-181
test/java/lang/invoke/7196190/MHProxyTest.java
test/java/lang/invoke/7196190/MHProxyTest.java
+0
-181
未找到文件。
test/java/lang/invoke/7196190/MHProxyTest.java
已删除
100644 → 0
浏览文件 @
2e4a8cb2
/*
* Copyright (c) 2012, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
/**
* @test
* @bug 7196190
* @summary Improve method of handling MethodHandles
*
* @run main/othervm MHProxyTest
*/
import
java.lang.invoke.*
;
import
java.security.*
;
import
static
java
.
lang
.
invoke
.
MethodHandles
.*;
import
static
java
.
lang
.
invoke
.
MethodType
.*;
public
class
MHProxyTest
{
private
static
final
Class
<?>
C_Unsafe
;
private
static
final
MethodHandle
MH_getUnsafe
;
static
{
// Do these before there is a SM installed.
C_Unsafe
=
sun
.
misc
.
Unsafe
.
class
;
// EXPECT A WARNING ON THIS LINE
Lookup
lookup
=
lookup
();
MethodHandle
gumh
=
null
;
try
{
gumh
=
lookup
.
findStatic
(
C_Unsafe
,
"getUnsafe"
,
methodType
(
C_Unsafe
));
}
catch
(
ReflectiveOperationException
ex
)
{
throw
new
InternalError
(
ex
.
toString
());
}
MH_getUnsafe
=
gumh
;
// Try some different lookups:
try
{
lookup
.
in
(
Object
.
class
).
findStatic
(
C_Unsafe
,
"getUnsafe"
,
methodType
(
C_Unsafe
));
}
catch
(
ReflectiveOperationException
ex
)
{
throw
new
InternalError
(
ex
.
toString
());
}
lookup
=
lookup
().
in
(
C_Unsafe
);
try
{
lookup
.
in
(
C_Unsafe
).
findStatic
(
C_Unsafe
,
"getUnsafe"
,
methodType
(
C_Unsafe
));
}
catch
(
ReflectiveOperationException
ex
)
{
throw
new
InternalError
(
ex
.
toString
());
}
}
public
static
void
main
(
String
[]
args
)
throws
Throwable
{
System
.
setSecurityManager
(
new
SecurityManager
());
Lookup
lookup
=
lookup
();
testBasic
(
lookup
);
testDoPriv
(
lookup
);
testSetVar
();
Lookup
l2
=
lookup
.
in
(
Object
.
class
);
System
.
out
.
println
(
"=== "
+
l2
);
testBasic
(
l2
);
testDoPriv
(
l2
);
Lookup
l3
=
lookup
.
in
(
C_Unsafe
);
System
.
out
.
println
(
"=== "
+
l3
);
testBasic
(
l3
);
testDoPriv
(
l3
);
if
(
failure
!=
null
)
throw
failure
;
}
private
static
Throwable
failure
;
private
static
void
fail
(
Throwable
ex
)
{
if
(
failure
==
null
)
failure
=
ex
;
StackTraceElement
frame
=
new
Exception
().
getStackTrace
()[
1
];
System
.
out
.
printf
(
"Failed at %s:%d: %s\n"
,
frame
.
getFileName
(),
frame
.
getLineNumber
(),
ex
);
}
private
static
void
ok
(
Throwable
ex
)
{
StackTraceElement
frame
=
new
Exception
().
getStackTrace
()[
1
];
System
.
out
.
printf
(
"OK at %s:%d: %s\n"
,
frame
.
getFileName
(),
frame
.
getLineNumber
(),
ex
);
}
private
static
void
testBasic
(
Lookup
lookup
)
throws
Throwable
{
// Verify that we can't get to this guy under the SM:
try
{
MethodHandle
badmh
=
lookup
.
findStatic
(
C_Unsafe
,
"getUnsafe"
,
methodType
(
C_Unsafe
));
assert
(
badmh
.
type
()
==
methodType
(
C_Unsafe
));
badmh
=
badmh
.
asType
(
badmh
.
type
().
generic
());
Object
u
=
C_Unsafe
.
cast
(
badmh
.
invokeExact
());
assert
(
C_Unsafe
.
isInstance
(
u
));
fail
(
new
AssertionError
(
"got mh to getUnsafe!"
));
}
catch
(
SecurityException
ex
)
{
ok
(
ex
);
}
try
{
Object
u
=
MH_getUnsafe
.
invokeWithArguments
();
assert
(
C_Unsafe
.
isInstance
(
u
));
fail
(
new
AssertionError
(
"got the Unsafe object! (MH invoke)"
));
}
catch
(
SecurityException
ex
)
{
ok
(
ex
);
}
try
{
MethodHandle
mh
=
MH_getUnsafe
;
mh
=
mh
.
asType
(
mh
.
type
().
generic
());
mh
=
foldArguments
(
identity
(
Object
.
class
),
mh
);
mh
=
filterReturnValue
(
mh
,
identity
(
Object
.
class
));
Object
u
=
mh
.
invokeExact
();
assert
(
C_Unsafe
.
isInstance
(
u
));
fail
(
new
AssertionError
(
"got the Unsafe object! (MH invokeWithArguments)"
));
}
catch
(
SecurityException
ex
)
{
ok
(
ex
);
}
}
private
static
void
testDoPriv
(
Lookup
lookup
)
throws
Throwable
{
PrivilegedAction
privAct
=
MethodHandleProxies
.
asInterfaceInstance
(
PrivilegedAction
.
class
,
MH_getUnsafe
);
try
{
Object
u
=
AccessController
.
doPrivileged
(
privAct
);
assert
(
C_Unsafe
.
isInstance
(
u
));
fail
(
new
AssertionError
(
"got the Unsafe object! (static doPriv)"
));
}
catch
(
SecurityException
ex
)
{
ok
(
ex
);
}
MethodHandle
MH_doPriv
=
lookup
.
findStatic
(
AccessController
.
class
,
"doPrivileged"
,
methodType
(
Object
.
class
,
PrivilegedAction
.
class
));
MH_doPriv
=
MH_doPriv
.
bindTo
(
privAct
);
try
{
Object
u
=
MH_doPriv
.
invoke
();
assert
(
C_Unsafe
.
isInstance
(
u
));
fail
(
new
AssertionError
(
"got the Unsafe object! (MH + doPriv)"
));
}
catch
(
SecurityException
ex
)
{
ok
(
ex
);
}
// try one more layer of indirection:
Runnable
rbl
=
MethodHandleProxies
.
asInterfaceInstance
(
Runnable
.
class
,
MH_doPriv
);
try
{
rbl
.
run
();
fail
(
new
AssertionError
(
"got the Unsafe object! (Runnable + MH + doPriv)"
));
}
catch
(
SecurityException
ex
)
{
ok
(
ex
);
}
}
private
static
void
testSetVar
()
throws
Throwable
{
{
// Test the box pattern:
Object
[]
box
=
new
Object
[
1
];
MethodHandle
MH_getFoo
=
identity
(
Object
.
class
).
bindTo
(
"foo"
);
MethodHandle
MH_storeToBox
=
insertArguments
(
arrayElementSetter
(
Object
[].
class
),
0
,
box
,
0
);
MethodHandle
mh
=
filterReturnValue
(
MH_getFoo
,
MH_storeToBox
);
mh
.
invokeExact
();
assert
(
box
[
0
]
==
"foo"
);
}
{
Object
[]
box
=
new
Object
[
1
];
MethodHandle
MH_storeToBox
=
insertArguments
(
arrayElementSetter
(
Object
[].
class
),
0
,
box
,
0
);
MethodHandle
mh
=
filterReturnValue
(
MH_getUnsafe
.
asType
(
MH_getUnsafe
.
type
().
generic
()),
MH_storeToBox
);
try
{
mh
.
invokeExact
();
Object
u
=
box
[
0
];
assert
(
C_Unsafe
.
isInstance
(
u
));
fail
(
new
AssertionError
(
"got the Unsafe object! (MH + setElement)"
));
}
catch
(
SecurityException
ex
)
{
ok
(
ex
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录