Skip to content

Commit bd353dc

Browse files
author
dslomov@chromium.org
committed
Inline internal getters for typed arrays & friends.
R=hpayer@chromium.org, yangguo@chromium.org Committed: https://code.google.com/p/v8/source/detail?r=20330 Review URL: https://codereview.chromium.org/212603014 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20338 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
1 parent feeccf0 commit bd353dc

9 files changed

Lines changed: 148 additions & 99 deletions

File tree

src/arraybuffer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function ArrayBufferGetByteLength() {
4545
throw MakeTypeError('incompatible_method_receiver',
4646
['ArrayBuffer.prototype.byteLength', this]);
4747
}
48-
return %ArrayBufferGetByteLength(this);
48+
return %_ArrayBufferGetByteLength(this);
4949
}
5050

5151
// ES6 Draft 15.13.5.5.3
@@ -60,7 +60,7 @@ function ArrayBufferSlice(start, end) {
6060
end = TO_INTEGER(end);
6161
}
6262
var first;
63-
var byte_length = %ArrayBufferGetByteLength(this);
63+
var byte_length = %_ArrayBufferGetByteLength(this);
6464
if (relativeStart < 0) {
6565
first = MathMax(byte_length + relativeStart, 0);
6666
} else {

src/hydrogen-instructions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6025,6 +6025,11 @@ class HObjectAccess V8_FINAL {
60256025
JSArrayBuffer::kBackingStoreOffset, Representation::External());
60266026
}
60276027

6028+
static HObjectAccess ForJSArrayBufferByteLength() {
6029+
return HObjectAccess::ForObservableJSObjectOffset(
6030+
JSArrayBuffer::kByteLengthOffset, Representation::Tagged());
6031+
}
6032+
60286033
static HObjectAccess ForExternalArrayExternalPointer() {
60296034
return HObjectAccess::ForObservableJSObjectOffset(
60306035
ExternalArray::kExternalPointerOffset, Representation::External());

src/hydrogen.cc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8730,6 +8730,58 @@ void HOptimizedGraphBuilder::GenerateTypedArrayMaxSizeInHeap(
87308730
}
87318731

87328732

8733+
void HOptimizedGraphBuilder::GenerateArrayBufferGetByteLength(
8734+
CallRuntime* expr) {
8735+
ASSERT(expr->arguments()->length() == 1);
8736+
CHECK_ALIVE(VisitForValue(expr->arguments()->at(0)));
8737+
HValue* buffer = Pop();
8738+
HInstruction* result = New<HLoadNamedField>(
8739+
buffer,
8740+
static_cast<HValue*>(NULL),
8741+
HObjectAccess::ForJSArrayBufferByteLength());
8742+
return ast_context()->ReturnInstruction(result, expr->id());
8743+
}
8744+
8745+
8746+
void HOptimizedGraphBuilder::GenerateArrayBufferViewGetByteLength(
8747+
CallRuntime* expr) {
8748+
ASSERT(expr->arguments()->length() == 1);
8749+
CHECK_ALIVE(VisitForValue(expr->arguments()->at(0)));
8750+
HValue* buffer = Pop();
8751+
HInstruction* result = New<HLoadNamedField>(
8752+
buffer,
8753+
static_cast<HValue*>(NULL),
8754+
HObjectAccess::ForJSArrayBufferViewByteLength());
8755+
return ast_context()->ReturnInstruction(result, expr->id());
8756+
}
8757+
8758+
8759+
void HOptimizedGraphBuilder::GenerateArrayBufferViewGetByteOffset(
8760+
CallRuntime* expr) {
8761+
ASSERT(expr->arguments()->length() == 1);
8762+
CHECK_ALIVE(VisitForValue(expr->arguments()->at(0)));
8763+
HValue* buffer = Pop();
8764+
HInstruction* result = New<HLoadNamedField>(
8765+
buffer,
8766+
static_cast<HValue*>(NULL),
8767+
HObjectAccess::ForJSArrayBufferViewByteOffset());
8768+
return ast_context()->ReturnInstruction(result, expr->id());
8769+
}
8770+
8771+
8772+
void HOptimizedGraphBuilder::GenerateTypedArrayGetLength(
8773+
CallRuntime* expr) {
8774+
ASSERT(expr->arguments()->length() == 1);
8775+
CHECK_ALIVE(VisitForValue(expr->arguments()->at(0)));
8776+
HValue* buffer = Pop();
8777+
HInstruction* result = New<HLoadNamedField>(
8778+
buffer,
8779+
static_cast<HValue*>(NULL),
8780+
HObjectAccess::ForJSTypedArrayLength());
8781+
return ast_context()->ReturnInstruction(result, expr->id());
8782+
}
8783+
8784+
87338785
void HOptimizedGraphBuilder::VisitCallRuntime(CallRuntime* expr) {
87348786
ASSERT(!HasStackOverflow());
87358787
ASSERT(current_block() != NULL);

src/runtime.cc

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,33 +1132,26 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitializeFromArrayLike) {
11321132
}
11331133

11341134

1135-
#define TYPED_ARRAY_GETTER(getter, accessor) \
1136-
RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayGet##getter) { \
1135+
#define BUFFER_VIEW_GETTER(Type, getter, accessor) \
1136+
RUNTIME_FUNCTION(MaybeObject*, Runtime_##Type##Get##getter) { \
11371137
HandleScope scope(isolate); \
11381138
ASSERT(args.length() == 1); \
1139-
CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0); \
1140-
if (!holder->IsJSTypedArray()) \
1141-
return isolate->Throw(*isolate->factory()->NewTypeError( \
1142-
"not_typed_array", HandleVector<Object>(NULL, 0))); \
1143-
Handle<JSTypedArray> typed_array(JSTypedArray::cast(*holder)); \
1144-
return typed_array->accessor(); \
1139+
CONVERT_ARG_HANDLE_CHECKED(JS##Type, holder, 0); \
1140+
return holder->accessor(); \
11451141
}
11461142

1147-
TYPED_ARRAY_GETTER(ByteLength, byte_length)
1148-
TYPED_ARRAY_GETTER(ByteOffset, byte_offset)
1149-
TYPED_ARRAY_GETTER(Length, length)
1143+
BUFFER_VIEW_GETTER(ArrayBufferView, ByteLength, byte_length)
1144+
BUFFER_VIEW_GETTER(ArrayBufferView, ByteOffset, byte_offset)
1145+
BUFFER_VIEW_GETTER(TypedArray, Length, length)
1146+
BUFFER_VIEW_GETTER(DataView, Buffer, buffer)
11501147

1151-
#undef TYPED_ARRAY_GETTER
1148+
#undef BUFFER_VIEW_GETTER
11521149

11531150
RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayGetBuffer) {
11541151
HandleScope scope(isolate);
11551152
ASSERT(args.length() == 1);
1156-
CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0);
1157-
if (!holder->IsJSTypedArray())
1158-
return isolate->Throw(*isolate->factory()->NewTypeError(
1159-
"not_typed_array", HandleVector<Object>(NULL, 0)));
1160-
Handle<JSTypedArray> typed_array(JSTypedArray::cast(*holder));
1161-
return *typed_array->GetBuffer();
1153+
CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0);
1154+
return *holder->GetBuffer();
11621155
}
11631156

11641157

@@ -1273,30 +1266,6 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewInitialize) {
12731266
}
12741267

12751268

1276-
RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewGetBuffer) {
1277-
HandleScope scope(isolate);
1278-
ASSERT(args.length() == 1);
1279-
CONVERT_ARG_HANDLE_CHECKED(JSDataView, data_view, 0);
1280-
return data_view->buffer();
1281-
}
1282-
1283-
1284-
RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewGetByteOffset) {
1285-
HandleScope scope(isolate);
1286-
ASSERT(args.length() == 1);
1287-
CONVERT_ARG_HANDLE_CHECKED(JSDataView, data_view, 0);
1288-
return data_view->byte_offset();
1289-
}
1290-
1291-
1292-
RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewGetByteLength) {
1293-
HandleScope scope(isolate);
1294-
ASSERT(args.length() == 1);
1295-
CONVERT_ARG_HANDLE_CHECKED(JSDataView, data_view, 0);
1296-
return data_view->byte_length();
1297-
}
1298-
1299-
13001269
inline static bool NeedToFlipBytes(bool is_little_endian) {
13011270
#ifdef V8_TARGET_LITTLE_ENDIAN
13021271
return !is_little_endian;

src/runtime.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,15 @@ namespace internal {
328328
\
329329
/* Harmony typed arrays */ \
330330
F(ArrayBufferInitialize, 2, 1)\
331-
F(ArrayBufferGetByteLength, 1, 1)\
332331
F(ArrayBufferSliceImpl, 3, 1) \
333332
F(ArrayBufferIsView, 1, 1) \
334333
F(ArrayBufferNeuter, 1, 1) \
335334
\
336335
F(TypedArrayInitializeFromArrayLike, 4, 1) \
337336
F(TypedArrayGetBuffer, 1, 1) \
338-
F(TypedArrayGetByteLength, 1, 1) \
339-
F(TypedArrayGetByteOffset, 1, 1) \
340-
F(TypedArrayGetLength, 1, 1) \
341337
F(TypedArraySetFastCases, 3, 1) \
342338
\
343339
F(DataViewGetBuffer, 1, 1) \
344-
F(DataViewGetByteLength, 1, 1) \
345-
F(DataViewGetByteOffset, 1, 1) \
346340
F(DataViewGetInt8, 3, 1) \
347341
F(DataViewGetUint8, 3, 1) \
348342
F(DataViewGetInt16, 3, 1) \
@@ -690,13 +684,17 @@ namespace internal {
690684
// Entries have the form F(name, number of arguments, number of return values).
691685
#define INLINE_OPTIMIZED_FUNCTION_LIST(F) \
692686
/* Typed Arrays */ \
693-
F(ConstructDouble, 2, 1) \
694687
F(TypedArrayInitialize, 5, 1) \
695688
F(DataViewInitialize, 4, 1) \
696689
F(MaxSmi, 0, 1) \
697690
F(TypedArrayMaxSizeInHeap, 0, 1) \
698-
\
691+
F(ArrayBufferViewGetByteLength, 1, 1) \
692+
F(ArrayBufferViewGetByteOffset, 1, 1) \
693+
F(TypedArrayGetLength, 1, 1) \
694+
/* ArrayBuffer */ \
695+
F(ArrayBufferGetByteLength, 1, 1) \
699696
/* Maths */ \
697+
F(ConstructDouble, 2, 1) \
700698
F(DoubleHi, 1, 1) \
701699
F(DoubleLo, 1, 1) \
702700
F(MathSqrt, 1, 1) \

src/spaces.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ intptr_t PagedSpace::SizeOfFirstPage() {
10511051
int size = 0;
10521052
switch (identity()) {
10531053
case OLD_POINTER_SPACE:
1054-
size = 72 * kPointerSize * KB;
1054+
size = 96 * kPointerSize * KB;
10551055
break;
10561056
case OLD_DATA_SPACE:
10571057
size = 192 * KB;

0 commit comments

Comments
 (0)