Reviewers: danno,
Description:
Fix caching of optimized code for OSR.
This makes sure we do not share optimized code across closures that were
optimized using OSR (for a particular OSR entry AST id) even if caching
of optimized code kicks in.
[email protected]
BUG=v8:2326
TEST=mjsunit/regress/regress-2326
Please review this at https://chromiumcodereview.appspot.com/10933088/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/compiler.cc
A + test/mjsunit/regress/regress-2326.js
Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index
e4a30dbbcedf92b5134755fd3dec41f100f49406..86374371e9b81de642cb528ad2b9a89e76c2c7f1
100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -746,8 +746,10 @@ static void InstallCodeCommon(CompilationInfo* info) {
static void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) {
Handle<Code> code = info->code();
- Handle<JSFunction> function = info->closure();
- if (FLAG_cache_optimized_code && code->kind() ==
Code::OPTIMIZED_FUNCTION) {
+ if (FLAG_cache_optimized_code &&
+ info->osr_ast_id().IsNone() &&
+ code->kind() == Code::OPTIMIZED_FUNCTION) {
+ Handle<JSFunction> function = info->closure();
Handle<SharedFunctionInfo> shared(function->shared());
Handle<FixedArray> literals(function->literals());
Handle<Context> native_context(function->context()->native_context());
@@ -758,7 +760,9 @@ static void
InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) {
static bool InstallCodeFromOptimizedCodeMap(CompilationInfo* info) {
- if (FLAG_cache_optimized_code && info->IsOptimizing()) {
+ if (FLAG_cache_optimized_code &&
+ info->osr_ast_id().IsNone() &&
+ info->IsOptimizing()) {
Handle<SharedFunctionInfo> shared = info->shared_info();
Handle<JSFunction> function = info->closure();
ASSERT(!function.is_null());
Index: test/mjsunit/regress/regress-2326.js
diff --git a/test/mjsunit/object-is.js
b/test/mjsunit/regress/regress-2326.js
similarity index 67%
copy from test/mjsunit/object-is.js
copy to test/mjsunit/regress/regress-2326.js
index
b9fdc8442068b4d7c50c06cb0eb8a134b8e9a7f3..d2edf2b1648b10a0800779af59d9bb98d673f05f
100644
--- a/test/mjsunit/object-is.js
+++ b/test/mjsunit/regress/regress-2326.js
@@ -25,23 +25,30 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test both the Harmony egal operator and it's function equivalent.
+// This tests that we do not share optimized code across closures that
+// were optimized using OSR (for a particular OSR entry AST id) even if
+// caching of optimized code kicks in.
-function TestEgal(expected, x, y) {
- // TODO(mstarzinger): Once we have the egal operator, we can test it
here.
- assertSame(expected, Object.is(x, y));
-}
-
-var test_set = [ {}, [], 1/0, -1/0, "s", 0, 0/-1, null, undefined ];
-print(test_set);
-for (var i = 0; i < test_set.length; i++) {
- for (var j = 0; j < test_set.length; j++) {
- if (i == j) {
- assertSame(test_set[i], test_set[j]);
- TestEgal(true, test_set[i], test_set[j]);
+function makeClosure() {
+ function f(mode, iterations) {
+ var accumulator = 0;
+ if (mode == 1) {
+ while (--iterations > 0) accumulator = Math.ceil(accumulator);
+ return 1;
} else {
- TestEgal(false, test_set[i], test_set[j]);
- TestEgal(false, test_set[j], test_set[i]);
+ while (--iterations > 0) accumulator = Math.floor(accumulator);
+ return 2;
}
}
+ return f;
}
+
+// Generate two closures sharing the same underlying function literal.
+var f1 = makeClosure();
+var f2 = makeClosure();
+
+// This function should be optimized via OSR in the first tight loop.
+assertSame(1, f1(1, 100000));
+
+// This function should be optimized via OSR in the second tight loop.
+assertSame(2, f2(2, 100000));
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev