mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-21 21:33:07 +00:00
Merge
This commit is contained in:
commit
57d4d0207b
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, 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.
|
||||
@ -61,7 +61,7 @@ PREFIX);
|
||||
|
||||
for each (opt in Options.validOptions) {
|
||||
|
||||
var isTimezone = (opt.type == "timezone");
|
||||
var isTimezone = (opt.type == "timezone");
|
||||
var defValue = opt.defaultValue;
|
||||
if (defValue == null) {
|
||||
defValue = "<none>";
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -32,7 +32,7 @@
|
||||
// load compatibility script
|
||||
load("nashorn:mozilla_compat.js");
|
||||
|
||||
// Import Java packages and classes
|
||||
// Import Java packages and classes
|
||||
// like import package.*; in Java
|
||||
importPackage(java.awt);
|
||||
// like import java.awt.Frame in Java
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -31,6 +31,6 @@
|
||||
|
||||
var out = java.lang.System.out;
|
||||
|
||||
// select a particular print function
|
||||
// select a particular print function
|
||||
out["println(java.lang.Object)"]("hello");
|
||||
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -519,6 +519,8 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
|
||||
<java classname="${parallel.test.runner}" dir="${basedir}" fork="true">
|
||||
<jvmarg line="${ext.class.path}"/>
|
||||
<jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
|
||||
<!-- avoid too many typeinfo cache files. Each script is run only once anyway -->
|
||||
<jvmarg line="-Dnashorn.typeInfo.disabled=true"/>
|
||||
<classpath>
|
||||
<pathelement path="${run.test.classpath}"/>
|
||||
</classpath>
|
||||
@ -582,6 +584,8 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
|
||||
<!-- clone test262 git repo -->
|
||||
<exec executable="${git.executable}">
|
||||
<arg value="clone"/>
|
||||
<arg value="--branch"/>
|
||||
<arg value="es5-tests"/>
|
||||
<arg value="https://github.com/tc39/test262"/>
|
||||
<arg value="${test.external.dir}/test262"/>
|
||||
</exec>
|
||||
|
||||
@ -202,7 +202,7 @@ test262-test-sys-prop.test.js.enable.strict.mode=true
|
||||
# list of test262 test dirs to be excluded
|
||||
test262-test-sys-prop.test.js.exclude.dir=\
|
||||
${test262.suite.dir}/intl402/ \
|
||||
${test262.suite.dir}/bestPractice/
|
||||
${test262.suite.dir}/bestPractice/
|
||||
|
||||
test262-test-sys-prop.test.failed.list.file=${build.dir}/test/failedTests
|
||||
|
||||
@ -217,7 +217,7 @@ test262-test-sys-prop.test.js.framework=\
|
||||
${test262.dir}/test/harness/sta.js
|
||||
|
||||
# testmarkdown test root
|
||||
testmarkdown-test-sys-prop.test.js.roots=${testmarkdown.dir}
|
||||
testmarkdown-test-sys-prop.test.js.roots=${testmarkdown.dir}
|
||||
|
||||
# execute testmarkdown tests in shared nashorn context or not?
|
||||
testmarkdown-test-sys-prop.test.js.shared.context=false
|
||||
@ -227,7 +227,7 @@ testmarkdown-test-sys-prop.test.js.framework=\
|
||||
${test.script.dir}${file.separator}markdown.js
|
||||
|
||||
# testjfx test root
|
||||
testjfx-test-sys-prop.test.js.roots=${testjfx.dir}
|
||||
testjfx-test-sys-prop.test.js.roots=${testjfx.dir}
|
||||
|
||||
# execute testjfx tests in shared nashorn context or not?
|
||||
testjfx-test-sys-prop.test.js.shared.context=false
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -31,9 +31,9 @@
|
||||
|
||||
// Usage: jjs array_mapreduce.js
|
||||
|
||||
// Many Array.prototype functions such as map,
|
||||
// Many Array.prototype functions such as map,
|
||||
// filter, reduce, reduceRight, every, some are generic.
|
||||
// These functions accept ECMAScript array as well as
|
||||
// These functions accept ECMAScript array as well as
|
||||
// many array-like objects including java arrays.
|
||||
// So, you can do map/filter/reduce with Java streams or
|
||||
// you can also use Array.prototype functions as below.
|
||||
@ -73,6 +73,6 @@ forEach.call(jarr, function(x) print(x));
|
||||
// print sum of squares of the random numbers
|
||||
print("Square sum:",
|
||||
reduce.call(
|
||||
map.call(jarr, function(x) x*x),
|
||||
map.call(jarr, function(x) x*x),
|
||||
function(x, y) x + y)
|
||||
);
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -82,7 +82,7 @@ var sourceName = arguments.length == 0? __FILE__ : arguments[0];
|
||||
// load parser.js from nashorn resources
|
||||
load("nashorn:parser.js");
|
||||
|
||||
// read the full content of the file and parse it
|
||||
// read the full content of the file and parse it
|
||||
// to get AST of the script specified
|
||||
var ast = parse(readFully(sourceName));
|
||||
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
// Simple .class disassembler that uses bundled ObjectWeb ASM
|
||||
// classes in jdk8. WARNING: Bundled ObjectWeb ASM classes are
|
||||
// not part of official jdk8 API. It can be changed/removed
|
||||
// not part of official jdk8 API. It can be changed/removed
|
||||
// without notice. So, this script is brittle by design!
|
||||
|
||||
// This example demonstrates passing arguments to script
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -29,7 +29,7 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// simple example showing how to call a global script
|
||||
// simple example showing how to call a global script
|
||||
// function from caller
|
||||
|
||||
var ScriptEngineManager = Java.type("javax.script.ScriptEngineManager");
|
||||
@ -42,7 +42,7 @@ var engine = manager.getEngineByName("js");
|
||||
engine.eval("function func(name) { print('I am func, hello ' + name) }");
|
||||
|
||||
// invoke functions, methods of code evaluated by engine
|
||||
// from javax.script.Invocable interface. But, hey,
|
||||
// from javax.script.Invocable interface. But, hey,
|
||||
// calling code is JavaScript and don't worry about types :)
|
||||
|
||||
engine.invokeFunction("func", "Nashorn");
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -55,7 +55,7 @@ engine.eval(<<CODE
|
||||
CODE);
|
||||
|
||||
// invoke methods of an object in script world
|
||||
// from javax.script.Invocable interface. But, hey,
|
||||
// from javax.script.Invocable interface. But, hey,
|
||||
// calling code is JavaScript and don't worry about types :)
|
||||
|
||||
// get that script object on which to call a method
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -54,7 +54,7 @@ CODE);
|
||||
// the class jdk.nashorn.api.scripting.ScriptObjectMirror
|
||||
// But nashorn's dynalink linker can treat these objects
|
||||
// specially to support natural script syntax to access..
|
||||
// In Java code, you need to use ScriptObjectMirror's
|
||||
// In Java code, you need to use ScriptObjectMirror's
|
||||
// methods though. Once again, script world is simpler :-)
|
||||
|
||||
var foreignObj = engine.get("obj");
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -50,7 +50,7 @@ CODE);
|
||||
|
||||
// create Java interface object whose methods are
|
||||
// implemented by script functions. This is from
|
||||
// javax.script.Invocable. But we are in JS world,
|
||||
// javax.script.Invocable. But we are in JS world,
|
||||
// don't worry about types :)
|
||||
|
||||
var Runnable = Java.type("java.lang.Runnable");
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -31,8 +31,8 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// In nashorn -scripting mode,
|
||||
// "$ENV" object exposes process
|
||||
// In nashorn -scripting mode,
|
||||
// "$ENV" object exposes process
|
||||
// environment variables
|
||||
|
||||
print($ENV.PATH);
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -42,7 +42,7 @@ var JArray = Java.type("int[]");
|
||||
var arr = new JArray(10);
|
||||
|
||||
// store squares as values
|
||||
for (i in arr)
|
||||
for (i in arr)
|
||||
arr[i] = i*i;
|
||||
|
||||
// for .. each on java arrays
|
||||
@ -57,7 +57,7 @@ var System = Java.type("java.lang.System");
|
||||
print("System properties");
|
||||
for each (p in System.properties.entrySet()) {
|
||||
print(p.key, "=", p.value);
|
||||
}
|
||||
}
|
||||
|
||||
// print process environment vars as name = value pairs
|
||||
print("Process environment");
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -37,7 +37,7 @@ var DoubleStream = Java.type("java.util.stream.DoubleStream");
|
||||
var r = new Random();
|
||||
|
||||
// expression closure (see expression_closure.js as well)
|
||||
// passed as lambda double generator. "print" passed as
|
||||
// passed as lambda double generator. "print" passed as
|
||||
// double consumer lambda to 'forEach' method.
|
||||
|
||||
DoubleStream
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -34,7 +34,7 @@
|
||||
var Random = Java.type("java.util.Random");
|
||||
var DoubleStream = Java.type("java.util.stream.DoubleStream");
|
||||
|
||||
// function as lambda double generator. "print" passed as
|
||||
// function as lambda double generator. "print" passed as
|
||||
// double consumer lambda to 'forEach' method.
|
||||
// Function.prototype.bind used to attach 'state' for the
|
||||
// generator function.
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -69,7 +69,7 @@ function readRssFeed(url) {
|
||||
// capture title, description now
|
||||
inItem = true;
|
||||
}
|
||||
|
||||
|
||||
if (inItem) {
|
||||
switch (local) {
|
||||
case 'title':
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -38,14 +38,14 @@
|
||||
|
||||
var sender = "Buffy the Vampire Slayer";
|
||||
var recipient = "Spike";
|
||||
|
||||
|
||||
print(<<END
|
||||
|
||||
|
||||
Dear ${recipient},
|
||||
|
||||
|
||||
I wish you to leave Sunnydale and never return.
|
||||
|
||||
|
||||
Not Quite Love,
|
||||
${sender}
|
||||
|
||||
|
||||
END);
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -56,8 +56,8 @@ function javaASTToScriptObject(args) {
|
||||
// may not be exhaustive - any getAbc would become "abc" property or
|
||||
// public field becomes a property of same name.
|
||||
var ignoredProps = new HashSet();
|
||||
for each (var word in
|
||||
['extending', 'implementing', 'init', 'mods', 'clazz', 'defs',
|
||||
for each (var word in
|
||||
['extending', 'implementing', 'init', 'mods', 'clazz', 'defs',
|
||||
'expr', 'tag', 'preferredPosition', 'qualid', 'recvparam',
|
||||
'restype', 'params', 'startPosition', 'thrown',
|
||||
'tree', 'typarams', 'typetag', 'vartype']) {
|
||||
@ -83,7 +83,7 @@ function javaASTToScriptObject(args) {
|
||||
|
||||
var visitor = new ConverterVisitor() {
|
||||
// convert java AST node to a friendly script object
|
||||
// which can be viewed. Every node ends up in defaultAction
|
||||
// which can be viewed. Every node ends up in defaultAction
|
||||
// method of SimpleTreeVisitor method.
|
||||
|
||||
defaultAction: function (node, p) {
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -83,7 +83,7 @@ var counter = new CastCounter() {
|
||||
this.lineMap = node.lineMap;
|
||||
this.fileName = node.sourceFile.name;
|
||||
|
||||
// Using Java.super API to call super class method here
|
||||
// Using Java.super API to call super class method here
|
||||
return Java.super(counter).visitCompilationUnit(node, p);
|
||||
},
|
||||
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -30,7 +30,7 @@
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
// This example demonstrates Java subclassing by Java.extend
|
||||
// and javac Compiler and Tree API. This example counts number
|
||||
// of variables called "foo" in the given java source files!
|
||||
@ -38,7 +38,7 @@ if (arguments.length == 0) {
|
||||
print("Usage: jjs javafoovars.js -- <directory>");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
// Java types used
|
||||
var File = Java.type("java.io.File");
|
||||
var Files = Java.type("java.nio.file.Files");
|
||||
@ -48,7 +48,7 @@ var ToolProvider = Java.type("javax.tools.ToolProvider");
|
||||
var Tree = Java.type("com.sun.source.tree.Tree");
|
||||
var TreeScanner = Java.type("com.sun.source.util.TreeScanner");
|
||||
var VariableTree = Java.type("com.sun.source.tree.VariableTree");
|
||||
|
||||
|
||||
// count "foo"-s in the given .java files
|
||||
function countFoo() {
|
||||
// get the system compiler tool
|
||||
@ -63,7 +63,7 @@ function countFoo() {
|
||||
// subclass SimpleTreeVisitor - to count variables called "foo"
|
||||
var FooCounterVisitor = Java.extend(TreeScanner);
|
||||
var fooCount = 0;
|
||||
|
||||
|
||||
var visitor = new FooCounterVisitor() {
|
||||
visitVariable: function (node, p) {
|
||||
if (node.name.toString() == "foo") {
|
||||
@ -71,13 +71,13 @@ function countFoo() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for each (var cu in task.parse()) {
|
||||
cu.accept(visitor, null);
|
||||
}
|
||||
return fooCount;
|
||||
}
|
||||
|
||||
|
||||
// for each ".java" file in directory (recursively) count "foo".
|
||||
function main(dir) {
|
||||
var totalCount = 0;
|
||||
@ -99,5 +99,5 @@ function main(dir) {
|
||||
});
|
||||
print("Total foo count: " + totalCount);
|
||||
}
|
||||
|
||||
|
||||
main(new File(arguments[0]));
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -34,14 +34,14 @@
|
||||
|
||||
function readTextFromURL(url) {
|
||||
|
||||
// equivalent to
|
||||
//
|
||||
// equivalent to
|
||||
//
|
||||
// import java.io.*;
|
||||
// import java.net.*;
|
||||
// import java.lang.StringBuffer;
|
||||
//
|
||||
// only inside the 'with' statement
|
||||
with (new JavaImporter(java.io,
|
||||
with (new JavaImporter(java.io,
|
||||
java.net,
|
||||
java.lang.StringBuilder)) {
|
||||
var buf = new StringBuilder();
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -45,7 +45,7 @@ print(map.get('js'));
|
||||
print(map['js']);
|
||||
print(map.js);
|
||||
|
||||
// also assign new key-value pair
|
||||
// also assign new key-value pair
|
||||
// as 'property-value'
|
||||
map['language'] = 'java';
|
||||
print(map.get("language"));
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -130,7 +130,7 @@ function exec(args) {
|
||||
// generate unique name
|
||||
function uniqueName() {
|
||||
var now = LocalDateTime.now().toString();
|
||||
// replace unsafe chars with '_'
|
||||
// replace unsafe chars with '_'
|
||||
return "JavaShell" + now.replace(/-|:|\./g, '_');
|
||||
}
|
||||
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
// Simple example that demonstrates reading XML Rss feed
|
||||
// to generate a HTML file from script and show it by browser
|
||||
// Uses XML DOM parser and DOM element wrapped by script
|
||||
// Uses XML DOM parser and DOM element wrapped by script
|
||||
// "proxy" (JSAdapter constructor)
|
||||
|
||||
// Java classes used
|
||||
@ -78,7 +78,7 @@ function getElemText(elem) {
|
||||
var node = nodeList.item(i);
|
||||
if (node.nodeType == TEXT_NODE) {
|
||||
text += node.nodeValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
var AbstractJSObject = Java.type("jdk.nashorn.api.scripting.AbstractJSObject");
|
||||
|
||||
// JSObject example that uses a map for properties and
|
||||
// JSObject example that uses a map for properties and
|
||||
// falls back to with methods on a java object (for missing
|
||||
// properties
|
||||
|
||||
@ -49,7 +49,7 @@ function makeJSObj(map, fallback) {
|
||||
return function() {
|
||||
var a = arguments;
|
||||
switch (a.length) {
|
||||
case 0: return fallback[name]();
|
||||
case 0: return fallback[name]();
|
||||
case 1: return fallback[name](a[0]);
|
||||
case 2: return fallback[name](a[0], a[1]);
|
||||
case 3: return fallback[name](a[0], a[1], a[2]);
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -31,9 +31,9 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// Many Array.prototype functions such as map,
|
||||
// Many Array.prototype functions such as map,
|
||||
// filter, reduce, reduceRight, every, some are generic.
|
||||
// These functions accept ECMAScript array as well as
|
||||
// These functions accept ECMAScript array as well as
|
||||
// many array-like objects including JSObjects.
|
||||
// See also http://en.wikipedia.org/wiki/MapReduce
|
||||
|
||||
@ -57,6 +57,6 @@ forEach.call(buf, function(x) print(x));
|
||||
// print sum of squares of the random numbers
|
||||
print("Square sum:",
|
||||
reduce.call(
|
||||
map.call(buf, function(x) x*x),
|
||||
map.call(buf, function(x) x*x),
|
||||
function(x, y) x + y)
|
||||
);
|
||||
|
||||
@ -4,22 +4,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -52,8 +52,8 @@ var TreeView = Java.type("javafx.scene.control.TreeView");
|
||||
|
||||
// read text content of a URL
|
||||
function readTextFromURL(url) {
|
||||
// equivalent to
|
||||
//
|
||||
// equivalent to
|
||||
//
|
||||
// import java.io.*;
|
||||
// import java.net.*;
|
||||
// import java.lang.StringBuffer;
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -43,7 +43,7 @@ var obj = { sender: $ARG[0], recipient: $ARG[1] };
|
||||
// JavaScript style line comment is ok too.
|
||||
print(<<EOF);
|
||||
Dear ${obj.recipient},
|
||||
|
||||
|
||||
I wish you all the best.
|
||||
|
||||
Regards,
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -31,9 +31,9 @@
|
||||
|
||||
// Usage: jjs list_mapreduce.js
|
||||
|
||||
// Many Array.prototype functions such as map,
|
||||
// Many Array.prototype functions such as map,
|
||||
// filter, reduce, reduceRight, every, some are generic.
|
||||
// These functions accept ECMAScript array as well as
|
||||
// These functions accept ECMAScript array as well as
|
||||
// many array-like objects including java.util.ArrayLists.
|
||||
// So, you can do map/filter/reduce with Java streams or
|
||||
// you can also use Array.prototype functions as below.
|
||||
@ -81,6 +81,6 @@ forEach.call(list, function(x) print(x));
|
||||
// print sum of squares of the random numbers
|
||||
print("Square sum:",
|
||||
reduce.call(
|
||||
map.call(list, function(x) x*x),
|
||||
map.call(list, function(x) x*x),
|
||||
function(x, y) x + y)
|
||||
);
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -46,6 +46,6 @@ timer.schedule(function() {
|
||||
}, 1000);
|
||||
|
||||
// wait for timer thread to print by
|
||||
// reading from stdin.
|
||||
// reading from stdin.
|
||||
print("press any key to exit after message from timer...");
|
||||
System.in.read();
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -33,7 +33,7 @@
|
||||
// error objects. This property's value is a string
|
||||
// that shows script stack trace.
|
||||
|
||||
function g() {
|
||||
function g() {
|
||||
throw new Error("wrong");
|
||||
}
|
||||
|
||||
@ -44,9 +44,9 @@ function f() {
|
||||
// Output looks something like:
|
||||
//
|
||||
// Error: wrong
|
||||
// at g (stack.js:37)
|
||||
// at f (stack.js:41)
|
||||
// at <program> (stack.js:52)
|
||||
// at g (stack.js:37)
|
||||
// at f (stack.js:41)
|
||||
// at <program> (stack.js:52)
|
||||
|
||||
try {
|
||||
f();
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -31,7 +31,7 @@
|
||||
|
||||
// Usage: jjs uniqs.js -- <file>
|
||||
// omit repeated lines and print unique lines
|
||||
// But this version uses Stream API
|
||||
// But this version uses Stream API
|
||||
|
||||
if (arguments.length < 1) {
|
||||
print("Usage: jjs uniqs.js -- <file>");
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
48
nashorn/samples/zipfs.js
Normal file
48
nashorn/samples/zipfs.js
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
if (arguments.length == 0) {
|
||||
print("Usage: jjs zipfs.js -- <.zip/.jar file>")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
var Files = Java.type("java.nio.file.Files")
|
||||
var FileSystems = Java.type("java.nio.file.FileSystems")
|
||||
var FileVisitOption = Java.type("java.nio.file.FileVisitOption")
|
||||
var Paths = Java.type("java.nio.file.Paths")
|
||||
|
||||
var zipfile = Paths.get(arguments[0])
|
||||
var fs = FileSystems.newFileSystem(zipfile, null)
|
||||
var root = fs.rootDirectories[0]
|
||||
Files.walk(root, FileVisitOption.FOLLOW_LINKS).forEach(
|
||||
function(p) (print(p), print(Files.readAttributes(p, "zip:*")))
|
||||
)
|
||||
fs.close()
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -30,7 +30,7 @@
|
||||
*/
|
||||
|
||||
if (arguments.length == 0) {
|
||||
print("Usage: jjs ziplist <zip-file>");
|
||||
print("Usage: jjs ziplist -- <zip-file>");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@ -40,7 +40,6 @@ import java.security.ProtectionDomain;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.script.AbstractScriptEngine;
|
||||
import javax.script.Bindings;
|
||||
import javax.script.Compilable;
|
||||
@ -51,7 +50,6 @@ import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineFactory;
|
||||
import javax.script.ScriptException;
|
||||
import javax.script.SimpleBindings;
|
||||
|
||||
import jdk.nashorn.internal.objects.Global;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.ErrorManager;
|
||||
|
||||
@ -715,6 +715,23 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
|
||||
return newArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Are the given objects mirrors to same underlying object?
|
||||
*
|
||||
* @param obj1 first object
|
||||
* @param obj2 second object
|
||||
* @return true if obj1 and obj2 are identical script objects or mirrors of it.
|
||||
*/
|
||||
public static boolean identical(final Object obj1, final Object obj2) {
|
||||
final Object o1 = (obj1 instanceof ScriptObjectMirror)?
|
||||
((ScriptObjectMirror)obj1).sobj : obj1;
|
||||
|
||||
final Object o2 = (obj2 instanceof ScriptObjectMirror)?
|
||||
((ScriptObjectMirror)obj2).sobj : obj2;
|
||||
|
||||
return o1 == o2;
|
||||
}
|
||||
|
||||
// package-privates below this.
|
||||
|
||||
ScriptObjectMirror(final ScriptObject sobj, final Global global) {
|
||||
|
||||
@ -382,10 +382,6 @@ final class AssignSymbols extends NodeOperatorVisitor<LexicalContext> implements
|
||||
symbol.setFlags(flags);
|
||||
}
|
||||
|
||||
if((isVar || isParam) && compiler.useOptimisticTypes() && compiler.isOnDemandCompilation()) {
|
||||
compiler.declareLocalSymbol(name);
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
@ -687,6 +683,22 @@ final class AssignSymbols extends NodeOperatorVisitor<LexicalContext> implements
|
||||
return binaryNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node leaveBlock(final Block block) {
|
||||
// It's not necessary to guard the marking of symbols as locals with this "if"condition for correctness, it's
|
||||
// just an optimization -- runtime type calculation is not used when the compilation is not an on-demand
|
||||
// optimistic compilation, so we can skip locals marking then.
|
||||
if (compiler.useOptimisticTypes() && compiler.isOnDemandCompilation()) {
|
||||
for (final Symbol symbol: block.getSymbols()) {
|
||||
if (!symbol.isScope()) {
|
||||
assert symbol.isVar() || symbol.isParam();
|
||||
compiler.declareLocalSymbol(symbol.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node leaveDELETE(final UnaryNode unaryNode) {
|
||||
final FunctionNode currentFunctionNode = lc.getCurrentFunction();
|
||||
|
||||
@ -56,7 +56,6 @@ import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALL
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_OPTIMISTIC;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_PROGRAM_POINT_SHIFT;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_SCOPE;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_STRICT;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayDeque;
|
||||
@ -250,8 +249,6 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
|
||||
private final Deque<Label> scopeEntryLabels = new ArrayDeque<>();
|
||||
|
||||
private final Set<Integer> initializedFunctionIds = new HashSet<>();
|
||||
|
||||
private static final Label METHOD_BOUNDARY = new Label("");
|
||||
private final Deque<Label> catchLabels = new ArrayDeque<>();
|
||||
// Number of live locals on entry to (and thus also break from) labeled blocks.
|
||||
@ -291,7 +288,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
* @return the correct flags for a call site in the current function
|
||||
*/
|
||||
int getCallSiteFlags() {
|
||||
return lc.getCurrentFunction().isStrict() ? callSiteFlags | CALLSITE_STRICT : callSiteFlags;
|
||||
return lc.getCurrentFunction().getCallSiteFlags() | callSiteFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1766,7 +1763,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
}
|
||||
|
||||
// Debugging: print symbols? @see --print-symbols flag
|
||||
printSymbols(block, (isFunctionBody ? "Function " : "Block in ") + (function.getIdent() == null ? "<anonymous>" : function.getIdent().getName()));
|
||||
printSymbols(block, function, (isFunctionBody ? "Function " : "Block in ") + (function.getIdent() == null ? "<anonymous>" : function.getIdent().getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1872,6 +1869,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
// lingers around. Also, currently loading previously persisted optimistic types information only works if
|
||||
// we're on-demand compiling a function, so with this strategy the :program method can also have the warmup
|
||||
// benefit of using previously persisted types.
|
||||
//
|
||||
// NOTE that this means the first compiled class will effectively just have a :createProgramFunction method, and
|
||||
// the RecompilableScriptFunctionData (RSFD) object in its constants array. It won't even have the :program
|
||||
// method. This is by design. It does mean that we're wasting one compiler execution (and we could minimize this
|
||||
@ -1879,11 +1877,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
// We could emit an initial separate compile unit with the initial version of :program in it to better utilize
|
||||
// the compilation pipeline, but that would need more invasive changes, as currently the assumption that
|
||||
// :program is emitted into the first compilation unit of the function lives in many places.
|
||||
if(!onDemand && lazy && env._optimistic_types && functionNode.isProgram()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return !onDemand && lazy && env._optimistic_types && functionNode.isProgram();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -4111,19 +4105,18 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
* Debug code used to print symbols
|
||||
*
|
||||
* @param block the block we are in
|
||||
* @param function the function we are in
|
||||
* @param ident identifier for block or function where applicable
|
||||
*/
|
||||
private void printSymbols(final Block block, final String ident) {
|
||||
if (!compiler.getScriptEnvironment()._print_symbols) {
|
||||
return;
|
||||
private void printSymbols(final Block block, final FunctionNode function, final String ident) {
|
||||
if (compiler.getScriptEnvironment()._print_symbols || function.getFlag(FunctionNode.IS_PRINT_SYMBOLS)) {
|
||||
final PrintWriter out = compiler.getScriptEnvironment().getErr();
|
||||
out.println("[BLOCK in '" + ident + "']");
|
||||
if (!block.printSymbols(out)) {
|
||||
out.println("<no symbols>");
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
|
||||
final PrintWriter out = compiler.getScriptEnvironment().getErr();
|
||||
out.println("[BLOCK in '" + ident + "']");
|
||||
if (!block.printSymbols(out)) {
|
||||
out.println("<no symbols>");
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
|
||||
|
||||
@ -4383,9 +4376,8 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
createFunction.end();
|
||||
}
|
||||
|
||||
if (addInitializer && !initializedFunctionIds.contains(fnId) && !compiler.isOnDemandCompilation()) {
|
||||
functionNode.getCompileUnit().addFunctionInitializer(data, functionNode);
|
||||
initializedFunctionIds.add(fnId);
|
||||
if (addInitializer && !compiler.isOnDemandCompilation()) {
|
||||
compiler.addFunctionInitializer(data, functionNode);
|
||||
}
|
||||
|
||||
// We don't emit a ScriptFunction on stack for the outermost compiled function (as there's no code being
|
||||
|
||||
@ -61,6 +61,7 @@ import jdk.nashorn.internal.ir.debug.ASTWriter;
|
||||
import jdk.nashorn.internal.ir.debug.PrintVisitor;
|
||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||
import jdk.nashorn.internal.runtime.CodeInstaller;
|
||||
import jdk.nashorn.internal.runtime.FunctionInitializer;
|
||||
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
|
||||
import jdk.nashorn.internal.runtime.ScriptEnvironment;
|
||||
import jdk.nashorn.internal.runtime.logging.DebugLogger;
|
||||
@ -279,12 +280,12 @@ enum CompilationPhase {
|
||||
final PrintWriter err = senv.getErr();
|
||||
|
||||
//TODO separate phase for the debug printouts for abstraction and clarity
|
||||
if (senv._print_lower_ast) {
|
||||
if (senv._print_lower_ast || fn.getFlag(FunctionNode.IS_PRINT_LOWER_AST)) {
|
||||
err.println("Lower AST for: " + quote(newFunctionNode.getName()));
|
||||
err.println(new ASTWriter(newFunctionNode));
|
||||
}
|
||||
|
||||
if (senv._print_lower_parse) {
|
||||
if (senv._print_lower_parse || fn.getFlag(FunctionNode.IS_PRINT_LOWER_PARSE)) {
|
||||
err.println("Lower AST for: " + quote(newFunctionNode.getName()));
|
||||
err.println(new PrintVisitor(newFunctionNode));
|
||||
}
|
||||
@ -324,15 +325,15 @@ enum CompilationPhase {
|
||||
final DebugLogger log = compiler.getLogger();
|
||||
|
||||
log.fine("Clearing bytecode cache");
|
||||
compiler.clearBytecode();
|
||||
|
||||
for (final CompileUnit oldUnit : compiler.getCompileUnits()) {
|
||||
CompileUnit newUnit = map.get(oldUnit);
|
||||
assert map.get(oldUnit) == null;
|
||||
final StringBuilder sb = new StringBuilder(compiler.nextCompileUnitName());
|
||||
if (phases.isRestOfCompilation()) {
|
||||
sb.append("$restOf");
|
||||
}
|
||||
newUnit = compiler.createCompileUnit(sb.toString(), oldUnit.getWeight());
|
||||
final CompileUnit newUnit = compiler.createCompileUnit(sb.toString(), oldUnit.getWeight());
|
||||
log.fine("Creating new compile unit ", oldUnit, " => ", newUnit);
|
||||
map.put(oldUnit, newUnit);
|
||||
assert newUnit != null;
|
||||
@ -502,8 +503,7 @@ enum CompilationPhase {
|
||||
long length = 0L;
|
||||
|
||||
final CodeInstaller<ScriptEnvironment> codeInstaller = compiler.getCodeInstaller();
|
||||
|
||||
final Map<String, byte[]> bytecode = compiler.getBytecode();
|
||||
final Map<String, byte[]> bytecode = compiler.getBytecode();
|
||||
|
||||
for (final Entry<String, byte[]> entry : bytecode.entrySet()) {
|
||||
final String className = entry.getKey();
|
||||
@ -536,17 +536,18 @@ enum CompilationPhase {
|
||||
// initialize function in the compile units
|
||||
for (final CompileUnit unit : compiler.getCompileUnits()) {
|
||||
unit.setCode(installedClasses.get(unit.getUnitClassName()));
|
||||
unit.initializeFunctionsCode();
|
||||
}
|
||||
|
||||
if (!compiler.isOnDemandCompilation()) {
|
||||
codeInstaller.storeCompiledScript(compiler.getSource(), compiler.getFirstCompileUnit().getUnitClassName(), bytecode, constants);
|
||||
}
|
||||
|
||||
// remove installed bytecode from table in case compiler is reused
|
||||
for (final String className : installedClasses.keySet()) {
|
||||
log.fine("Removing installed class ", quote(className), " from bytecode table...");
|
||||
compiler.removeClass(className);
|
||||
// Initialize functions
|
||||
final Map<Integer, FunctionInitializer> initializers = compiler.getFunctionInitializers();
|
||||
if (initializers != null) {
|
||||
for (final Entry<Integer, FunctionInitializer> entry : initializers.entrySet()) {
|
||||
final FunctionInitializer initializer = entry.getValue();
|
||||
initializer.setCode(installedClasses.get(initializer.getClassName()));
|
||||
compiler.getScriptFunctionData(entry.getKey()).initializeCode(initializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (log.isEnabled()) {
|
||||
|
||||
@ -25,12 +25,8 @@
|
||||
|
||||
package jdk.nashorn.internal.codegen;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import jdk.nashorn.internal.ir.FunctionNode;
|
||||
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
|
||||
|
||||
/**
|
||||
* Used to track split class compilation.
|
||||
@ -46,36 +42,6 @@ public final class CompileUnit implements Comparable<CompileUnit> {
|
||||
|
||||
private Class<?> clazz;
|
||||
|
||||
private Set<FunctionInitializer> functionInitializers = new LinkedHashSet<>();
|
||||
|
||||
private static class FunctionInitializer {
|
||||
final RecompilableScriptFunctionData data;
|
||||
final FunctionNode functionNode;
|
||||
|
||||
FunctionInitializer(final RecompilableScriptFunctionData data, final FunctionNode functionNode) {
|
||||
this.data = data;
|
||||
this.functionNode = functionNode;
|
||||
}
|
||||
|
||||
void initializeCode() {
|
||||
data.initializeCode(functionNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return data.hashCode() + 31 * functionNode.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == null || obj.getClass() != FunctionInitializer.class) {
|
||||
return false;
|
||||
}
|
||||
final FunctionInitializer other = (FunctionInitializer)obj;
|
||||
return data == other.data && functionNode == other.functionNode;
|
||||
}
|
||||
}
|
||||
|
||||
CompileUnit(final String className, final ClassEmitter classEmitter, final long initialWeight) {
|
||||
this.className = className;
|
||||
this.weight = initialWeight;
|
||||
@ -108,29 +74,6 @@ public final class CompileUnit implements Comparable<CompileUnit> {
|
||||
this.classEmitter = null;
|
||||
}
|
||||
|
||||
void addFunctionInitializer(final RecompilableScriptFunctionData data, final FunctionNode functionNode) {
|
||||
functionInitializers.add(new FunctionInitializer(data, functionNode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this compile unit is responsible for initializing the specified function data with specified
|
||||
* function node.
|
||||
* @param data the function data to check
|
||||
* @param functionNode the function node to check
|
||||
* @return true if this unit is responsible for initializing the function data with the function node, otherwise
|
||||
* false
|
||||
*/
|
||||
public boolean isInitializing(final RecompilableScriptFunctionData data, final FunctionNode functionNode) {
|
||||
return functionInitializers.contains(new FunctionInitializer(data, functionNode));
|
||||
}
|
||||
|
||||
void initializeFunctionsCode() {
|
||||
for(final FunctionInitializer init : functionInitializers) {
|
||||
init.initializeCode();
|
||||
}
|
||||
functionInitializers = Collections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add weight to this compile unit
|
||||
* @param w weight to add
|
||||
|
||||
@ -50,7 +50,6 @@ import java.util.TreeMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import jdk.internal.dynalink.support.NameCodec;
|
||||
import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
|
||||
import jdk.nashorn.internal.codegen.types.Type;
|
||||
@ -60,6 +59,7 @@ import jdk.nashorn.internal.ir.debug.ClassHistogramElement;
|
||||
import jdk.nashorn.internal.ir.debug.ObjectSizeCalculator;
|
||||
import jdk.nashorn.internal.runtime.CodeInstaller;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.FunctionInitializer;
|
||||
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
|
||||
import jdk.nashorn.internal.runtime.ScriptEnvironment;
|
||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||
@ -89,8 +89,6 @@ public final class Compiler implements Loggable {
|
||||
|
||||
private final String sourceName;
|
||||
|
||||
private final String sourceURL;
|
||||
|
||||
private final boolean optimistic;
|
||||
|
||||
private final Map<String, byte[]> bytecode;
|
||||
@ -309,21 +307,19 @@ public final class Compiler implements Loggable {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context context
|
||||
* @param env script environment
|
||||
* @param installer code installer
|
||||
* @param source source to compile
|
||||
* @param sourceURL source URL, or null if not present
|
||||
* @param isStrict is this a strict compilation
|
||||
* @param context context
|
||||
* @param env script environment
|
||||
* @param installer code installer
|
||||
* @param source source to compile
|
||||
* @param isStrict is this a strict compilation
|
||||
*/
|
||||
public Compiler(
|
||||
final Context context,
|
||||
final ScriptEnvironment env,
|
||||
final CodeInstaller<ScriptEnvironment> installer,
|
||||
final Source source,
|
||||
final String sourceURL,
|
||||
final boolean isStrict) {
|
||||
this(context, env, installer, source, sourceURL, isStrict, false, null, null, null, null, null, null);
|
||||
this(context, env, installer, source, isStrict, false, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -333,7 +329,6 @@ public final class Compiler implements Loggable {
|
||||
* @param env script environment
|
||||
* @param installer code installer
|
||||
* @param source source to compile
|
||||
* @param sourceURL source URL, or null if not present
|
||||
* @param isStrict is this a strict compilation
|
||||
* @param isOnDemand is this an on demand compilation
|
||||
* @param compiledFunction compiled function, if any
|
||||
@ -348,7 +343,6 @@ public final class Compiler implements Loggable {
|
||||
final ScriptEnvironment env,
|
||||
final CodeInstaller<ScriptEnvironment> installer,
|
||||
final Source source,
|
||||
final String sourceURL,
|
||||
final boolean isStrict,
|
||||
final boolean isOnDemand,
|
||||
final RecompilableScriptFunctionData compiledFunction,
|
||||
@ -365,8 +359,7 @@ public final class Compiler implements Loggable {
|
||||
this.bytecode = new LinkedHashMap<>();
|
||||
this.log = initLogger(context);
|
||||
this.source = source;
|
||||
this.sourceURL = sourceURL;
|
||||
this.sourceName = FunctionNode.getSourceName(source, sourceURL);
|
||||
this.sourceName = FunctionNode.getSourceName(source);
|
||||
this.onDemand = isOnDemand;
|
||||
this.compiledFunction = compiledFunction;
|
||||
this.types = types;
|
||||
@ -411,6 +404,15 @@ public final class Compiler implements Loggable {
|
||||
sb.append(compilationId).append('$');
|
||||
}
|
||||
|
||||
if (types != null && compiledFunction.getFunctionNodeId() > 0) {
|
||||
sb.append(compiledFunction.getFunctionNodeId());
|
||||
final Type[] paramTypes = types.getParameterTypes(compiledFunction.getFunctionNodeId());
|
||||
for (final Type t : paramTypes) {
|
||||
sb.append(Type.getShortSignatureDescriptor(t));
|
||||
}
|
||||
sb.append('$');
|
||||
}
|
||||
|
||||
sb.append(Compiler.safeSourceName(env, installer, source));
|
||||
|
||||
return sb.toString();
|
||||
@ -559,8 +561,11 @@ public final class Compiler implements Loggable {
|
||||
return Collections.unmodifiableMap(bytecode);
|
||||
}
|
||||
|
||||
byte[] getBytecode(final String className) {
|
||||
return bytecode.get(className);
|
||||
/**
|
||||
* Reset bytecode cache for compiler reuse.
|
||||
*/
|
||||
void clearBytecode() {
|
||||
bytecode.clear();
|
||||
}
|
||||
|
||||
CompileUnit getFirstCompileUnit() {
|
||||
@ -584,15 +589,6 @@ public final class Compiler implements Loggable {
|
||||
bytecode.put(name, code);
|
||||
}
|
||||
|
||||
void removeClass(final String name) {
|
||||
assert bytecode.get(name) != null;
|
||||
bytecode.remove(name);
|
||||
}
|
||||
|
||||
String getSourceURL() {
|
||||
return sourceURL;
|
||||
}
|
||||
|
||||
String nextCompileUnitName() {
|
||||
final StringBuilder sb = new StringBuilder(firstCompileUnitName);
|
||||
final int cuid = nextCompileUnitId.getAndIncrement();
|
||||
@ -603,8 +599,51 @@ public final class Compiler implements Loggable {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
void clearCompileUnits() {
|
||||
compileUnits.clear();
|
||||
Map<Integer, FunctionInitializer> functionInitializers;
|
||||
|
||||
void addFunctionInitializer(final RecompilableScriptFunctionData functionData, final FunctionNode functionNode) {
|
||||
if (functionInitializers == null) {
|
||||
functionInitializers = new HashMap<>();
|
||||
}
|
||||
if (!functionInitializers.containsKey(functionData)) {
|
||||
functionInitializers.put(functionData.getFunctionNodeId(), new FunctionInitializer(functionNode));
|
||||
}
|
||||
}
|
||||
|
||||
Map<Integer, FunctionInitializer> getFunctionInitializers() {
|
||||
return functionInitializers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist current compilation with the given {@code cacheKey}.
|
||||
* @param cacheKey cache key
|
||||
* @param functionNode function node
|
||||
*/
|
||||
public void persistClassInfo(final String cacheKey, final FunctionNode functionNode) {
|
||||
if (cacheKey != null && env._persistent_cache) {
|
||||
Map<Integer, FunctionInitializer> initializers;
|
||||
// If this is an on-demand compilation create a function initializer for the function being compiled.
|
||||
// Otherwise use function initializer map generated by codegen.
|
||||
if (functionInitializers == null) {
|
||||
initializers = new HashMap<>();
|
||||
final FunctionInitializer initializer = new FunctionInitializer(functionNode, getInvalidatedProgramPoints());
|
||||
initializers.put(functionNode.getId(), initializer);
|
||||
} else {
|
||||
initializers = functionInitializers;
|
||||
}
|
||||
final String mainClassName = getFirstCompileUnit().getUnitClassName();
|
||||
installer.storeScript(cacheKey, source, mainClassName, bytecode, initializers, constantData.toArray(), compilationId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure the next compilation id is greater than {@code value}.
|
||||
* @param value compilation id value
|
||||
*/
|
||||
public static void updateCompilationId(final int value) {
|
||||
if (value >= COMPILATION_ID.get()) {
|
||||
COMPILATION_ID.set(value + 1);
|
||||
}
|
||||
}
|
||||
|
||||
CompileUnit addCompileUnit(final long initialWeight) {
|
||||
|
||||
@ -30,7 +30,6 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import jdk.nashorn.internal.runtime.Property;
|
||||
import jdk.nashorn.internal.runtime.PropertyMap;
|
||||
|
||||
/**
|
||||
@ -121,12 +120,7 @@ final class ConstantData {
|
||||
private final int hashCode;
|
||||
|
||||
public PropertyMapWrapper(final PropertyMap map) {
|
||||
int hash = 0;
|
||||
for (final Property property : map.getProperties()) {
|
||||
hash = hash << 7 ^ hash >> 7;
|
||||
hash ^= property.hashCode();
|
||||
}
|
||||
this.hashCode = hash;
|
||||
this.hashCode = Arrays.hashCode(map.getProperties());
|
||||
this.propertyMap = map;
|
||||
}
|
||||
|
||||
@ -137,14 +131,8 @@ final class ConstantData {
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object other) {
|
||||
if (!(other instanceof PropertyMapWrapper)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Property[] ownProperties = propertyMap.getProperties();
|
||||
final Property[] otherProperties = ((PropertyMapWrapper) other).propertyMap.getProperties();
|
||||
|
||||
return Arrays.equals(ownProperties, otherProperties);
|
||||
return other instanceof PropertyMapWrapper &&
|
||||
Arrays.equals(propertyMap.getProperties(), ((PropertyMapWrapper) other).propertyMap.getProperties());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -217,7 +217,6 @@ final class FindScopeDepths extends NodeVisitor<LexicalContext> implements Logga
|
||||
allocatorClassName,
|
||||
allocatorMap,
|
||||
nestedFunctions,
|
||||
compiler.getSourceURL(),
|
||||
externalSymbolDepths.get(fnId),
|
||||
internalSymbols.get(fnId)
|
||||
);
|
||||
|
||||
@ -34,7 +34,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import jdk.nashorn.internal.ir.BaseNode;
|
||||
import jdk.nashorn.internal.ir.BinaryNode;
|
||||
import jdk.nashorn.internal.ir.Block;
|
||||
|
||||
@ -40,8 +40,6 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import jdk.nashorn.internal.codegen.types.Type;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
|
||||
@ -80,12 +78,11 @@ public final class OptimisticTypesPersistence {
|
||||
final StringBuilder b = new StringBuilder(48);
|
||||
// Base64-encode the digest of the source, and append the function id.
|
||||
b.append(source.getDigest()).append('-').append(functionId);
|
||||
// Finally, if this is a parameter-type specialized version of the function, add the parameter types to the file
|
||||
// name.
|
||||
// Finally, if this is a parameter-type specialized version of the function, add the parameter types to the file name.
|
||||
if(paramTypes != null && paramTypes.length > 0) {
|
||||
b.append('-');
|
||||
for(final Type t: paramTypes) {
|
||||
b.append(t.getBytecodeStackType());
|
||||
b.append(Type.getShortSignatureDescriptor(t));
|
||||
}
|
||||
}
|
||||
return new LocationDescriptor(new File(cacheDir, b.toString()));
|
||||
@ -108,7 +105,7 @@ public final class OptimisticTypesPersistence {
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
public static void store(final Object locationDescriptor, final Map<Integer, Type> optimisticTypes) {
|
||||
if(locationDescriptor == null) {
|
||||
if(locationDescriptor == null || optimisticTypes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final File file = ((LocationDescriptor)locationDescriptor).file;
|
||||
@ -117,25 +114,10 @@ public final class OptimisticTypesPersistence {
|
||||
@Override
|
||||
public Void run() {
|
||||
synchronized(getFileLock(file)) {
|
||||
try (final FileOutputStream out = new FileOutputStream(file);) {
|
||||
try (final FileOutputStream out = new FileOutputStream(file)) {
|
||||
out.getChannel().lock(); // lock exclusive
|
||||
final DataOutputStream dout = new DataOutputStream(new BufferedOutputStream(out));
|
||||
dout.writeInt(optimisticTypes.size());
|
||||
for(final Map.Entry<Integer, Type> e: optimisticTypes.entrySet()) {
|
||||
dout.writeInt(e.getKey());
|
||||
final byte typeChar;
|
||||
final Type type = e.getValue();
|
||||
if(type == Type.OBJECT) {
|
||||
typeChar = 'L';
|
||||
} else if(type == Type.NUMBER) {
|
||||
typeChar = 'D';
|
||||
} else if(type == Type.LONG) {
|
||||
typeChar = 'J';
|
||||
} else {
|
||||
throw new AssertionError();
|
||||
}
|
||||
dout.write(typeChar);
|
||||
}
|
||||
Type.writeTypeMap(optimisticTypes, dout);
|
||||
dout.flush();
|
||||
} catch(final Exception e) {
|
||||
reportError("write", file, e);
|
||||
@ -166,24 +148,10 @@ public final class OptimisticTypesPersistence {
|
||||
return null;
|
||||
}
|
||||
synchronized(getFileLock(file)) {
|
||||
try (final FileInputStream in = new FileInputStream(file);) {
|
||||
try (final FileInputStream in = new FileInputStream(file)) {
|
||||
in.getChannel().lock(0, Long.MAX_VALUE, true); // lock shared
|
||||
final DataInputStream din = new DataInputStream(new BufferedInputStream(in));
|
||||
final Map<Integer, Type> map = new TreeMap<>();
|
||||
final int size = din.readInt();
|
||||
for(int i = 0; i < size; ++i) {
|
||||
final int pp = din.readInt();
|
||||
final int typeChar = din.read();
|
||||
final Type type;
|
||||
switch(typeChar) {
|
||||
case 'L': type = Type.OBJECT; break;
|
||||
case 'D': type = Type.NUMBER; break;
|
||||
case 'J': type = Type.LONG; break;
|
||||
default: throw new AssertionError();
|
||||
}
|
||||
map.put(pp, type);
|
||||
}
|
||||
return map;
|
||||
return Type.readTypeMap(din);
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
@ -276,7 +244,7 @@ public final class OptimisticTypesPersistence {
|
||||
private static String getVersionDirName() throws Exception {
|
||||
final URL url = OptimisticTypesPersistence.class.getResource("");
|
||||
final String protocol = url.getProtocol();
|
||||
if(protocol.equals("jar")) {
|
||||
if (protocol.equals("jar")) {
|
||||
// Normal deployment: nashorn.jar
|
||||
final String jarUrlFile = url.getFile();
|
||||
final String filePath = jarUrlFile.substring(0, jarUrlFile.indexOf('!'));
|
||||
@ -310,12 +278,12 @@ public final class OptimisticTypesPersistence {
|
||||
for(final File f: dir.listFiles()) {
|
||||
if(f.getName().endsWith(".class")) {
|
||||
final long lastModified = f.lastModified();
|
||||
if(lastModified > currentMax) {
|
||||
if (lastModified > currentMax) {
|
||||
currentMax = lastModified;
|
||||
}
|
||||
} else if(f.isDirectory()) {
|
||||
} else if (f.isDirectory()) {
|
||||
final long lastModified = getLastModifiedClassFile(f, currentMax);
|
||||
if(lastModified > currentMax) {
|
||||
if (lastModified > currentMax) {
|
||||
currentMax = lastModified;
|
||||
}
|
||||
}
|
||||
@ -325,7 +293,7 @@ public final class OptimisticTypesPersistence {
|
||||
|
||||
private static Object[] createLockArray() {
|
||||
final Object[] lockArray = new Object[Runtime.getRuntime().availableProcessors() * 2];
|
||||
for(int i = 0; i < lockArray.length; ++i) {
|
||||
for (int i = 0; i < lockArray.length; ++i) {
|
||||
lockArray[i] = new Object();
|
||||
}
|
||||
return lockArray;
|
||||
|
||||
@ -115,6 +115,14 @@ final class TypeEvaluator {
|
||||
return Type.typeFor(JSType.unboxedFieldType(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares a symbol name as belonging to a non-scoped local variable during an on-demand compilation of a single
|
||||
* function. This method will add an explicit Undefined binding for the local into the runtime scope if it's
|
||||
* otherwise implicitly undefined so that when an expression is evaluated for the name, it won't accidentally find
|
||||
* an unrelated value higher up the scope chain. It is only required to call this method when doing an optimistic
|
||||
* on-demand compilation.
|
||||
* @param symbolName the name of the symbol that is to be declared as being a non-scoped local variable.
|
||||
*/
|
||||
void declareLocalSymbol(final String symbolName) {
|
||||
assert
|
||||
compiler.useOptimisticTypes() &&
|
||||
|
||||
@ -48,10 +48,15 @@ import static jdk.internal.org.objectweb.asm.Opcodes.T_INT;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.T_LONG;
|
||||
import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.lang.invoke.CallSite;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import jdk.internal.org.objectweb.asm.Handle;
|
||||
@ -203,6 +208,20 @@ public abstract class Type implements Comparable<Type>, BytecodeOps {
|
||||
return jdk.internal.org.objectweb.asm.Type.getMethodDescriptor(getInternalType(returnType), itypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a character representing {@code type} in a method signature.
|
||||
*
|
||||
* @param type parameter type
|
||||
* @return descriptor character
|
||||
*/
|
||||
public static char getShortSignatureDescriptor(final Type type) {
|
||||
// Use 'Z' for boolean parameters as we need to distinguish from int
|
||||
if (type instanceof BooleanType) {
|
||||
return 'Z';
|
||||
}
|
||||
return type.getBytecodeStackType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type for an internal type, package private - do not use
|
||||
* outside code gen
|
||||
@ -275,6 +294,64 @@ public abstract class Type implements Comparable<Type>, BytecodeOps {
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a map of {@code int} to {@code Type} to an output stream. This is used to store deoptimization state.
|
||||
*
|
||||
* @param typeMap the type map
|
||||
* @param output data output
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void writeTypeMap(final Map<Integer, Type> typeMap, final DataOutput output) throws IOException {
|
||||
if (typeMap == null) {
|
||||
output.writeInt(0);
|
||||
} else {
|
||||
output.writeInt(typeMap.size());
|
||||
for(final Map.Entry<Integer, Type> e: typeMap.entrySet()) {
|
||||
output.writeInt(e.getKey());
|
||||
final byte typeChar;
|
||||
final Type type = e.getValue();
|
||||
if(type == Type.OBJECT) {
|
||||
typeChar = 'L';
|
||||
} else if (type == Type.NUMBER) {
|
||||
typeChar = 'D';
|
||||
} else if (type == Type.LONG) {
|
||||
typeChar = 'J';
|
||||
} else {
|
||||
throw new AssertionError();
|
||||
}
|
||||
output.writeByte(typeChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a map of {@code int} to {@code Type} from an input stream. This is used to store deoptimization state.
|
||||
*
|
||||
* @param input data input
|
||||
* @return type map
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Map<Integer, Type> readTypeMap(final DataInput input) throws IOException {
|
||||
final int size = input.readInt();
|
||||
if (size == 0) {
|
||||
return null;
|
||||
}
|
||||
final Map<Integer, Type> map = new TreeMap<>();
|
||||
for(int i = 0; i < size; ++i) {
|
||||
final int pp = input.readInt();
|
||||
final int typeChar = input.readByte();
|
||||
final Type type;
|
||||
switch(typeChar) {
|
||||
case 'L': type = Type.OBJECT; break;
|
||||
case 'D': type = Type.NUMBER; break;
|
||||
case 'J': type = Type.LONG; break;
|
||||
default: throw new AssertionError();
|
||||
}
|
||||
map.put(pp, type);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
static jdk.internal.org.objectweb.asm.Type getInternalType(final String className) {
|
||||
return jdk.internal.org.objectweb.asm.Type.getType(className);
|
||||
}
|
||||
|
||||
@ -30,7 +30,6 @@ import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import jdk.nashorn.internal.codegen.types.Type;
|
||||
import jdk.nashorn.internal.ir.annotations.Ignore;
|
||||
import jdk.nashorn.internal.ir.annotations.Immutable;
|
||||
|
||||
@ -25,12 +25,18 @@
|
||||
|
||||
package jdk.nashorn.internal.ir;
|
||||
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_PROFILE;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_STRICT;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_ENTEREXIT;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_MISSES;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_VALUES;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import jdk.nashorn.internal.codegen.CompileUnit;
|
||||
@ -81,7 +87,7 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
LOWERED,
|
||||
/** program points have been assigned to unique locations */
|
||||
PROGRAM_POINTS_ASSIGNED,
|
||||
/** any transformations of builtins have taken place, e.g. apply=>call */
|
||||
/** any transformations of builtins have taken place, e.g. apply=>call */
|
||||
BUILTINS_TRANSFORMED,
|
||||
/** method has been split */
|
||||
SPLIT,
|
||||
@ -150,9 +156,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
/** Function flags. */
|
||||
private final int flags;
|
||||
|
||||
/** //@ sourceURL or //# sourceURL for program function nodes */
|
||||
private final String sourceURL;
|
||||
|
||||
/** Line number of function start */
|
||||
private final int lineNumber;
|
||||
|
||||
@ -232,6 +235,37 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
/** Is this declared in a dynamic context */
|
||||
public static final int IN_DYNAMIC_CONTEXT = 1 << 17;
|
||||
|
||||
/**
|
||||
* The following flags are derived from directive comments within this function.
|
||||
* Note that even IS_STRICT is one such flag but that requires special handling.
|
||||
*/
|
||||
|
||||
// parser, lower debugging this function
|
||||
public static final int IS_PRINT_PARSE = 1 << 18;
|
||||
public static final int IS_PRINT_LOWER_PARSE = 1 << 19;
|
||||
public static final int IS_PRINT_AST = 1 << 20;
|
||||
public static final int IS_PRINT_LOWER_AST = 1 << 21;
|
||||
public static final int IS_PRINT_SYMBOLS = 1 << 22;
|
||||
|
||||
/** profile callsites in this function? */
|
||||
public static final int IS_PROFILE = 1 << 23;
|
||||
|
||||
// callsite tracing, profiling within this function
|
||||
/** trace callsite enterexit in this function? */
|
||||
public static final int IS_TRACE_ENTEREXIT = 1 << 24;
|
||||
|
||||
/** trace callsite misses in this function? */
|
||||
public static final int IS_TRACE_MISSES = 1 << 25;
|
||||
|
||||
/** trace callsite values in this function? */
|
||||
public static final int IS_TRACE_VALUES = 1 << 26;
|
||||
|
||||
/** extension callsite flags mask */
|
||||
public static final int EXTENSION_CALLSITE_FLAGS = IS_PRINT_PARSE |
|
||||
IS_PRINT_LOWER_PARSE | IS_PRINT_AST | IS_PRINT_LOWER_AST |
|
||||
IS_PRINT_SYMBOLS | IS_PROFILE | IS_TRACE_ENTEREXIT |
|
||||
IS_TRACE_MISSES | IS_TRACE_VALUES;
|
||||
|
||||
/** Does this function or any nested functions contain an eval? */
|
||||
private static final int HAS_DEEP_EVAL = HAS_EVAL | HAS_NESTED_EVAL;
|
||||
|
||||
@ -269,7 +303,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
* @param parameters parameter list
|
||||
* @param kind kind of function as in {@link FunctionNode.Kind}
|
||||
* @param flags initial flags
|
||||
* @param sourceURL sourceURL specified in script (optional)
|
||||
*/
|
||||
public FunctionNode(
|
||||
final Source source,
|
||||
@ -283,8 +316,7 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
final String name,
|
||||
final List<IdentNode> parameters,
|
||||
final FunctionNode.Kind kind,
|
||||
final int flags,
|
||||
final String sourceURL) {
|
||||
final int flags) {
|
||||
super(token, finish);
|
||||
|
||||
this.source = source;
|
||||
@ -300,7 +332,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this.compilationState = EnumSet.of(CompilationState.INITIALIZED);
|
||||
this.declaredSymbols = new HashSet<>();
|
||||
this.flags = flags;
|
||||
this.sourceURL = sourceURL;
|
||||
this.compileUnit = null;
|
||||
this.body = null;
|
||||
this.thisProperties = 0;
|
||||
@ -311,7 +342,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
final FunctionNode functionNode,
|
||||
final long lastToken,
|
||||
final int flags,
|
||||
final String sourceURL,
|
||||
final String name,
|
||||
final Type returnType,
|
||||
final CompileUnit compileUnit,
|
||||
@ -324,7 +354,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
|
||||
this.lineNumber = functionNode.lineNumber;
|
||||
this.flags = flags;
|
||||
this.sourceURL = sourceURL;
|
||||
this.name = name;
|
||||
this.returnType = returnType;
|
||||
this.compileUnit = compileUnit;
|
||||
@ -362,6 +391,41 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
return Node.accept(visitor, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional callsite flags to be used specific to this function.
|
||||
*
|
||||
* @return callsite flags
|
||||
*/
|
||||
public int getCallSiteFlags() {
|
||||
int callsiteFlags = 0;
|
||||
if (getFlag(IS_STRICT)) {
|
||||
callsiteFlags |= CALLSITE_STRICT;
|
||||
}
|
||||
|
||||
// quick check for extension callsite flags turned on by directives.
|
||||
if ((flags & EXTENSION_CALLSITE_FLAGS) == 0) {
|
||||
return callsiteFlags;
|
||||
}
|
||||
|
||||
if (getFlag(IS_PROFILE)) {
|
||||
callsiteFlags |= CALLSITE_PROFILE;
|
||||
}
|
||||
|
||||
if (getFlag(IS_TRACE_MISSES)) {
|
||||
callsiteFlags |= CALLSITE_TRACE | CALLSITE_TRACE_MISSES;
|
||||
}
|
||||
|
||||
if (getFlag(IS_TRACE_VALUES)) {
|
||||
callsiteFlags |= CALLSITE_TRACE | CALLSITE_TRACE_ENTEREXIT | CALLSITE_TRACE_VALUES;
|
||||
}
|
||||
|
||||
if (getFlag(IS_TRACE_ENTEREXIT)) {
|
||||
callsiteFlags |= CALLSITE_TRACE | CALLSITE_TRACE_ENTEREXIT;
|
||||
}
|
||||
|
||||
return callsiteFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source for this function
|
||||
* @return the source
|
||||
@ -384,56 +448,50 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
* @return name for the script source
|
||||
*/
|
||||
public String getSourceName() {
|
||||
return getSourceName(source, sourceURL);
|
||||
return getSourceName(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static source name getter
|
||||
*
|
||||
* @param source
|
||||
* @param sourceURL
|
||||
* @param source the source
|
||||
* @return source name
|
||||
*/
|
||||
public static String getSourceName(final Source source, final String sourceURL) {
|
||||
return sourceURL != null ? sourceURL : source.getName();
|
||||
public static String getSourceName(final Source source) {
|
||||
final String explicitURL = source.getExplicitURL();
|
||||
return explicitURL != null ? explicitURL : source.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the sourceURL
|
||||
* @return the sourceURL
|
||||
*/
|
||||
public String getSourceURL() {
|
||||
return sourceURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sourceURL
|
||||
* Function to parse nashorn per-function extension directive comments.
|
||||
*
|
||||
* @param lc lexical context
|
||||
* @param newSourceURL source url string to set
|
||||
* @return function node or a new one if state was changed
|
||||
* @param directive nashorn extension directive string
|
||||
* @return integer flag for the given directive.
|
||||
*/
|
||||
public FunctionNode setSourceURL(final LexicalContext lc, final String newSourceURL) {
|
||||
if (Objects.equals(sourceURL, newSourceURL)) {
|
||||
return this;
|
||||
public static int getDirectiveFlag(final String directive) {
|
||||
switch (directive) {
|
||||
case "nashorn callsite trace enterexit":
|
||||
return IS_TRACE_ENTEREXIT;
|
||||
case "nashorn callsite trace misses":
|
||||
return IS_TRACE_MISSES;
|
||||
case "nashorn callsite trace objects":
|
||||
return IS_TRACE_VALUES;
|
||||
case "nashorn callsite profile":
|
||||
return IS_PROFILE;
|
||||
case "nashorn print parse":
|
||||
return IS_PRINT_PARSE;
|
||||
case "nashorn print lower parse":
|
||||
return IS_PRINT_LOWER_PARSE;
|
||||
case "nashorn print ast":
|
||||
return IS_PRINT_AST;
|
||||
case "nashorn print lower ast":
|
||||
return IS_PRINT_LOWER_AST;
|
||||
case "nashorn print symbols":
|
||||
return IS_PRINT_SYMBOLS;
|
||||
default:
|
||||
// unknown/unsupported directive
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Node.replaceInLexicalContext(
|
||||
lc,
|
||||
this,
|
||||
new FunctionNode(
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
newSourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
compilationState,
|
||||
body,
|
||||
parameters,
|
||||
thisProperties,
|
||||
rootClass));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -469,11 +527,11 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the state of this FunctionNode contains a given compilation<
|
||||
* Check whether the state of this FunctionNode contains a given compilation
|
||||
* state.
|
||||
*
|
||||
* A node can be in many states at once, e.g. both lowered and initialized.
|
||||
* To check for an exact state, use {FunctionNode{@link #hasState(EnumSet)}
|
||||
* To check for an exact state, use {@link #hasState(EnumSet)}
|
||||
*
|
||||
* @param state state to check for
|
||||
* @return true if state is present in the total compilation state of this FunctionNode
|
||||
@ -504,7 +562,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -576,7 +633,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -733,7 +789,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
(body.needsScope() ?
|
||||
FunctionNode.HAS_SCOPE_BLOCK :
|
||||
0),
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -829,7 +884,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -890,7 +944,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -926,7 +979,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -992,7 +1044,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -1071,7 +1122,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
type,
|
||||
compileUnit,
|
||||
@ -1118,7 +1168,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -1174,7 +1223,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
|
||||
@ -27,7 +27,6 @@ package jdk.nashorn.internal.ir;
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import jdk.nashorn.internal.runtime.Debug;
|
||||
import jdk.nashorn.internal.runtime.Source;
|
||||
|
||||
|
||||
@ -29,7 +29,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import jdk.nashorn.internal.codegen.CompileUnit;
|
||||
import jdk.nashorn.internal.codegen.types.ArrayType;
|
||||
import jdk.nashorn.internal.codegen.types.Type;
|
||||
|
||||
@ -27,7 +27,6 @@ package jdk.nashorn.internal.ir;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||
import jdk.nashorn.internal.parser.Token;
|
||||
import jdk.nashorn.internal.parser.TokenType;
|
||||
|
||||
@ -39,7 +39,6 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import jdk.internal.org.objectweb.asm.Attribute;
|
||||
import jdk.internal.org.objectweb.asm.Handle;
|
||||
import jdk.internal.org.objectweb.asm.Label;
|
||||
|
||||
@ -46,10 +46,8 @@ import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
import javax.script.ScriptEngine;
|
||||
|
||||
import jdk.internal.dynalink.linker.GuardedInvocation;
|
||||
import jdk.internal.dynalink.linker.LinkRequest;
|
||||
import jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||
@ -396,19 +394,19 @@ public final class Global extends ScriptObject implements Scope {
|
||||
private ScriptObject builtinJavafx;
|
||||
private ScriptObject builtinJavax;
|
||||
private ScriptObject builtinOrg;
|
||||
private ScriptObject builtinJavaImporter;
|
||||
private ScriptFunction builtinJavaImporter;
|
||||
private ScriptObject builtinJavaApi;
|
||||
private ScriptObject builtinArrayBuffer;
|
||||
private ScriptObject builtinDataView;
|
||||
private ScriptObject builtinInt8Array;
|
||||
private ScriptObject builtinUint8Array;
|
||||
private ScriptObject builtinUint8ClampedArray;
|
||||
private ScriptObject builtinInt16Array;
|
||||
private ScriptObject builtinUint16Array;
|
||||
private ScriptObject builtinInt32Array;
|
||||
private ScriptObject builtinUint32Array;
|
||||
private ScriptObject builtinFloat32Array;
|
||||
private ScriptObject builtinFloat64Array;
|
||||
private ScriptFunction builtinArrayBuffer;
|
||||
private ScriptFunction builtinDataView;
|
||||
private ScriptFunction builtinInt8Array;
|
||||
private ScriptFunction builtinUint8Array;
|
||||
private ScriptFunction builtinUint8ClampedArray;
|
||||
private ScriptFunction builtinInt16Array;
|
||||
private ScriptFunction builtinUint16Array;
|
||||
private ScriptFunction builtinInt32Array;
|
||||
private ScriptFunction builtinUint32Array;
|
||||
private ScriptFunction builtinFloat32Array;
|
||||
private ScriptFunction builtinFloat64Array;
|
||||
|
||||
/*
|
||||
* ECMA section 13.2.3 The [[ThrowTypeError]] Function Object
|
||||
@ -1688,15 +1686,15 @@ public final class Global extends ScriptObject implements Scope {
|
||||
this.quit = ScriptFunctionImpl.makeFunction("quit", EXIT);
|
||||
|
||||
// built-in constructors
|
||||
this.builtinArray = (ScriptFunction)initConstructor("Array");
|
||||
this.builtinBoolean = (ScriptFunction)initConstructor("Boolean");
|
||||
this.builtinDate = (ScriptFunction)initConstructor("Date");
|
||||
this.builtinJSON = initConstructor("JSON");
|
||||
this.builtinJSAdapter = (ScriptFunction)initConstructor("JSAdapter");
|
||||
this.builtinMath = initConstructor("Math");
|
||||
this.builtinNumber = (ScriptFunction)initConstructor("Number");
|
||||
this.builtinRegExp = (ScriptFunction)initConstructor("RegExp");
|
||||
this.builtinString = (ScriptFunction)initConstructor("String");
|
||||
this.builtinArray = initConstructor("Array", ScriptFunction.class);
|
||||
this.builtinBoolean = initConstructor("Boolean", ScriptFunction.class);
|
||||
this.builtinDate = initConstructor("Date", ScriptFunction.class);
|
||||
this.builtinJSON = initConstructor("JSON", ScriptObject.class);
|
||||
this.builtinJSAdapter = initConstructor("JSAdapter", ScriptFunction.class);
|
||||
this.builtinMath = initConstructor("Math", ScriptObject.class);
|
||||
this.builtinNumber = initConstructor("Number", ScriptFunction.class);
|
||||
this.builtinRegExp = initConstructor("RegExp", ScriptFunction.class);
|
||||
this.builtinString = initConstructor("String", ScriptFunction.class);
|
||||
|
||||
// initialize String.prototype.length to 0
|
||||
// add String.prototype.length
|
||||
@ -1777,7 +1775,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
|
||||
private void initErrorObjects() {
|
||||
// Error objects
|
||||
this.builtinError = (ScriptFunction)initConstructor("Error");
|
||||
this.builtinError = initConstructor("Error", ScriptFunction.class);
|
||||
final ScriptObject errorProto = getErrorPrototype();
|
||||
|
||||
// Nashorn specific accessors on Error.prototype - stack, lineNumber, columnNumber and fileName
|
||||
@ -1810,12 +1808,12 @@ public final class Global extends ScriptObject implements Scope {
|
||||
}
|
||||
|
||||
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) {
|
||||
final ScriptObject cons = initConstructor(name);
|
||||
final ScriptFunction cons = initConstructor(name, ScriptFunction.class);
|
||||
final ScriptObject prototype = ScriptFunction.getPrototype(cons);
|
||||
prototype.set(NativeError.NAME, name, false);
|
||||
prototype.set(NativeError.MESSAGE, "", false);
|
||||
prototype.setInitialProto(errorProto);
|
||||
return (ScriptFunction)cons;
|
||||
return cons;
|
||||
}
|
||||
|
||||
private void initJavaAccess() {
|
||||
@ -1827,8 +1825,8 @@ public final class Global extends ScriptObject implements Scope {
|
||||
this.builtinJavafx = new NativeJavaPackage("javafx", objectProto);
|
||||
this.builtinJavax = new NativeJavaPackage("javax", objectProto);
|
||||
this.builtinOrg = new NativeJavaPackage("org", objectProto);
|
||||
this.builtinJavaImporter = initConstructor("JavaImporter");
|
||||
this.builtinJavaApi = initConstructor("Java");
|
||||
this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class);
|
||||
this.builtinJavaApi = initConstructor("Java", ScriptObject.class);
|
||||
}
|
||||
|
||||
private void initScripting(final ScriptEnvironment scriptEnv) {
|
||||
@ -1881,17 +1879,17 @@ public final class Global extends ScriptObject implements Scope {
|
||||
}
|
||||
|
||||
private void initTypedArray() {
|
||||
this.builtinArrayBuffer = initConstructor("ArrayBuffer");
|
||||
this.builtinDataView = initConstructor("DataView");
|
||||
this.builtinInt8Array = initConstructor("Int8Array");
|
||||
this.builtinUint8Array = initConstructor("Uint8Array");
|
||||
this.builtinUint8ClampedArray = initConstructor("Uint8ClampedArray");
|
||||
this.builtinInt16Array = initConstructor("Int16Array");
|
||||
this.builtinUint16Array = initConstructor("Uint16Array");
|
||||
this.builtinInt32Array = initConstructor("Int32Array");
|
||||
this.builtinUint32Array = initConstructor("Uint32Array");
|
||||
this.builtinFloat32Array = initConstructor("Float32Array");
|
||||
this.builtinFloat64Array = initConstructor("Float64Array");
|
||||
this.builtinArrayBuffer = initConstructor("ArrayBuffer", ScriptFunction.class);
|
||||
this.builtinDataView = initConstructor("DataView", ScriptFunction.class);
|
||||
this.builtinInt8Array = initConstructor("Int8Array", ScriptFunction.class);
|
||||
this.builtinUint8Array = initConstructor("Uint8Array", ScriptFunction.class);
|
||||
this.builtinUint8ClampedArray = initConstructor("Uint8ClampedArray", ScriptFunction.class);
|
||||
this.builtinInt16Array = initConstructor("Int16Array", ScriptFunction.class);
|
||||
this.builtinUint16Array = initConstructor("Uint16Array", ScriptFunction.class);
|
||||
this.builtinInt32Array = initConstructor("Int32Array", ScriptFunction.class);
|
||||
this.builtinUint32Array = initConstructor("Uint32Array", ScriptFunction.class);
|
||||
this.builtinFloat32Array = initConstructor("Float32Array", ScriptFunction.class);
|
||||
this.builtinFloat64Array = initConstructor("Float64Array", ScriptFunction.class);
|
||||
}
|
||||
|
||||
private void copyBuiltins() {
|
||||
@ -1936,7 +1934,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
}
|
||||
|
||||
private void initDebug() {
|
||||
this.addOwnProperty("Debug", Attribute.NOT_ENUMERABLE, initConstructor("Debug"));
|
||||
this.addOwnProperty("Debug", Attribute.NOT_ENUMERABLE, initConstructor("Debug", ScriptObject.class));
|
||||
}
|
||||
|
||||
private Object printImpl(final boolean newLine, final Object... objects) {
|
||||
@ -1968,7 +1966,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
* These classes are generated by nasgen tool and so we have to use
|
||||
* reflection to load and create new instance of these classes.
|
||||
*/
|
||||
private ScriptObject initConstructor(final String name) {
|
||||
private <T extends ScriptObject> T initConstructor(final String name, final Class<T> clazz) {
|
||||
try {
|
||||
// Assuming class name pattern for built-in JS constructors.
|
||||
final StringBuilder sb = new StringBuilder("jdk.nashorn.internal.objects.");
|
||||
@ -1977,8 +1975,8 @@ public final class Global extends ScriptObject implements Scope {
|
||||
sb.append(name);
|
||||
sb.append("$Constructor");
|
||||
|
||||
final Class<?> funcClass = Class.forName(sb.toString());
|
||||
final ScriptObject res = (ScriptObject)funcClass.newInstance();
|
||||
final Class<?> funcClass = Class.forName(sb.toString());
|
||||
final T res = clazz.cast(funcClass.newInstance());
|
||||
|
||||
if (res instanceof ScriptFunction) {
|
||||
// All global constructor prototypes are not-writable,
|
||||
@ -1992,9 +1990,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
}
|
||||
|
||||
res.setIsBuiltin();
|
||||
|
||||
return res;
|
||||
|
||||
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -2008,7 +2004,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
// to play with object references carefully!!
|
||||
private void initFunctionAndObject() {
|
||||
// First-n-foremost is Function
|
||||
this.builtinFunction = (ScriptFunction)initConstructor("Function");
|
||||
this.builtinFunction = initConstructor("Function", ScriptFunction.class);
|
||||
|
||||
// create global anonymous function
|
||||
final ScriptFunction anon = ScriptFunctionImpl.newAnonymousFunction();
|
||||
@ -2030,7 +2026,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
typeErrorThrower.preventExtensions();
|
||||
|
||||
// now initialize Object
|
||||
this.builtinObject = (ScriptFunction)initConstructor("Object");
|
||||
this.builtinObject = initConstructor("Object", ScriptFunction.class);
|
||||
final ScriptObject ObjectPrototype = getObjectPrototype();
|
||||
// Object.getPrototypeOf(Function.prototype) === Object.prototype
|
||||
anon.setInitialProto(ObjectPrototype);
|
||||
@ -2154,7 +2150,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
/**
|
||||
* Tag a reserved name as invalidated - used when someone writes
|
||||
* to a property with this name - overly conservative, but link time
|
||||
* is too late to apply e.g. apply->call specialization
|
||||
* is too late to apply e.g. apply->call specialization
|
||||
* @param name property name
|
||||
*/
|
||||
public void invalidateReservedName(final String name) {
|
||||
|
||||
@ -45,8 +45,8 @@ import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.JSType;
|
||||
import jdk.nashorn.internal.runtime.ListAdapter;
|
||||
import jdk.nashorn.internal.runtime.PropertyMap;
|
||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||
import jdk.nashorn.internal.runtime.ScriptFunction;
|
||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||
import jdk.nashorn.internal.runtime.ScriptRuntime;
|
||||
import jdk.nashorn.internal.runtime.linker.Bootstrap;
|
||||
import jdk.nashorn.internal.runtime.linker.JavaAdapterFactory;
|
||||
|
||||
@ -39,7 +39,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import jdk.internal.dynalink.beans.BeansLinker;
|
||||
import jdk.internal.dynalink.beans.StaticClass;
|
||||
import jdk.internal.dynalink.linker.GuardedInvocation;
|
||||
|
||||
@ -39,6 +39,7 @@ import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import jdk.internal.dynalink.CallSiteDescriptor;
|
||||
import jdk.internal.dynalink.linker.GuardedInvocation;
|
||||
import jdk.internal.dynalink.linker.LinkRequest;
|
||||
@ -391,10 +392,12 @@ public final class NativeString extends ScriptObject {
|
||||
/**
|
||||
* return a List of own keys associated with the object.
|
||||
* @param all True if to include non-enumerable keys.
|
||||
* @param nonEnumerable set of non-enumerable properties seen already.Used
|
||||
* to filter out shadowed, but enumerable properties from proto children.
|
||||
* @return Array of keys.
|
||||
*/
|
||||
@Override
|
||||
public String[] getOwnKeys(final boolean all) {
|
||||
protected String[] getOwnKeys(final boolean all, final Set<String> nonEnumerable) {
|
||||
final List<Object> keys = new ArrayList<>();
|
||||
|
||||
// add string index keys
|
||||
@ -403,7 +406,7 @@ public final class NativeString extends ScriptObject {
|
||||
}
|
||||
|
||||
// add super class properties
|
||||
keys.addAll(Arrays.asList(super.getOwnKeys(all)));
|
||||
keys.addAll(Arrays.asList(super.getOwnKeys(all, nonEnumerable)));
|
||||
return keys.toArray(new String[keys.size()]);
|
||||
}
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ import java.lang.annotation.Target;
|
||||
* in NativeArray that takes an int, write
|
||||
*
|
||||
* <pre>
|
||||
* @SpecializedFunction @Optimistic
|
||||
* {@literal @}SpecializedFunction {@literal @}Optimistic
|
||||
* public static int push(final Object self, final int x, final int programPoint) {
|
||||
* try {
|
||||
* //push code assuming that this is an int array
|
||||
|
||||
@ -91,9 +91,6 @@ public abstract class AbstractParser {
|
||||
/** What should line numbers be counted from? */
|
||||
protected final int lineOffset;
|
||||
|
||||
/** //@ sourceURL or //# sourceURL */
|
||||
protected String sourceURL;
|
||||
|
||||
/**
|
||||
* Construct a parser.
|
||||
*
|
||||
@ -182,7 +179,7 @@ public abstract class AbstractParser {
|
||||
// currently only @sourceURL=foo supported
|
||||
private void checkDirectiveComment() {
|
||||
// if already set, ignore this one
|
||||
if (sourceURL != null) {
|
||||
if (source.getExplicitURL() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -190,7 +187,7 @@ public abstract class AbstractParser {
|
||||
final int len = comment.length();
|
||||
// 4 characters for directive comment marker //@\s or //#\s
|
||||
if (len > 4 && comment.substring(4).startsWith(SOURCE_URL_PREFIX)) {
|
||||
sourceURL = comment.substring(4 + SOURCE_URL_PREFIX.length());
|
||||
source.setExplicitURL(comment.substring(4 + SOURCE_URL_PREFIX.length()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -106,6 +106,8 @@ import jdk.nashorn.internal.ir.UnaryNode;
|
||||
import jdk.nashorn.internal.ir.VarNode;
|
||||
import jdk.nashorn.internal.ir.WhileNode;
|
||||
import jdk.nashorn.internal.ir.WithNode;
|
||||
import jdk.nashorn.internal.ir.debug.ASTWriter;
|
||||
import jdk.nashorn.internal.ir.debug.PrintVisitor;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.ErrorManager;
|
||||
import jdk.nashorn.internal.runtime.JSErrorType;
|
||||
@ -346,9 +348,10 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
expect(EOF);
|
||||
|
||||
function.setFinish(source.getLength() - 1);
|
||||
|
||||
function = restoreFunctionNode(function, token); //commit code
|
||||
function = function.setBody(lc, function.getBody().setNeedsScope(lc));
|
||||
|
||||
printAST(function);
|
||||
return function;
|
||||
} catch (final Exception e) {
|
||||
handleParseException(e);
|
||||
@ -477,8 +480,7 @@ loop:
|
||||
name,
|
||||
parameters,
|
||||
kind,
|
||||
flags,
|
||||
sourceURL);
|
||||
flags);
|
||||
|
||||
lc.push(functionNode);
|
||||
// Create new block, and just put it on the context stack, restoreFunctionNode() will associate it with the
|
||||
@ -702,10 +704,6 @@ loop:
|
||||
|
||||
script = restoreFunctionNode(script, token); //commit code
|
||||
script = script.setBody(lc, script.getBody().setNeedsScope(lc));
|
||||
// user may have directive comment to set sourceURL
|
||||
if (sourceURL != null) {
|
||||
script = script.setSourceURL(lc, sourceURL);
|
||||
}
|
||||
|
||||
return script;
|
||||
}
|
||||
@ -805,6 +803,12 @@ loop:
|
||||
verifyStrictIdent(param, "function parameter");
|
||||
}
|
||||
}
|
||||
} else if (Context.DEBUG) {
|
||||
final int flag = FunctionNode.getDirectiveFlag(directive);
|
||||
if (flag != 0) {
|
||||
final FunctionNode function = lc.getCurrentFunction();
|
||||
lc.setFlag(function, flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2814,14 +2818,24 @@ loop:
|
||||
lastToken = token;
|
||||
expect(RBRACE);
|
||||
functionNode.setFinish(finish);
|
||||
|
||||
}
|
||||
} finally {
|
||||
functionNode = restoreFunctionNode(functionNode, lastToken);
|
||||
}
|
||||
printAST(functionNode);
|
||||
return functionNode;
|
||||
}
|
||||
|
||||
private void printAST(final FunctionNode functionNode) {
|
||||
if (functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
|
||||
env.getErr().println(new ASTWriter(functionNode));
|
||||
}
|
||||
|
||||
if (functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
|
||||
env.getErr().println(new PrintVisitor(functionNode, true, false));
|
||||
}
|
||||
}
|
||||
|
||||
private void addFunctionDeclarations(final FunctionNode functionNode) {
|
||||
assert lc.peek() == lc.getFunctionBody(functionNode);
|
||||
VarNode lastDecl = null;
|
||||
|
||||
@ -136,16 +136,16 @@ public class AccessorProperty extends Property {
|
||||
}
|
||||
|
||||
/** Seed getter for the primitive version of this field (in -Dnashorn.fields.dual=true mode) */
|
||||
private transient MethodHandle primitiveGetter;
|
||||
transient MethodHandle primitiveGetter;
|
||||
|
||||
/** Seed setter for the primitive version of this field (in -Dnashorn.fields.dual=true mode) */
|
||||
private transient MethodHandle primitiveSetter;
|
||||
transient MethodHandle primitiveSetter;
|
||||
|
||||
/** Seed getter for the Object version of this field */
|
||||
private transient MethodHandle objectGetter;
|
||||
transient MethodHandle objectGetter;
|
||||
|
||||
/** Seed setter for the Object version of this field */
|
||||
private transient MethodHandle objectSetter;
|
||||
transient MethodHandle objectSetter;
|
||||
|
||||
/**
|
||||
* Current type of this object, in object only mode, this is an Object.class. In dual-fields mode
|
||||
@ -185,10 +185,10 @@ public class AccessorProperty extends Property {
|
||||
* @param key the property key
|
||||
* @param flags the property flags
|
||||
* @param slot spill slot
|
||||
* @param objectGetter
|
||||
* @param objectSetter
|
||||
* @param primitiveGetter
|
||||
* @param primitiveSetter
|
||||
* @param primitiveGetter primitive getter
|
||||
* @param primitiveSetter primitive setter
|
||||
* @param objectGetter object getter
|
||||
* @param objectSetter object setter
|
||||
*/
|
||||
protected AccessorProperty(
|
||||
final String key,
|
||||
@ -255,7 +255,7 @@ public class AccessorProperty extends Property {
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal ACCESS PROPERTY constructor given a structure glass.
|
||||
* Normal ACCESS PROPERTY constructor given a structure class.
|
||||
* Constructor for dual field AccessorPropertys.
|
||||
*
|
||||
* @param key property key
|
||||
@ -267,6 +267,7 @@ public class AccessorProperty extends Property {
|
||||
super(key, flags, slot);
|
||||
|
||||
initGetterSetter(structure);
|
||||
initializeType();
|
||||
}
|
||||
|
||||
private void initGetterSetter(final Class<?> structure) {
|
||||
@ -291,8 +292,6 @@ public class AccessorProperty extends Property {
|
||||
objectSetter = gs.objectSetters[slot];
|
||||
primitiveSetter = gs.primitiveSetters[slot];
|
||||
}
|
||||
|
||||
initializeType();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -412,8 +411,8 @@ public class AccessorProperty extends Property {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLongValue(final ScriptObject self, final ScriptObject owner) {
|
||||
@Override
|
||||
public long getLongValue(final ScriptObject self, final ScriptObject owner) {
|
||||
try {
|
||||
return (long)getGetter(long.class).invokeExact((Object)self);
|
||||
} catch (final Error | RuntimeException e) {
|
||||
@ -531,12 +530,13 @@ public class AccessorProperty extends Property {
|
||||
|
||||
@Override
|
||||
void initMethodHandles(final Class<?> structure) {
|
||||
// sanity check for structure class
|
||||
if (!ScriptObject.class.isAssignableFrom(structure) || !StructureLoader.isStructureClass(structure.getName())) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
if (!isSpill()) {
|
||||
initGetterSetter(structure);
|
||||
}
|
||||
// this method is overridden in SpillProperty
|
||||
assert !isSpill();
|
||||
initGetterSetter(structure);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -712,7 +712,7 @@ public class AccessorProperty extends Property {
|
||||
|
||||
|
||||
private MethodHandle debug(final MethodHandle mh, final Class<?> forType, final Class<?> type, final String tag) {
|
||||
if (!Global.hasInstance()) {
|
||||
if (!Context.DEBUG || !Global.hasInstance()) {
|
||||
return mh;
|
||||
}
|
||||
|
||||
@ -734,7 +734,7 @@ public class AccessorProperty extends Property {
|
||||
}
|
||||
|
||||
private MethodHandle debugReplace(final Class<?> oldType, final Class<?> newType, final PropertyMap oldMap, final PropertyMap newMap) {
|
||||
if (!Global.hasInstance()) {
|
||||
if (!Context.DEBUG || !Global.hasInstance()) {
|
||||
return REPLACE_MAP;
|
||||
}
|
||||
|
||||
@ -767,7 +767,7 @@ public class AccessorProperty extends Property {
|
||||
}
|
||||
|
||||
private static MethodHandle debugInvalidate(final String key, final SwitchPoint sp) {
|
||||
if (!Global.hasInstance()) {
|
||||
if (!Context.DEBUG || !Global.hasInstance()) {
|
||||
return INVALIDATE_SP;
|
||||
}
|
||||
|
||||
|
||||
@ -92,5 +92,14 @@ public interface CodeInstaller<T> {
|
||||
* @param classBytes map of class names to class bytes
|
||||
* @param constants constants array
|
||||
*/
|
||||
public void storeCompiledScript(Source source, String mainClassName, Map<String, byte[]> classBytes, Object[] constants);
|
||||
public void storeScript(String cacheKey, Source source, String mainClassName, Map<String, byte[]> classBytes,
|
||||
Map<Integer, FunctionInitializer> initializers, Object[] constants, int compilationId);
|
||||
|
||||
/**
|
||||
* Load a previously compiled script
|
||||
* @param source the script source
|
||||
* @param functionKey the function id and signature
|
||||
* @return compiled script data
|
||||
*/
|
||||
public StoredScript loadScript(Source source, String functionKey);
|
||||
}
|
||||
|
||||
@ -38,25 +38,30 @@ import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.Map;
|
||||
import jdk.nashorn.internal.codegen.types.Type;
|
||||
import jdk.nashorn.internal.runtime.logging.DebugLogger;
|
||||
import jdk.nashorn.internal.runtime.logging.Loggable;
|
||||
import jdk.nashorn.internal.runtime.logging.Logger;
|
||||
|
||||
/**
|
||||
* A code cache for persistent caching of compiled scripts.
|
||||
*/
|
||||
final class CodeStore {
|
||||
@Logger(name="codestore")
|
||||
final class CodeStore implements Loggable {
|
||||
|
||||
private final File dir;
|
||||
private final int minSize;
|
||||
private final DebugLogger log;
|
||||
|
||||
// Default minimum size for storing a compiled script class
|
||||
private final static int DEFAULT_MIN_SIZE = 1000;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param path directory to store code in
|
||||
* @throws IOException
|
||||
*/
|
||||
public CodeStore(final String path) throws IOException {
|
||||
this(path, DEFAULT_MIN_SIZE);
|
||||
public CodeStore(final Context context, final String path) throws IOException {
|
||||
this(context, path, DEFAULT_MIN_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,9 +70,20 @@ final class CodeStore {
|
||||
* @param minSize minimum file size for caching scripts
|
||||
* @throws IOException
|
||||
*/
|
||||
public CodeStore(final String path, final int minSize) throws IOException {
|
||||
public CodeStore(final Context context, final String path, final int minSize) throws IOException {
|
||||
this.dir = checkDirectory(path);
|
||||
this.minSize = minSize;
|
||||
this.log = initLogger(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DebugLogger initLogger(final Context context) {
|
||||
return context.getLogger(getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DebugLogger getLogger() {
|
||||
return log;
|
||||
}
|
||||
|
||||
private static File checkDirectory(final String path) throws IOException {
|
||||
@ -77,11 +93,11 @@ final class CodeStore {
|
||||
public File run() throws IOException {
|
||||
final File dir = new File(path).getAbsoluteFile();
|
||||
if (!dir.exists() && !dir.mkdirs()) {
|
||||
throw new IOException("Could not create directory: " + dir);
|
||||
throw new IOException("Could not create directory: " + dir.getPath());
|
||||
} else if (!dir.isDirectory()) {
|
||||
throw new IOException("Not a directory: " + dir);
|
||||
throw new IOException("Not a directory: " + dir.getPath());
|
||||
} else if (!dir.canRead() || !dir.canWrite()) {
|
||||
throw new IOException("Directory not readable or writable: " + dir);
|
||||
throw new IOException("Directory not readable or writable: " + dir.getPath());
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
@ -91,69 +107,85 @@ final class CodeStore {
|
||||
}
|
||||
}
|
||||
|
||||
private File getCacheFile(final Source source, final String functionKey) {
|
||||
return new File(dir, source.getDigest() + '-' + functionKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a string representing the function with {@code functionId} and {@code paramTypes}.
|
||||
* @param functionId function id
|
||||
* @param paramTypes parameter types
|
||||
* @return a string representing the function
|
||||
*/
|
||||
public static String getCacheKey(final int functionId, final Type[] paramTypes) {
|
||||
final StringBuilder b = new StringBuilder().append(functionId);
|
||||
if(paramTypes != null && paramTypes.length > 0) {
|
||||
b.append('-');
|
||||
for(final Type t: paramTypes) {
|
||||
b.append(Type.getShortSignatureDescriptor(t));
|
||||
}
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a compiled script from the cache, or null if it isn't found.
|
||||
*
|
||||
* @param source the source
|
||||
* @return the compiled script or null
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
* @param functionKey the function key
|
||||
* @return the stored script or null
|
||||
*/
|
||||
public CompiledScript getScript(final Source source) throws IOException, ClassNotFoundException {
|
||||
public StoredScript loadScript(final Source source, final String functionKey) {
|
||||
if (source.getLength() < minSize) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final File file = new File(dir, source.getDigest());
|
||||
final File file = getCacheFile(source, functionKey);
|
||||
|
||||
try {
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<CompiledScript>() {
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<StoredScript>() {
|
||||
@Override
|
||||
public CompiledScript run() throws IOException, ClassNotFoundException {
|
||||
public StoredScript run() throws IOException, ClassNotFoundException {
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
try (ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)))) {
|
||||
final CompiledScript compiledScript = (CompiledScript) in.readObject();
|
||||
compiledScript.setSource(source);
|
||||
return compiledScript;
|
||||
final StoredScript storedScript = (StoredScript) in.readObject();
|
||||
getLogger().info("loaded ", source, "-", functionKey);
|
||||
return storedScript;
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (final PrivilegedActionException e) {
|
||||
final Exception ex = e.getException();
|
||||
if (ex instanceof IOException) {
|
||||
throw (IOException) ex;
|
||||
} else if (ex instanceof ClassNotFoundException) {
|
||||
throw (ClassNotFoundException) ex;
|
||||
}
|
||||
throw (new RuntimeException(ex));
|
||||
getLogger().warning("failed to load ", source, "-", functionKey, ": ", e.getException());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a compiled script in the cache.
|
||||
*
|
||||
* @param functionKey the function key
|
||||
* @param source the source
|
||||
* @param mainClassName the main class name
|
||||
* @param classBytes a map of class bytes
|
||||
* @param constants the constants array
|
||||
* @throws IOException
|
||||
*/
|
||||
public void putScript(final Source source, final String mainClassName, final Map<String, byte[]> classBytes, final Object[] constants)
|
||||
throws IOException {
|
||||
public void storeScript(final String functionKey, final Source source, final String mainClassName, final Map<String, byte[]> classBytes,
|
||||
final Map<Integer, FunctionInitializer> initializers, final Object[] constants, final int compilationId) {
|
||||
if (source.getLength() < minSize) {
|
||||
return;
|
||||
}
|
||||
for (final Object constant : constants) {
|
||||
// Make sure all constant data is serializable
|
||||
if (! (constant instanceof Serializable)) {
|
||||
getLogger().warning("cannot store ", source, " non serializable constant ", constant);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final File file = new File(dir, source.getDigest());
|
||||
final CompiledScript script = new CompiledScript(source, mainClassName, classBytes, constants);
|
||||
final File file = getCacheFile(source, functionKey);
|
||||
final StoredScript script = new StoredScript(compilationId, mainClassName, classBytes, initializers, constants);
|
||||
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
|
||||
@ -162,11 +194,12 @@ final class CodeStore {
|
||||
try (ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) {
|
||||
out.writeObject(script);
|
||||
}
|
||||
getLogger().info("stored ", source, "-", functionKey);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (final PrivilegedActionException e) {
|
||||
throw (IOException) e.getException();
|
||||
getLogger().warning("failed to store ", script, "-", functionKey, ": ", e.getException());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,9 +37,12 @@ import java.lang.invoke.SwitchPoint;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import jdk.internal.dynalink.linker.GuardedInvocation;
|
||||
import jdk.nashorn.internal.codegen.Compiler;
|
||||
import jdk.nashorn.internal.codegen.Compiler.CompilationPhases;
|
||||
import jdk.nashorn.internal.codegen.TypeMap;
|
||||
import jdk.nashorn.internal.codegen.types.ArrayType;
|
||||
import jdk.nashorn.internal.codegen.types.Type;
|
||||
import jdk.nashorn.internal.ir.FunctionNode;
|
||||
@ -69,7 +72,8 @@ final class CompiledFunction {
|
||||
private MethodHandle invoker;
|
||||
private MethodHandle constructor;
|
||||
private OptimismInfo optimismInfo;
|
||||
private int flags; // from FunctionNode
|
||||
private final int flags; // from FunctionNode
|
||||
private final MethodType callSiteType;
|
||||
|
||||
CompiledFunction(final MethodHandle invoker) {
|
||||
this(invoker, null);
|
||||
@ -80,19 +84,20 @@ final class CompiledFunction {
|
||||
}
|
||||
|
||||
CompiledFunction(final MethodHandle invoker, final MethodHandle constructor) {
|
||||
this(invoker, constructor, DebugLogger.DISABLED_LOGGER);
|
||||
this(invoker, constructor, 0, null, DebugLogger.DISABLED_LOGGER);
|
||||
}
|
||||
|
||||
CompiledFunction(final MethodHandle invoker, final MethodHandle constructor, final DebugLogger log) {
|
||||
CompiledFunction(final MethodHandle invoker, final MethodHandle constructor, final int flags, final MethodType callSiteType, final DebugLogger log) {
|
||||
this.invoker = invoker;
|
||||
this.constructor = constructor;
|
||||
this.flags = flags;
|
||||
this.callSiteType = callSiteType;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
CompiledFunction(final MethodHandle invoker, final RecompilableScriptFunctionData functionData,
|
||||
final Map<Integer, Type> invalidatedProgramPoints, final int flags) {
|
||||
this(invoker, null, functionData.getLogger());
|
||||
this.flags = flags;
|
||||
final Map<Integer, Type> invalidatedProgramPoints, final MethodType callSiteType, final int flags) {
|
||||
this(invoker, null, flags, callSiteType, functionData.getLogger());
|
||||
if ((flags & FunctionNode.IS_DEOPTIMIZABLE) != 0) {
|
||||
optimismInfo = new OptimismInfo(functionData, invalidatedProgramPoints);
|
||||
} else {
|
||||
@ -125,9 +130,9 @@ final class CompiledFunction {
|
||||
* Returns an invoker method handle for this function. Note that the handle is safely composable in
|
||||
* the sense that you can compose it with other handles using any combinators even if you can't affect call site
|
||||
* invalidation. If this compiled function is non-optimistic, then it returns the same value as
|
||||
* {@link #getInvoker()}. However, if the function is optimistic, then this handle will incur an overhead as it will
|
||||
* add an intermediate internal call site that can relink itself when the function needs to regenerate its code to
|
||||
* always point at the latest generated code version.
|
||||
* {@link #getInvokerOrConstructor(boolean)}. However, if the function is optimistic, then this handle will
|
||||
* incur an overhead as it will add an intermediate internal call site that can relink itself when the function
|
||||
* needs to regenerate its code to always point at the latest generated code version.
|
||||
* @return a guaranteed composable invoker method handle for this function.
|
||||
*/
|
||||
MethodHandle createComposableInvoker() {
|
||||
@ -142,7 +147,7 @@ final class CompiledFunction {
|
||||
* all other cases, use {@link #createComposableConstructor()}.
|
||||
* @return a direct constructor method handle for this function.
|
||||
*/
|
||||
MethodHandle getConstructor() {
|
||||
private MethodHandle getConstructor() {
|
||||
if (constructor == null) {
|
||||
constructor = createConstructorFromInvoker(createInvokerForPessimisticCaller());
|
||||
}
|
||||
@ -163,8 +168,6 @@ final class CompiledFunction {
|
||||
* Compose a constructor from an invoker.
|
||||
*
|
||||
* @param invoker invoker
|
||||
* @param needsCallee do we need to pass a callee
|
||||
*
|
||||
* @return the composed constructor
|
||||
*/
|
||||
private static MethodHandle createConstructorFromInvoker(final MethodHandle invoker) {
|
||||
@ -425,6 +428,9 @@ final class CompiledFunction {
|
||||
}
|
||||
|
||||
boolean matchesCallSite(final MethodType callSiteType, final boolean pickVarArg) {
|
||||
if (callSiteType.equals(this.callSiteType)) {
|
||||
return true;
|
||||
}
|
||||
final MethodType type = type();
|
||||
final int fnParamCount = getParamCount(type);
|
||||
final boolean isVarArg = fnParamCount == Integer.MAX_VALUE;
|
||||
@ -462,17 +468,7 @@ final class CompiledFunction {
|
||||
return type.parameterType(paramCount - 1).isArray() ? Integer.MAX_VALUE : paramCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the switch point embodying the optimistic assumptions in this compiled function. It should be used to
|
||||
* guard any linking to the function's invoker or constructor.
|
||||
* @return the switch point embodying the optimistic assumptions in this compiled function. Null is returned if the
|
||||
* function has no optimistic assumptions.
|
||||
*/
|
||||
SwitchPoint getOptimisticAssumptionsSwitchPoint() {
|
||||
return canBeDeoptimized() ? optimismInfo.optimisticAssumptions : null;
|
||||
}
|
||||
|
||||
boolean canBeDeoptimized() {
|
||||
private boolean canBeDeoptimized() {
|
||||
return optimismInfo != null;
|
||||
}
|
||||
|
||||
@ -491,19 +487,73 @@ final class CompiledFunction {
|
||||
relinkComposableInvoker(cs, this, isConstructor);
|
||||
return cs.dynamicInvoker();
|
||||
}
|
||||
|
||||
private static class HandleAndAssumptions {
|
||||
final MethodHandle handle;
|
||||
final SwitchPoint assumptions;
|
||||
|
||||
HandleAndAssumptions(final MethodHandle handle, final SwitchPoint assumptions) {
|
||||
this.handle = handle;
|
||||
this.assumptions = assumptions;
|
||||
}
|
||||
|
||||
GuardedInvocation createInvocation() {
|
||||
return new GuardedInvocation(handle, assumptions);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pair of an invocation created with a passed-in supplier and a non-invalidated switch point for
|
||||
* optimistic assumptions (or null for the switch point if the function can not be deoptimized). While the method
|
||||
* makes a best effort to return a non-invalidated switch point (compensating for possible deoptimizing
|
||||
* recompilation happening on another thread) it is still possible that by the time this method returns the
|
||||
* switchpoint has been invalidated by a {@code RewriteException} triggered on another thread for this function.
|
||||
* This is not a problem, though, as these switch points are always used to produce call sites that fall back to
|
||||
* relinking when they are invalidated, and in this case the execution will end up here again. What this method
|
||||
* basically does is minimize such busy-loop relinking while the function is being recompiled on a different thread.
|
||||
* @param invocationSupplier the supplier that constructs the actual invocation method handle; should use the
|
||||
* {@code CompiledFunction} method itself in some capacity.
|
||||
* @return a tuple object containing the method handle as created by the supplier and an optimistic assumptions
|
||||
* switch point that is guaranteed to not have been invalidated before the call to this method (or null if the
|
||||
* function can't be further deoptimized).
|
||||
*/
|
||||
private synchronized HandleAndAssumptions getValidOptimisticInvocation(final Supplier<MethodHandle> invocationSupplier) {
|
||||
for(;;) {
|
||||
final MethodHandle handle = invocationSupplier.get();
|
||||
final SwitchPoint assumptions = canBeDeoptimized() ? optimismInfo.optimisticAssumptions : null;
|
||||
if(assumptions != null && assumptions.hasBeenInvalidated()) {
|
||||
// We can be in a situation where one thread is in the middle of a deoptimizing compilation when we hit
|
||||
// this and thus, it has invalidated the old switch point, but hasn't created the new one yet. Note that
|
||||
// the behavior of invalidating the old switch point before recompilation, and only creating the new one
|
||||
// after recompilation is by design. If we didn't wait here for the recompilation to complete, we would
|
||||
// be busy looping through the fallback path of the invalidated switch point, relinking the call site
|
||||
// again with the same invalidated switch point, invoking the fallback, etc. stealing CPU cycles from
|
||||
// the recompilation task we're dependent on. This can still happen if the switch point gets invalidated
|
||||
// after we grabbed it here, in which case we'll indeed do one busy relink immediately.
|
||||
try {
|
||||
wait();
|
||||
} catch (final InterruptedException e) {
|
||||
// Intentionally ignored. There's nothing meaningful we can do if we're interrupted
|
||||
}
|
||||
} else {
|
||||
return new HandleAndAssumptions(handle, assumptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void relinkComposableInvoker(final CallSite cs, final CompiledFunction inv, final boolean constructor) {
|
||||
final MethodHandle handle = inv.getInvokerOrConstructor(constructor);
|
||||
final SwitchPoint assumptions = inv.getOptimisticAssumptionsSwitchPoint();
|
||||
final HandleAndAssumptions handleAndAssumptions = inv.getValidOptimisticInvocation(new Supplier<MethodHandle>() {
|
||||
@Override
|
||||
public MethodHandle get() {
|
||||
return inv.getInvokerOrConstructor(constructor);
|
||||
}
|
||||
});
|
||||
final MethodHandle handle = handleAndAssumptions.handle;
|
||||
final SwitchPoint assumptions = handleAndAssumptions.assumptions;
|
||||
final MethodHandle target;
|
||||
if(assumptions == null) {
|
||||
target = handle;
|
||||
} else {
|
||||
// This assertion can obviously fail in a multithreaded environment, as we can be in a situation where
|
||||
// one thread is in the middle of a deoptimizing compilation when we hit this and thus, it has invalidated
|
||||
// the old switch point, but hasn't created the new one yet. Note that the behavior of invalidating the old
|
||||
// switch point before recompilation, and only creating the new one after recompilation is by design.
|
||||
// TODO: We need to think about thread safety of CompiledFunction objects.
|
||||
assert !assumptions.hasBeenInvalidated();
|
||||
final MethodHandle relink = MethodHandles.insertArguments(RELINK_COMPOSABLE_INVOKER, 0, cs, inv, constructor);
|
||||
target = assumptions.guardWithTest(handle, MethodHandles.foldArguments(cs.dynamicInvoker(), relink));
|
||||
}
|
||||
@ -514,7 +564,41 @@ final class CompiledFunction {
|
||||
return selectCtor ? getConstructor() : createInvokerForPessimisticCaller();
|
||||
}
|
||||
|
||||
MethodHandle createInvoker(final Class<?> callSiteReturnType, final int callerProgramPoint) {
|
||||
/**
|
||||
* Returns a guarded invocation for this function when not invoked as a constructor. The guarded invocation has no
|
||||
* guard but it potentially has an optimistic assumptions switch point. As such, it will probably not be used as a
|
||||
* final guarded invocation, but rather as a holder for an invocation handle and switch point to be decomposed and
|
||||
* reassembled into a different final invocation by the user of this method. Any recompositions should take care to
|
||||
* continue to use the switch point. If that is not possible, use {@link #createComposableInvoker()} instead.
|
||||
* @return a guarded invocation for an ordinary (non-constructor) invocation of this function.
|
||||
*/
|
||||
GuardedInvocation createFunctionInvocation(final Class<?> callSiteReturnType, final int callerProgramPoint) {
|
||||
return getValidOptimisticInvocation(new Supplier<MethodHandle>() {
|
||||
@Override
|
||||
public MethodHandle get() {
|
||||
return createInvoker(callSiteReturnType, callerProgramPoint);
|
||||
}
|
||||
}).createInvocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a guarded invocation for this function when invoked as a constructor. The guarded invocation has no guard
|
||||
* but it potentially has an optimistic assumptions switch point. As such, it will probably not be used as a final
|
||||
* guarded invocation, but rather as a holder for an invocation handle and switch point to be decomposed and
|
||||
* reassembled into a different final invocation by the user of this method. Any recompositions should take care to
|
||||
* continue to use the switch point. If that is not possible, use {@link #createComposableConstructor()} instead.
|
||||
* @return a guarded invocation for invocation of this function as a constructor.
|
||||
*/
|
||||
GuardedInvocation createConstructorInvocation() {
|
||||
return getValidOptimisticInvocation(new Supplier<MethodHandle>() {
|
||||
@Override
|
||||
public MethodHandle get() {
|
||||
return getConstructor();
|
||||
}
|
||||
}).createInvocation();
|
||||
}
|
||||
|
||||
private MethodHandle createInvoker(final Class<?> callSiteReturnType, final int callerProgramPoint) {
|
||||
final boolean isOptimistic = canBeDeoptimized();
|
||||
MethodHandle handleRewriteException = isOptimistic ? createRewriteExceptionHandler() : null;
|
||||
|
||||
@ -601,7 +685,7 @@ final class CompiledFunction {
|
||||
* @param re the rewrite exception that was raised
|
||||
* @return the method handle for the rest-of method, for folding composition.
|
||||
*/
|
||||
private MethodHandle handleRewriteException(final OptimismInfo oldOptInfo, final RewriteException re) {
|
||||
private synchronized MethodHandle handleRewriteException(final OptimismInfo oldOptInfo, final RewriteException re) {
|
||||
if (log.isEnabled()) {
|
||||
log.info(new RecompilationEvent(Level.INFO, re, re.getReturnValueNonDestructive()), "RewriteException ", re.getMessageShort());
|
||||
}
|
||||
@ -639,6 +723,15 @@ final class CompiledFunction {
|
||||
logRecompile("Rest-of compilation [CODE PIPELINE REUSE] ", fn, callSiteType, effectiveOptInfo.invalidatedProgramPoints);
|
||||
final FunctionNode normalFn = compiler.compile(fn, CompilationPhases.COMPILE_FROM_BYTECODE);
|
||||
|
||||
if (effectiveOptInfo.data.usePersistentCodeCache()) {
|
||||
final RecompilableScriptFunctionData data = effectiveOptInfo.data;
|
||||
final int functionNodeId = data.getFunctionNodeId();
|
||||
final TypeMap typeMap = data.typeMap(callSiteType);
|
||||
final Type[] paramTypes = typeMap == null ? null : typeMap.getParameterTypes(functionNodeId);
|
||||
final String cacheKey = CodeStore.getCacheKey(functionNodeId, paramTypes);
|
||||
compiler.persistClassInfo(cacheKey, normalFn);
|
||||
}
|
||||
|
||||
FunctionNode fn2 = effectiveOptInfo.reparse();
|
||||
fn2 = compiler.compile(fn2, CompilationPhases.COMPILE_UPTO_BYTECODE);
|
||||
log.info("Done.");
|
||||
@ -664,17 +757,18 @@ final class CompiledFunction {
|
||||
} else {
|
||||
optimismInfo = null; // If we got to a point where we no longer have optimistic assumptions, let the optimism info go.
|
||||
}
|
||||
notifyAll();
|
||||
|
||||
return restOf;
|
||||
}
|
||||
|
||||
private MethodHandle restOfHandle(final OptimismInfo info, final FunctionNode restOfFunction, final boolean canBeDeoptimized) {
|
||||
assert info != null;
|
||||
assert restOfFunction.getCompileUnit().getUnitClassName().indexOf("restOf") != -1;
|
||||
assert restOfFunction.getCompileUnit().getUnitClassName().contains("restOf");
|
||||
final MethodHandle restOf =
|
||||
changeReturnType(
|
||||
info.data.lookupWithExplicitType(
|
||||
restOfFunction,
|
||||
info.data.lookupCodeMethod(
|
||||
restOfFunction.getCompileUnit().getCode(),
|
||||
MH.type(restOfFunction.getReturnType().getTypeClass(),
|
||||
RewriteException.class)),
|
||||
Object.class);
|
||||
|
||||
@ -1,183 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package jdk.nashorn.internal.runtime;
|
||||
|
||||
import static jdk.nashorn.internal.lookup.Lookup.MH;
|
||||
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* This is a list of code versions of a function.
|
||||
* The list is sorted in ascending order of generic descriptors
|
||||
*/
|
||||
final class CompiledFunctions {
|
||||
|
||||
private final String name;
|
||||
final LinkedList<CompiledFunction> functions = new LinkedList<>();
|
||||
|
||||
CompiledFunctions(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
void add(final CompiledFunction f) {
|
||||
functions.add(f);
|
||||
}
|
||||
|
||||
void addAll(final CompiledFunctions fs) {
|
||||
functions.addAll(fs.functions);
|
||||
}
|
||||
|
||||
boolean isEmpty() {
|
||||
return functions.isEmpty();
|
||||
}
|
||||
|
||||
int size() {
|
||||
return functions.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return '\'' + name + "' code=" + functions;
|
||||
}
|
||||
|
||||
private static MethodType widen(final MethodType cftype) {
|
||||
final Class<?>[] paramTypes = new Class<?>[cftype.parameterCount()];
|
||||
for (int i = 0; i < cftype.parameterCount(); i++) {
|
||||
paramTypes[i] = cftype.parameterType(i).isPrimitive() ? cftype.parameterType(i) : Object.class;
|
||||
}
|
||||
return MH.type(cftype.returnType(), paramTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to find an apply to call version that fits this callsite.
|
||||
* We cannot just, as in the normal matcher case, return e.g. (Object, Object, int)
|
||||
* for (Object, Object, int, int, int) or we will destroy the semantics and get
|
||||
* a function that, when padded with undefineds, behaves differently
|
||||
* @param type actual call site type
|
||||
* @return apply to call that perfectly fits this callsite or null if none found
|
||||
*/
|
||||
CompiledFunction lookupExactApplyToCall(final MethodType type) {
|
||||
for (final CompiledFunction cf : functions) {
|
||||
if (!cf.isApplyToCall()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final MethodType cftype = cf.type();
|
||||
if (cftype.parameterCount() != type.parameterCount()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (widen(cftype).equals(widen(type))) {
|
||||
return cf;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private CompiledFunction pick(final MethodType callSiteType, final boolean canPickVarArg) {
|
||||
for (final CompiledFunction candidate : functions) {
|
||||
if (candidate.matchesCallSite(callSiteType, false)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the compiled function best matching the requested call site method type
|
||||
* @param callSiteType
|
||||
* @param recompilable
|
||||
* @param hasThis
|
||||
* @return
|
||||
*/
|
||||
CompiledFunction best(final MethodType callSiteType, final boolean recompilable) {
|
||||
assert callSiteType.parameterCount() >= 2 : callSiteType; // Must have at least (callee, this)
|
||||
assert callSiteType.parameterType(0).isAssignableFrom(ScriptFunction.class) : callSiteType; // Callee must be assignable from script function
|
||||
|
||||
if (recompilable) {
|
||||
final CompiledFunction candidate = pick(callSiteType, false);
|
||||
if (candidate != null) {
|
||||
return candidate;
|
||||
}
|
||||
return pick(callSiteType, true); //try vararg last
|
||||
}
|
||||
|
||||
CompiledFunction best = null;
|
||||
for(final CompiledFunction candidate: functions) {
|
||||
if(candidate.betterThanFinal(best, callSiteType)) {
|
||||
best = candidate;
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if functions managed by this {@code CompiledFunctions} require a callee. This method is only safe to
|
||||
* be invoked for a {@code CompiledFunctions} that is not empty. As such, it should only be used from
|
||||
* {@link FinalScriptFunctionData} and not from {@link RecompilableScriptFunctionData}.
|
||||
* @return true if the functions need a callee, false otherwise.
|
||||
*/
|
||||
boolean needsCallee() {
|
||||
final boolean needsCallee = functions.getFirst().needsCallee();
|
||||
assert allNeedCallee(needsCallee);
|
||||
return needsCallee;
|
||||
}
|
||||
|
||||
private boolean allNeedCallee(final boolean needCallee) {
|
||||
for (final CompiledFunction inv : functions) {
|
||||
if(inv.needsCallee() != needCallee) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this CompiledFunctions object belongs to a {@code FinalScriptFunctionData}, get a method type for a generic
|
||||
* invoker. It will either be a vararg type, if any of the contained functions is vararg, or a generic type of the
|
||||
* arity of the largest arity of all functions.
|
||||
* @return the method type for the generic invoker
|
||||
*/
|
||||
MethodType getFinalGenericType() {
|
||||
int max = 0;
|
||||
for(final CompiledFunction fn: functions) {
|
||||
final MethodType t = fn.type();
|
||||
if(ScriptFunctionData.isVarArg(t)) {
|
||||
// 2 for (callee, this, args[])
|
||||
return MethodType.genericMethodType(2, true);
|
||||
}
|
||||
final int paramCount = t.parameterCount() - (ScriptFunctionData.needsCallee(t) ? 1 : 0);
|
||||
if(paramCount > max) {
|
||||
max = paramCount;
|
||||
}
|
||||
}
|
||||
// +1 for callee
|
||||
return MethodType.genericMethodType(max + 1);
|
||||
}
|
||||
|
||||
}
|
||||
@ -91,14 +91,14 @@ public final class ConsString implements CharSequence {
|
||||
return new CharSequence[] { left, right };
|
||||
}
|
||||
|
||||
private CharSequence flattened(boolean flattenNested) {
|
||||
private CharSequence flattened(final boolean flattenNested) {
|
||||
if (state != STATE_FLATTENED) {
|
||||
flatten(flattenNested);
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
private synchronized void flatten(boolean flattenNested) {
|
||||
private synchronized void flatten(final boolean flattenNested) {
|
||||
// We use iterative traversal as recursion may exceed the stack size limit.
|
||||
final char[] chars = new char[length];
|
||||
int pos = length;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user