OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Review notes: | 5 // Review notes: |
6 // | 6 // |
7 // - The use of macros in these inline functions may seem superfluous | 7 // - The use of macros in these inline functions may seem superfluous |
8 // but it is absolutely needed to make sure gcc generates optimal | 8 // but it is absolutely needed to make sure gcc generates optimal |
9 // code. gcc is not happy when attempting to inline too deep. | 9 // code. gcc is not happy when attempting to inline too deep. |
10 // | 10 // |
(...skipping 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2000 | 2000 |
2001 | 2001 |
2002 int JSObject::GetHeaderSize(InstanceType type) { | 2002 int JSObject::GetHeaderSize(InstanceType type) { |
2003 // Check for the most common kind of JavaScript object before | 2003 // Check for the most common kind of JavaScript object before |
2004 // falling into the generic switch. This speeds up the internal | 2004 // falling into the generic switch. This speeds up the internal |
2005 // field operations considerably on average. | 2005 // field operations considerably on average. |
2006 if (type == JS_OBJECT_TYPE) return JSObject::kHeaderSize; | 2006 if (type == JS_OBJECT_TYPE) return JSObject::kHeaderSize; |
2007 switch (type) { | 2007 switch (type) { |
2008 case JS_API_OBJECT_TYPE: | 2008 case JS_API_OBJECT_TYPE: |
2009 case JS_SPECIAL_API_OBJECT_TYPE: | 2009 case JS_SPECIAL_API_OBJECT_TYPE: |
2010 case JS_WASM_TYPE: | |
2010 return JSObject::kHeaderSize; | 2011 return JSObject::kHeaderSize; |
2011 case JS_GENERATOR_OBJECT_TYPE: | 2012 case JS_GENERATOR_OBJECT_TYPE: |
2012 return JSGeneratorObject::kSize; | 2013 return JSGeneratorObject::kSize; |
2013 case JS_MODULE_TYPE: | 2014 case JS_MODULE_TYPE: |
2014 return JSModule::kSize; | 2015 return JSModule::kSize; |
2015 case JS_GLOBAL_PROXY_TYPE: | 2016 case JS_GLOBAL_PROXY_TYPE: |
2016 return JSGlobalProxy::kSize; | 2017 return JSGlobalProxy::kSize; |
2017 case JS_GLOBAL_OBJECT_TYPE: | 2018 case JS_GLOBAL_OBJECT_TYPE: |
2018 return JSGlobalObject::kSize; | 2019 return JSGlobalObject::kSize; |
2019 case JS_BOUND_FUNCTION_TYPE: | 2020 case JS_BOUND_FUNCTION_TYPE: |
(...skipping 1872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3892 void StringCharacterStream::VisitTwoByteString( | 3893 void StringCharacterStream::VisitTwoByteString( |
3893 const uint16_t* chars, int length) { | 3894 const uint16_t* chars, int length) { |
3894 is_one_byte_ = false; | 3895 is_one_byte_ = false; |
3895 buffer16_ = chars; | 3896 buffer16_ = chars; |
3896 end_ = reinterpret_cast<const uint8_t*>(chars + length); | 3897 end_ = reinterpret_cast<const uint8_t*>(chars + length); |
3897 } | 3898 } |
3898 | 3899 |
3899 | 3900 |
3900 int ByteArray::Size() { return RoundUp(length() + kHeaderSize, kPointerSize); } | 3901 int ByteArray::Size() { return RoundUp(length() + kHeaderSize, kPointerSize); } |
3901 | 3902 |
3903 void ByteArray::get(int index, byte* buffer, int length) { | |
titzer
2016/04/22 13:21:08
Let's move this out of line into the .cc file; it'
titzer
2016/04/22 13:21:08
This shouldn't be called "get", but more like "cop
Clemens Hammacher
2016/04/22 14:38:40
It's not so easy to move it out, since it uses the
| |
3904 DCHECK(index >= 0 && length >= 0 && index + length >= 0 && | |
3905 index + length <= this->length()); | |
3906 const byte* src_addr = FIELD_ADDR(this, kHeaderSize + index * kCharSize); | |
3907 memcpy(buffer, src_addr, length); | |
3908 } | |
3902 | 3909 |
3903 byte ByteArray::get(int index) { | 3910 byte ByteArray::get(int index) { |
3904 DCHECK(index >= 0 && index < this->length()); | 3911 DCHECK(index >= 0 && index < this->length()); |
3905 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); | 3912 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); |
3906 } | 3913 } |
3907 | 3914 |
3908 | 3915 |
3909 void ByteArray::set(int index, byte value) { | 3916 void ByteArray::set(int index, byte value) { |
3910 DCHECK(index >= 0 && index < this->length()); | 3917 DCHECK(index >= 0 && index < this->length()); |
3911 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, value); | 3918 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, value); |
3912 } | 3919 } |
3913 | 3920 |
3921 void ByteArray::set(int index, const byte* buffer, int length) { | |
titzer
2016/04/22 13:21:07
This shouldn't be called "set", but more like "cop
| |
3922 DCHECK(index >= 0 && length >= 0 && index + length >= 0 && | |
3923 index + length <= this->length()); | |
3924 byte* dst_addr = FIELD_ADDR(this, kHeaderSize + index * kCharSize); | |
3925 memcpy(dst_addr, buffer, length); | |
3926 } | |
3914 | 3927 |
3915 int ByteArray::get_int(int index) { | 3928 int ByteArray::get_int(int index) { |
3916 DCHECK(index >= 0 && (index * kIntSize) < this->length()); | 3929 DCHECK(index >= 0 && |
3930 (static_cast<uint64_t>(index) * kIntSize) < this->length()); | |
3917 return READ_INT_FIELD(this, kHeaderSize + index * kIntSize); | 3931 return READ_INT_FIELD(this, kHeaderSize + index * kIntSize); |
3918 } | 3932 } |
3919 | 3933 |
3934 void ByteArray::set_int(int index, int value) { | |
3935 DCHECK(index >= 0 && | |
3936 (static_cast<uint64_t>(index) * kIntSize) < this->length()); | |
3937 WRITE_INT_FIELD(this, kHeaderSize + index * kIntSize, value); | |
3938 } | |
3920 | 3939 |
3921 ByteArray* ByteArray::FromDataStartAddress(Address address) { | 3940 ByteArray* ByteArray::FromDataStartAddress(Address address) { |
3922 DCHECK_TAG_ALIGNED(address); | 3941 DCHECK_TAG_ALIGNED(address); |
3923 return reinterpret_cast<ByteArray*>(address - kHeaderSize + kHeapObjectTag); | 3942 return reinterpret_cast<ByteArray*>(address - kHeaderSize + kHeapObjectTag); |
3924 } | 3943 } |
3925 | 3944 |
3926 | 3945 |
3927 int ByteArray::ByteArraySize() { return SizeFor(this->length()); } | 3946 int ByteArray::ByteArraySize() { return SizeFor(this->length()); } |
3928 | 3947 |
3929 | 3948 |
(...skipping 3888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7818 #undef WRITE_INT64_FIELD | 7837 #undef WRITE_INT64_FIELD |
7819 #undef READ_BYTE_FIELD | 7838 #undef READ_BYTE_FIELD |
7820 #undef WRITE_BYTE_FIELD | 7839 #undef WRITE_BYTE_FIELD |
7821 #undef NOBARRIER_READ_BYTE_FIELD | 7840 #undef NOBARRIER_READ_BYTE_FIELD |
7822 #undef NOBARRIER_WRITE_BYTE_FIELD | 7841 #undef NOBARRIER_WRITE_BYTE_FIELD |
7823 | 7842 |
7824 } // namespace internal | 7843 } // namespace internal |
7825 } // namespace v8 | 7844 } // namespace v8 |
7826 | 7845 |
7827 #endif // V8_OBJECTS_INL_H_ | 7846 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |