Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell11
提交
92853b17
D
dragonwell11
项目概览
openanolis
/
dragonwell11
通知
7
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell11
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
92853b17
编写于
9月 16, 2015
作者:
S
sundar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8136544: Call site switching to megamorphic causes incorrect property read
Reviewed-by: attila, mhaupt
上级
d2620475
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
127 addition
and
18 deletion
+127
-18
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJavaImporter.java
...sses/jdk/nashorn/internal/objects/NativeJavaImporter.java
+1
-1
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/NativeJavaPackage.java
...asses/jdk/nashorn/internal/runtime/NativeJavaPackage.java
+1
-1
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java
...re/classes/jdk/nashorn/internal/runtime/ScriptObject.java
+19
-13
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/WithObject.java
...hare/classes/jdk/nashorn/internal/runtime/WithObject.java
+6
-3
nashorn/test/script/basic/JDK-8136544.js
nashorn/test/script/basic/JDK-8136544.js
+65
-0
nashorn/test/src/jdk/nashorn/api/scripting/test/ScopeTest.java
...rn/test/src/jdk/nashorn/api/scripting/test/ScopeTest.java
+35
-0
未找到文件。
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJavaImporter.java
浏览文件 @
92853b17
...
...
@@ -134,7 +134,7 @@ public final class NativeJavaImporter extends ScriptObject {
}
@Override
protected
Object
invokeNoSuchProperty
(
final
String
name
,
final
int
programPoint
)
{
protected
Object
invokeNoSuchProperty
(
final
String
name
,
final
boolean
isScope
,
final
int
programPoint
)
{
final
Object
retval
=
createProperty
(
name
);
if
(
isValid
(
programPoint
))
{
throw
new
UnwarrantedOptimismException
(
retval
,
programPoint
);
...
...
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/NativeJavaPackage.java
浏览文件 @
92853b17
...
...
@@ -206,7 +206,7 @@ public final class NativeJavaPackage extends ScriptObject {
}
@Override
protected
Object
invokeNoSuchProperty
(
final
String
key
,
final
int
programPoint
)
{
protected
Object
invokeNoSuchProperty
(
final
String
key
,
final
boolean
isScope
,
final
int
programPoint
)
{
final
Object
retval
=
createProperty
(
key
);
if
(
isValid
(
programPoint
))
{
throw
new
UnwarrantedOptimismException
(
retval
,
programPoint
);
...
...
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java
浏览文件 @
92853b17
...
...
@@ -149,7 +149,7 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable {
/** Method handle to retrieve prototype of this object */
public
static
final
MethodHandle
GETPROTO
=
findOwnMH_V
(
"getProto"
,
ScriptObject
.
class
);
static
final
MethodHandle
MEGAMORPHIC_GET
=
findOwnMH_V
(
"megamorphicGet"
,
Object
.
class
,
String
.
class
,
boolean
.
class
);
static
final
MethodHandle
MEGAMORPHIC_GET
=
findOwnMH_V
(
"megamorphicGet"
,
Object
.
class
,
String
.
class
,
boolean
.
class
,
boolean
.
class
);
static
final
MethodHandle
GLOBALFILTER
=
findOwnMH_S
(
"globalFilter"
,
Object
.
class
,
Object
.
class
);
static
final
MethodHandle
DECLARE_AND_SET
=
findOwnMH_V
(
"declareAndSet"
,
void
.
class
,
String
.
class
,
Object
.
class
);
...
...
@@ -2035,19 +2035,19 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable {
private
static
GuardedInvocation
findMegaMorphicGetMethod
(
final
CallSiteDescriptor
desc
,
final
String
name
,
final
boolean
isMethod
)
{
Context
.
getContextTrusted
().
getLogger
(
ObjectClassGenerator
.
class
).
warning
(
"Megamorphic getter: "
+
desc
+
" "
+
name
+
" "
+
isMethod
);
final
MethodHandle
invoker
=
MH
.
insertArguments
(
MEGAMORPHIC_GET
,
1
,
name
,
isMethod
);
final
MethodHandle
invoker
=
MH
.
insertArguments
(
MEGAMORPHIC_GET
,
1
,
name
,
isMethod
,
NashornCallSiteDescriptor
.
isScope
(
desc
)
);
final
MethodHandle
guard
=
getScriptObjectGuard
(
desc
.
getMethodType
(),
true
);
return
new
GuardedInvocation
(
invoker
,
guard
);
}
@SuppressWarnings
(
"unused"
)
private
Object
megamorphicGet
(
final
String
key
,
final
boolean
isMethod
)
{
private
Object
megamorphicGet
(
final
String
key
,
final
boolean
isMethod
,
final
boolean
isScope
)
{
final
FindProperty
find
=
findProperty
(
key
,
true
);
if
(
find
!=
null
)
{
return
find
.
getObjectValue
();
}
return
isMethod
?
getNoSuchMethod
(
key
,
INVALID_PROGRAM_POINT
)
:
invokeNoSuchProperty
(
key
,
INVALID_PROGRAM_POINT
);
return
isMethod
?
getNoSuchMethod
(
key
,
isScope
,
INVALID_PROGRAM_POINT
)
:
invokeNoSuchProperty
(
key
,
isScope
,
INVALID_PROGRAM_POINT
);
}
// Marks a property as declared and sets its value. Used as slow path for block-scoped LET and CONST
...
...
@@ -2382,10 +2382,11 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable {
/**
* Invoke fall back if a property is not found.
* @param name Name of property.
* @param isScope is this a scope access?
* @param programPoint program point
* @return Result from call.
*/
protected
Object
invokeNoSuchProperty
(
final
String
name
,
final
int
programPoint
)
{
protected
Object
invokeNoSuchProperty
(
final
String
name
,
final
boolean
isScope
,
final
int
programPoint
)
{
final
FindProperty
find
=
findProperty
(
NO_SUCH_PROPERTY_NAME
,
true
);
Object
ret
=
UNDEFINED
;
...
...
@@ -2394,7 +2395,9 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable {
final
Object
func
=
find
.
getObjectValue
();
if
(
func
instanceof
ScriptFunction
)
{
ret
=
ScriptRuntime
.
apply
((
ScriptFunction
)
func
,
this
,
name
);
final
ScriptFunction
sfunc
=
(
ScriptFunction
)
func
;
final
Object
self
=
isScope
&&
sfunc
.
isStrict
()?
UNDEFINED
:
this
;
ret
=
ScriptRuntime
.
apply
(
sfunc
,
self
,
name
);
}
}
...
...
@@ -2409,13 +2412,14 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable {
/**
* Get __noSuchMethod__ as a function bound to this object and {@code name} if it is defined.
* @param name the method name
* @param isScope is this a scope access?
* @return the bound function, or undefined
*/
private
Object
getNoSuchMethod
(
final
String
name
,
final
int
programPoint
)
{
private
Object
getNoSuchMethod
(
final
String
name
,
final
boolean
isScope
,
final
int
programPoint
)
{
final
FindProperty
find
=
findProperty
(
NO_SUCH_METHOD_NAME
,
true
);
if
(
find
==
null
)
{
return
invokeNoSuchProperty
(
name
,
programPoint
);
return
invokeNoSuchProperty
(
name
,
isScope
,
programPoint
);
}
final
Object
value
=
find
.
getObjectValue
();
...
...
@@ -2423,7 +2427,9 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable {
return
UNDEFINED
;
}
return
((
ScriptFunction
)
value
).
createBound
(
this
,
new
Object
[]
{
name
});
final
ScriptFunction
func
=
(
ScriptFunction
)
value
;
final
Object
self
=
isScope
&&
func
.
isStrict
()?
UNDEFINED
:
this
;
return
func
.
createBound
(
self
,
new
Object
[]
{
name
});
}
private
GuardedInvocation
createEmptyGetter
(
final
CallSiteDescriptor
desc
,
final
boolean
explicitInstanceOfCheck
,
final
String
name
)
{
...
...
@@ -2738,7 +2744,7 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable {
}
}
return
JSType
.
toInt32
(
invokeNoSuchProperty
(
key
,
programPoint
));
return
JSType
.
toInt32
(
invokeNoSuchProperty
(
key
,
false
,
programPoint
));
}
@Override
...
...
@@ -2820,7 +2826,7 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable {
}
}
return
JSType
.
toLong
(
invokeNoSuchProperty
(
key
,
programPoint
));
return
JSType
.
toLong
(
invokeNoSuchProperty
(
key
,
false
,
programPoint
));
}
@Override
...
...
@@ -2902,7 +2908,7 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable {
}
}
return
JSType
.
toNumber
(
invokeNoSuchProperty
(
key
,
INVALID_PROGRAM_POINT
));
return
JSType
.
toNumber
(
invokeNoSuchProperty
(
key
,
false
,
INVALID_PROGRAM_POINT
));
}
@Override
...
...
@@ -2983,7 +2989,7 @@ public abstract class ScriptObject implements PropertyAccess, Cloneable {
}
}
return
invokeNoSuchProperty
(
key
,
INVALID_PROGRAM_POINT
);
return
invokeNoSuchProperty
(
key
,
false
,
INVALID_PROGRAM_POINT
);
}
@Override
...
...
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/WithObject.java
浏览文件 @
92853b17
...
...
@@ -26,6 +26,7 @@
package
jdk.nashorn.internal.runtime
;
import
static
jdk
.
nashorn
.
internal
.
lookup
.
Lookup
.
MH
;
import
static
jdk
.
nashorn
.
internal
.
runtime
.
ScriptRuntime
.
UNDEFINED
;
import
java.lang.invoke.MethodHandle
;
import
java.lang.invoke.MethodHandles
;
...
...
@@ -209,16 +210,18 @@ public final class WithObject extends Scope {
}
@Override
protected
Object
invokeNoSuchProperty
(
final
String
name
,
final
int
programPoint
)
{
protected
Object
invokeNoSuchProperty
(
final
String
name
,
final
boolean
isScope
,
final
int
programPoint
)
{
FindProperty
find
=
expression
.
findProperty
(
NO_SUCH_PROPERTY_NAME
,
true
);
if
(
find
!=
null
)
{
final
Object
func
=
find
.
getObjectValue
();
if
(
func
instanceof
ScriptFunction
)
{
return
ScriptRuntime
.
apply
((
ScriptFunction
)
func
,
expression
,
name
);
final
ScriptFunction
sfunc
=
(
ScriptFunction
)
func
;
final
Object
self
=
isScope
&&
sfunc
.
isStrict
()?
UNDEFINED
:
expression
;
return
ScriptRuntime
.
apply
(
sfunc
,
self
,
name
);
}
}
return
getProto
().
invokeNoSuchProperty
(
name
,
programPoint
);
return
getProto
().
invokeNoSuchProperty
(
name
,
isScope
,
programPoint
);
}
@Override
...
...
nashorn/test/script/basic/JDK-8136544.js
0 → 100644
浏览文件 @
92853b17
/*
* Copyright (c) 2015, 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.
*/
/**
* JDK-8136544: Call site switching to megamorphic causes incorrect property read
*
* @test
* @fork
* @option -Dnashorn.unstable.relink.threshold=8
* @run
*/
var
ScriptContext
=
Java
.
type
(
"
javax.script.ScriptContext
"
);
var
ScriptEngineManager
=
Java
.
type
(
"
javax.script.ScriptEngineManager
"
);
var
m
=
new
ScriptEngineManager
();
var
e
=
m
.
getEngineByName
(
"
nashorn
"
);
var
scope
=
e
.
getBindings
(
ScriptContext
.
ENGINE_SCOPE
);
var
MYVAR
=
"
myvar
"
;
function
loopupVar
()
{
try
{
e
.
eval
(
MYVAR
);
return
true
;
}
catch
(
e
)
{
return
false
;
}
}
// make sure we exercise callsite beyond megamorphic threshold we set
// in this test via nashorn.unstable.relink.threshold property
// In each iteration, callsite is exercised twice (two evals)
// So, LIMIT should be more than 4 to exercise megamorphic callsites.
var
LIMIT
=
5
;
// This LIMIT should be more than 4
for
(
var
i
=
0
;
i
<
LIMIT
;
i
++
)
{
// remove the variable and lookup
delete
scope
[
MYVAR
];
Assert
.
assertFalse
(
loopupVar
(),
"
Expected true in iteration
"
+
i
);
// set that variable and check again
scope
[
MYVAR
]
=
"
foo
"
;
Assert
.
assertTrue
(
loopupVar
(),
"
Expected false in iteration
"
+
i
);
}
nashorn/test/src/jdk/nashorn/api/scripting/test/ScopeTest.java
浏览文件 @
92853b17
...
...
@@ -26,6 +26,7 @@ package jdk.nashorn.api.scripting.test;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
import
static
org
.
testng
.
Assert
.
assertFalse
;
import
static
org
.
testng
.
Assert
.
assertTrue
;
import
static
org
.
testng
.
Assert
.
fail
;
import
javax.script.Bindings
;
...
...
@@ -820,4 +821,38 @@ public class ScopeTest {
public
void
recursiveEvalCallScriptContextTest
()
throws
ScriptException
{
new
RecursiveEval
().
program
();
}
private
static
final
String
VAR_NAME
=
"myvar"
;
private
static
boolean
lookupVar
(
final
ScriptEngine
engine
,
final
String
varName
)
{
try
{
engine
.
eval
(
varName
);
return
true
;
}
catch
(
final
ScriptException
se
)
{
return
false
;
}
}
// @bug 8136544: Call site switching to megamorphic causes incorrect property read
@Test
public
void
megamorphicPropertyReadTest
()
throws
ScriptException
{
final
NashornScriptEngineFactory
factory
=
new
NashornScriptEngineFactory
();
final
ScriptEngine
engine
=
factory
.
getScriptEngine
();
final
Bindings
scope
=
engine
.
getBindings
(
ScriptContext
.
ENGINE_SCOPE
);
boolean
ret
;
// Why 16 is the upper limit of this loop? The default nashorn dynalink megamorphic threshold is 16.
// See jdk.nashorn.internal.runtime.linker.Bootstrap.NASHORN_DEFAULT_UNSTABLE_RELINK_THRESHOLD
// We do, 'eval' of the same in this loop twice. So, 16*2 = 32 times that callsite in the script
// is exercised - much beyond the default megamorphic threshold.
for
(
int
i
=
0
;
i
<
16
;
i
++)
{
scope
.
remove
(
VAR_NAME
);
ret
=
lookupVar
(
engine
,
VAR_NAME
);
assertFalse
(
ret
,
"Expected false in iteration "
+
i
);
scope
.
put
(
VAR_NAME
,
"foo"
);
ret
=
lookupVar
(
engine
,
VAR_NAME
);
assertTrue
(
ret
,
"Expected true in iteration "
+
i
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录