Skip to content

Commit cd577d5

Browse files
committed
Upgrade V8 to 2.2.0.3
1 parent ae805f1 commit cd577d5

25 files changed

Lines changed: 257 additions & 731 deletions

deps/v8/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2010-03-29: Version 2.2.0
2+
3+
Fixed a few minor bugs.
4+
5+
Performance improvements for string operations.
6+
7+
18
2010-03-26: Version 2.1.10
29

310
Fixed scons build issues.

deps/v8/include/v8.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,12 +855,15 @@ class V8EXPORT String : public Primitive {
855855
* \param start The starting position within the string at which
856856
* copying begins.
857857
* \param length The number of bytes to copy from the string.
858-
* \return The number of characters copied to the buffer
858+
* \param nchars The number of characters written.
859+
* \return The number of bytes copied to the buffer
859860
* excluding the NULL terminator.
860861
*/
861862
int Write(uint16_t* buffer, int start = 0, int length = -1) const; // UTF-16
862863
int WriteAscii(char* buffer, int start = 0, int length = -1) const; // ASCII
863-
int WriteUtf8(char* buffer, int length = -1) const; // UTF-8
864+
int WriteUtf8(char* buffer,
865+
int length = -1,
866+
int* nchars = NULL) const; // UTF-8
864867

865868
/**
866869
* A zero length string.

deps/v8/src/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ SOURCES = {
102102
stub-cache.cc
103103
token.cc
104104
top.cc
105+
type-info.cc
105106
unicode.cc
106107
utils.cc
107108
v8-counters.cc

deps/v8/src/api.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,7 @@ int String::Utf8Length() const {
26392639
}
26402640

26412641

2642-
int String::WriteUtf8(char* buffer, int capacity) const {
2642+
int String::WriteUtf8(char* buffer, int capacity, int *ncharsRef) const {
26432643
if (IsDeadCheck("v8::String::WriteUtf8()")) return 0;
26442644
LOG_API("String::WriteUtf8");
26452645
ENTER_V8;
@@ -2653,10 +2653,12 @@ int String::WriteUtf8(char* buffer, int capacity) const {
26532653
int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1);
26542654
int i;
26552655
int pos = 0;
2656+
int nchars = 0;
26562657
for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) {
26572658
i::uc32 c = write_input_buffer.GetNext();
26582659
int written = unibrow::Utf8::Encode(buffer + pos, c);
26592660
pos += written;
2661+
nchars++;
26602662
}
26612663
if (i < len) {
26622664
// For the last characters we need to check the length for each one
@@ -2670,12 +2672,14 @@ int String::WriteUtf8(char* buffer, int capacity) const {
26702672
for (int j = 0; j < written; j++)
26712673
buffer[pos + j] = intermediate[j];
26722674
pos += written;
2675+
nchars++;
26732676
} else {
26742677
// We've reached the end of the buffer
26752678
break;
26762679
}
26772680
}
26782681
}
2682+
if (ncharsRef) *ncharsRef = nchars;
26792683
if (i == len && (capacity == -1 || pos < capacity))
26802684
buffer[pos++] = '\0';
26812685
return pos;

deps/v8/src/builtins.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,9 @@ BUILTIN(ArrayShift) {
495495
}
496496

497497
if (Heap::new_space()->Contains(elms)) {
498-
array->set_elements(LeftTrimFixedArray(elms));
498+
// As elms still in the same space they used to be (new space),
499+
// there is no need to update remembered set.
500+
array->set_elements(LeftTrimFixedArray(elms), SKIP_WRITE_BARRIER);
499501
} else {
500502
// Shift the elements.
501503
AssertNoAllocation no_gc;

deps/v8/src/date.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,16 @@ function EquivalentTime(t) {
121121
}
122122

123123

124-
// Because computing the DST offset is a pretty expensive operation
125-
// we keep a cache of last computed offset along with a time interval
124+
// local_time_offset is initialized when the DST_offset_cache is missed.
125+
// It must not be used until after a call to DaylightSavingsOffset().
126+
// In this way, only one check, for a DST cache miss, is needed.
127+
var local_time_offset;
128+
129+
130+
// Because computing the DST offset is an expensive operation,
131+
// we keep a cache of the last computed DST offset along with a time interval
126132
// where we know the cache is valid.
133+
// When the cache is valid, local_time_offset is also valid.
127134
var DST_offset_cache = {
128135
// Cached DST offset.
129136
offset: 0,
@@ -149,6 +156,11 @@ function DaylightSavingsOffset(t) {
149156
// If the time fits in the cached interval, return the cached offset.
150157
if (t <= end) return cache.offset;
151158

159+
// If the cache misses, the local_time_offset may not be initialized.
160+
if (IS_UNDEFINED(local_time_offset)) {
161+
local_time_offset = %DateLocalTimeOffset();
162+
}
163+
152164
// Compute a possible new interval end.
153165
var new_end = end + cache.increment;
154166

@@ -185,6 +197,10 @@ function DaylightSavingsOffset(t) {
185197
}
186198
}
187199

200+
// If the cache misses, the local_time_offset may not be initialized.
201+
if (IS_UNDEFINED(local_time_offset)) {
202+
local_time_offset = %DateLocalTimeOffset();
203+
}
188204
// Compute the DST offset for the time and shrink the cache interval
189205
// to only contain the time. This allows fast repeated DST offset
190206
// computations for the same time.
@@ -215,11 +231,11 @@ function WeekDay(time) {
215231
return Modulo(DAY(time) + 4, 7);
216232
}
217233

218-
var local_time_offset = %DateLocalTimeOffset();
219234

220235
function LocalTime(time) {
221236
if (NUMBER_IS_NAN(time)) return time;
222-
return time + local_time_offset + DaylightSavingsOffset(time);
237+
// DaylightSavingsOffset called before local_time_offset used.
238+
return time + DaylightSavingsOffset(time) + local_time_offset;
223239
}
224240

225241
function LocalTimeNoCheck(time) {
@@ -228,6 +244,8 @@ function LocalTimeNoCheck(time) {
228244
}
229245

230246
// Inline the DST offset cache checks for speed.
247+
// The cache is hit, or DaylightSavingsOffset is called,
248+
// before local_time_offset is used.
231249
var cache = DST_offset_cache;
232250
if (cache.start <= time && time <= cache.end) {
233251
var dst_offset = cache.offset;
@@ -240,6 +258,11 @@ function LocalTimeNoCheck(time) {
240258

241259
function UTC(time) {
242260
if (NUMBER_IS_NAN(time)) return time;
261+
// local_time_offset is needed before the call to DaylightSavingsOffset,
262+
// so it may be uninitialized.
263+
if (IS_UNDEFINED(local_time_offset)) {
264+
local_time_offset = %DateLocalTimeOffset();
265+
}
243266
var tmp = time - local_time_offset;
244267
return tmp - DaylightSavingsOffset(tmp);
245268
}
@@ -566,7 +589,7 @@ function TimeString(time) {
566589

567590
function LocalTimezoneString(time) {
568591
var timezoneOffset =
569-
(local_time_offset + DaylightSavingsOffset(time)) / msPerMinute;
592+
(DaylightSavingsOffset(time) + local_time_offset) / msPerMinute;
570593
var sign = (timezoneOffset >= 0) ? 1 : -1;
571594
var hours = FLOOR((sign * timezoneOffset)/60);
572595
var min = FLOOR((sign * timezoneOffset)%60);

deps/v8/src/frame-element.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#ifndef V8_FRAME_ELEMENT_H_
2929
#define V8_FRAME_ELEMENT_H_
3030

31-
#include "type-info-inl.h"
31+
#include "type-info.h"
3232
#include "macro-assembler.h"
3333
#include "zone.h"
3434

deps/v8/src/heap.cc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,8 +1961,9 @@ Object* Heap::AllocateConsString(String* first, String* second) {
19611961
return MakeOrFindTwoCharacterString(c1, c2);
19621962
}
19631963

1964-
bool is_ascii = first->IsAsciiRepresentation()
1965-
&& second->IsAsciiRepresentation();
1964+
bool first_is_ascii = first->IsAsciiRepresentation();
1965+
bool second_is_ascii = second->IsAsciiRepresentation();
1966+
bool is_ascii = first_is_ascii && second_is_ascii;
19661967

19671968
// Make sure that an out of memory exception is thrown if the length
19681969
// of the new cons string is too large.
@@ -1997,6 +1998,25 @@ Object* Heap::AllocateConsString(String* first, String* second) {
19971998
for (int i = 0; i < second_length; i++) *dest++ = src[i];
19981999
return result;
19992000
} else {
2001+
// For short external two-byte strings we check whether they can
2002+
// be represented using ascii.
2003+
if (!first_is_ascii) {
2004+
first_is_ascii = first->IsExternalTwoByteStringWithAsciiChars();
2005+
}
2006+
if (first_is_ascii && !second_is_ascii) {
2007+
second_is_ascii = second->IsExternalTwoByteStringWithAsciiChars();
2008+
}
2009+
if (first_is_ascii && second_is_ascii) {
2010+
Object* result = AllocateRawAsciiString(length);
2011+
if (result->IsFailure()) return result;
2012+
// Copy the characters into the new object.
2013+
char* dest = SeqAsciiString::cast(result)->GetChars();
2014+
String::WriteToFlat(first, dest, 0, first_length);
2015+
String::WriteToFlat(second, dest + first_length, 0, second_length);
2016+
Counters::string_add_runtime_ext_to_ascii.Increment();
2017+
return result;
2018+
}
2019+
20002020
Object* result = AllocateRawTwoByteString(length);
20012021
if (result->IsFailure()) return result;
20022022
// Copy the characters into the new object.

deps/v8/src/objects-inl.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,16 @@ bool String::IsTwoByteRepresentation() {
255255
}
256256

257257

258+
bool String::IsExternalTwoByteStringWithAsciiChars() {
259+
if (!IsExternalTwoByteString()) return false;
260+
const uc16* data = ExternalTwoByteString::cast(this)->resource()->data();
261+
for (int i = 0, len = length(); i < len; i++) {
262+
if (data[i] > kMaxAsciiCharCode) return false;
263+
}
264+
return true;
265+
}
266+
267+
258268
bool StringShape::IsCons() {
259269
return (type_ & kStringRepresentationMask) == kConsStringTag;
260270
}
@@ -732,7 +742,8 @@ Object* Object::GetProperty(String* key, PropertyAttributes* attributes) {
732742
} else { \
733743
ASSERT(mode == SKIP_WRITE_BARRIER); \
734744
ASSERT(Heap::InNewSpace(object) || \
735-
!Heap::InNewSpace(READ_FIELD(object, offset))); \
745+
!Heap::InNewSpace(READ_FIELD(object, offset)) || \
746+
Page::IsRSetSet(object->address(), offset)); \
736747
}
737748

738749
#define READ_DOUBLE_FIELD(p, offset) \

deps/v8/src/objects.cc

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4660,13 +4660,38 @@ bool String::IsEqualTo(Vector<const char> str) {
46604660
}
46614661

46624662

4663+
template <typename schar>
4664+
static inline uint32_t HashSequentialString(const schar* chars, int length) {
4665+
StringHasher hasher(length);
4666+
if (!hasher.has_trivial_hash()) {
4667+
int i;
4668+
for (i = 0; hasher.is_array_index() && (i < length); i++) {
4669+
hasher.AddCharacter(chars[i]);
4670+
}
4671+
for (; i < length; i++) {
4672+
hasher.AddCharacterNoIndex(chars[i]);
4673+
}
4674+
}
4675+
return hasher.GetHashField();
4676+
}
4677+
4678+
46634679
uint32_t String::ComputeAndSetHash() {
46644680
// Should only be called if hash code has not yet been computed.
46654681
ASSERT(!(hash_field() & kHashComputedMask));
46664682

4683+
const int len = length();
4684+
46674685
// Compute the hash code.
4668-
StringInputBuffer buffer(this);
4669-
uint32_t field = ComputeHashField(&buffer, length());
4686+
uint32_t field = 0;
4687+
if (StringShape(this).IsSequentialAscii()) {
4688+
field = HashSequentialString(SeqAsciiString::cast(this)->GetChars(), len);
4689+
} else if (StringShape(this).IsSequentialTwoByte()) {
4690+
field = HashSequentialString(SeqTwoByteString::cast(this)->GetChars(), len);
4691+
} else {
4692+
StringInputBuffer buffer(this);
4693+
field = ComputeHashField(&buffer, len);
4694+
}
46704695

46714696
// Store the hash code in the object.
46724697
set_hash_field(field);

0 commit comments

Comments
 (0)