Revision: 14175
Author: [email protected]
Date: Tue Apr 9 01:12:59 2013
Log: Fix slow path of JSON.stringifier when GC strikes.
FlatContent is not GC-safe.
[email protected]
BUG=
Review URL: https://chromiumcodereview.appspot.com/13782002
http://code.google.com/p/v8/source/detail?r=14175
Modified:
/branches/bleeding_edge/src/json-stringifier.h
/branches/bleeding_edge/test/mjsunit/regress/regress-json-stringify-gc.js
=======================================
--- /branches/bleeding_edge/src/json-stringifier.h Thu Mar 28 04:19:38 2013
+++ /branches/bleeding_edge/src/json-stringifier.h Tue Apr 9 01:12:59 2013
@@ -295,19 +295,30 @@
return stringifier.Stringify(object);
}
- FlattenString(object);
- String::FlatContent flat = object->GetFlatContent();
- if (flat.IsAscii()) {
+ object = FlattenGetString(object);
+ ASSERT(object->IsFlat());
+ if (object->IsOneByteRepresentation()) {
+ Handle<String> result =
+ isolate->factory()->NewRawOneByteString(worst_case_length);
+ AssertNoAllocation no_alloc;
+ const uint8_t* start = object->IsSeqOneByteString()
+ ? SeqOneByteString::cast(*object)->GetChars()
+ : ExternalAsciiString::cast(*object)->GetChars();
return StringifyString_<SeqOneByteString>(
isolate,
- flat.ToOneByteVector(),
- isolate->factory()->NewRawOneByteString(worst_case_length));
+ Vector<const uint8_t>(start, object->length()),
+ result);
} else {
- ASSERT(flat.IsTwoByte());
+ Handle<String> result =
+ isolate->factory()->NewRawTwoByteString(worst_case_length);
+ AssertNoAllocation no_alloc;
+ const uc16* start = object->IsSeqTwoByteString()
+ ? SeqTwoByteString::cast(*object)->GetChars()
+ : ExternalTwoByteString::cast(*object)->GetChars();
return StringifyString_<SeqTwoByteString>(
isolate,
- flat.ToUC16Vector(),
- isolate->factory()->NewRawTwoByteString(worst_case_length));
+ Vector<const uc16>(start, object->length()),
+ result);
}
}
=======================================
---
/branches/bleeding_edge/test/mjsunit/regress/regress-json-stringify-gc.js
Wed Dec 5 07:49:22 2012
+++
/branches/bleeding_edge/test/mjsunit/regress/regress-json-stringify-gc.js
Tue Apr 9 01:12:59 2013
@@ -39,3 +39,13 @@
json2 = JSON.stringify(a);
assertTrue(json1 == json2, "GC caused JSON.stringify to fail.");
+// Check that the slow path of JSON.stringify works correctly wrt GC.
+for (var i = 0; i < 100000; i++) {
+ var s = i.toString();
+ assertEquals('"' + s + '"', JSON.stringify(s, null, 0));
+}
+
+for (var i = 0; i < 100000; i++) {
+ var s = i.toString() + "\u2603";
+ assertEquals('"' + s + '"', JSON.stringify(s, null, 0));
+}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.