Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef V8_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
| 6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 // - Module | 161 // - Module |
| 162 // - WeakCell | 162 // - WeakCell |
| 163 // | 163 // |
| 164 // Formats of Object*: | 164 // Formats of Object*: |
| 165 // Smi: [31 bit signed int] 0 | 165 // Smi: [31 bit signed int] 0 |
| 166 // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 | 166 // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 |
| 167 | 167 |
| 168 namespace v8 { | 168 namespace v8 { |
| 169 namespace internal { | 169 namespace internal { |
| 170 | 170 |
| 171 struct InliningPosition; | |
| 172 | |
| 171 enum KeyedAccessStoreMode { | 173 enum KeyedAccessStoreMode { |
| 172 STANDARD_STORE, | 174 STANDARD_STORE, |
| 173 STORE_TRANSITION_TO_OBJECT, | 175 STORE_TRANSITION_TO_OBJECT, |
| 174 STORE_TRANSITION_TO_DOUBLE, | 176 STORE_TRANSITION_TO_DOUBLE, |
| 175 STORE_AND_GROW_NO_TRANSITION, | 177 STORE_AND_GROW_NO_TRANSITION, |
| 176 STORE_AND_GROW_TRANSITION_TO_OBJECT, | 178 STORE_AND_GROW_TRANSITION_TO_OBJECT, |
| 177 STORE_AND_GROW_TRANSITION_TO_DOUBLE, | 179 STORE_AND_GROW_TRANSITION_TO_DOUBLE, |
| 178 STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS, | 180 STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS, |
| 179 STORE_NO_TRANSITION_HANDLE_COW | 181 STORE_NO_TRANSITION_HANDLE_COW |
| 180 }; | 182 }; |
| (...skipping 4772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4953 | 4955 |
| 4954 // Maximal memory consumption for a single ByteArray. | 4956 // Maximal memory consumption for a single ByteArray. |
| 4955 static const int kMaxSize = 512 * MB; | 4957 static const int kMaxSize = 512 * MB; |
| 4956 // Maximal length of a single ByteArray. | 4958 // Maximal length of a single ByteArray. |
| 4957 static const int kMaxLength = kMaxSize - kHeaderSize; | 4959 static const int kMaxLength = kMaxSize - kHeaderSize; |
| 4958 | 4960 |
| 4959 private: | 4961 private: |
| 4960 DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); | 4962 DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 4961 }; | 4963 }; |
| 4962 | 4964 |
| 4965 // Wrapper class for ByteArray which can store arbitrary C++ classes, as long | |
| 4966 // as they can be copied with memcpy. | |
| 4967 template <class T> | |
| 4968 class PodArray : public ByteArray { | |
| 4969 public: | |
| 4970 static Handle<PodArray<T>> New(Isolate* isolate, int length, | |
| 4971 PretenureFlag pretenure = NOT_TENURED); | |
| 4972 void copy_out(int index, T* result) { | |
| 4973 ByteArray::copy_out(index * sizeof(T), reinterpret_cast<byte*>(result), | |
| 4974 sizeof(T)); | |
| 4975 } | |
| 4976 T get(int index) { | |
| 4977 T result; | |
| 4978 copy_out(index, &result); | |
| 4979 return result; | |
| 4980 } | |
| 4981 void set(int index, const T& value) { | |
| 4982 copy_in(index * sizeof(T), reinterpret_cast<const byte*>(&value), | |
| 4983 sizeof(T)); | |
| 4984 } | |
| 4985 int length() { return ByteArray::length() / sizeof(T); } | |
| 4986 DECLARE_CAST(PodArray<T>); | |
| 4987 | |
| 4988 private: | |
| 4989 DISALLOW_IMPLICIT_CONSTRUCTORS(PodArray<T>); | |
| 4990 }; | |
| 4963 | 4991 |
| 4964 // BytecodeArray represents a sequence of interpreter bytecodes. | 4992 // BytecodeArray represents a sequence of interpreter bytecodes. |
| 4965 class BytecodeArray : public FixedArrayBase { | 4993 class BytecodeArray : public FixedArrayBase { |
| 4966 public: | 4994 public: |
| 4967 static int SizeFor(int length) { | 4995 static int SizeFor(int length) { |
| 4968 return OBJECT_POINTER_ALIGN(kHeaderSize + length); | 4996 return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
| 4969 } | 4997 } |
| 4970 | 4998 |
| 4971 // Setter and getter | 4999 // Setter and getter |
| 4972 inline byte get(int index); | 5000 inline byte get(int index); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5185 elementType scalar); \ | 5213 elementType scalar); \ |
| 5186 static inline elementType defaultValue(); \ | 5214 static inline elementType defaultValue(); \ |
| 5187 }; \ | 5215 }; \ |
| 5188 \ | 5216 \ |
| 5189 typedef FixedTypedArray<Type##ArrayTraits> Fixed##Type##Array; | 5217 typedef FixedTypedArray<Type##ArrayTraits> Fixed##Type##Array; |
| 5190 | 5218 |
| 5191 TYPED_ARRAYS(FIXED_TYPED_ARRAY_TRAITS) | 5219 TYPED_ARRAYS(FIXED_TYPED_ARRAY_TRAITS) |
| 5192 | 5220 |
| 5193 #undef FIXED_TYPED_ARRAY_TRAITS | 5221 #undef FIXED_TYPED_ARRAY_TRAITS |
| 5194 | 5222 |
| 5195 | |
| 5196 // DeoptimizationInputData is a fixed array used to hold the deoptimization | 5223 // DeoptimizationInputData is a fixed array used to hold the deoptimization |
| 5197 // data for code generated by the Hydrogen/Lithium compiler. It also | 5224 // data for code generated by the Hydrogen/Lithium compiler. It also |
| 5198 // contains information about functions that were inlined. If N different | 5225 // contains information about functions that were inlined. If N different |
| 5199 // functions were inlined then first N elements of the literal array will | 5226 // functions were inlined then first N elements of the literal array will |
| 5200 // contain these functions. | 5227 // contain these functions. |
| 5201 // | 5228 // |
| 5202 // It can be empty. | 5229 // It can be empty. |
| 5203 class DeoptimizationInputData: public FixedArray { | 5230 class DeoptimizationInputData: public FixedArray { |
| 5204 public: | 5231 public: |
| 5205 // Layout description. Indices in the array. | 5232 // Layout description. Indices in the array. |
| 5206 static const int kTranslationByteArrayIndex = 0; | 5233 static const int kTranslationByteArrayIndex = 0; |
| 5207 static const int kInlinedFunctionCountIndex = 1; | 5234 static const int kInlinedFunctionCountIndex = 1; |
| 5208 static const int kLiteralArrayIndex = 2; | 5235 static const int kLiteralArrayIndex = 2; |
| 5209 static const int kOsrAstIdIndex = 3; | 5236 static const int kOsrAstIdIndex = 3; |
| 5210 static const int kOsrPcOffsetIndex = 4; | 5237 static const int kOsrPcOffsetIndex = 4; |
| 5211 static const int kOptimizationIdIndex = 5; | 5238 static const int kOptimizationIdIndex = 5; |
| 5212 static const int kSharedFunctionInfoIndex = 6; | 5239 static const int kSharedFunctionInfoIndex = 6; |
| 5213 static const int kWeakCellCacheIndex = 7; | 5240 static const int kWeakCellCacheIndex = 7; |
| 5214 static const int kFirstDeoptEntryIndex = 8; | 5241 static const int kInliningPositionsIndex = 8; |
| 5242 static const int kFirstDeoptEntryIndex = 9; | |
| 5215 | 5243 |
| 5216 // Offsets of deopt entry elements relative to the start of the entry. | 5244 // Offsets of deopt entry elements relative to the start of the entry. |
| 5217 static const int kAstIdRawOffset = 0; | 5245 static const int kAstIdRawOffset = 0; |
| 5218 static const int kTranslationIndexOffset = 1; | 5246 static const int kTranslationIndexOffset = 1; |
| 5219 static const int kArgumentsStackHeightOffset = 2; | 5247 static const int kArgumentsStackHeightOffset = 2; |
| 5220 static const int kPcOffset = 3; | 5248 static const int kPcOffset = 3; |
| 5221 static const int kDeoptEntrySize = 4; | 5249 static const int kDeoptEntrySize = 4; |
| 5222 | 5250 |
| 5223 // Simple element accessors. | 5251 // Simple element accessors. |
| 5224 #define DECLARE_ELEMENT_ACCESSORS(name, type) \ | 5252 #define DECLARE_ELEMENT_ACCESSORS(name, type) \ |
| 5225 inline type* name(); \ | 5253 inline type* name(); \ |
| 5226 inline void Set##name(type* value); | 5254 inline void Set##name(type* value); |
| 5227 | 5255 |
| 5228 DECLARE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray) | 5256 DECLARE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray) |
| 5229 DECLARE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi) | 5257 DECLARE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi) |
| 5230 DECLARE_ELEMENT_ACCESSORS(LiteralArray, FixedArray) | 5258 DECLARE_ELEMENT_ACCESSORS(LiteralArray, FixedArray) |
| 5231 DECLARE_ELEMENT_ACCESSORS(OsrAstId, Smi) | 5259 DECLARE_ELEMENT_ACCESSORS(OsrAstId, Smi) |
| 5232 DECLARE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) | 5260 DECLARE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) |
| 5233 DECLARE_ELEMENT_ACCESSORS(OptimizationId, Smi) | 5261 DECLARE_ELEMENT_ACCESSORS(OptimizationId, Smi) |
| 5234 DECLARE_ELEMENT_ACCESSORS(SharedFunctionInfo, Object) | 5262 DECLARE_ELEMENT_ACCESSORS(SharedFunctionInfo, Object) |
| 5235 DECLARE_ELEMENT_ACCESSORS(WeakCellCache, Object) | 5263 DECLARE_ELEMENT_ACCESSORS(WeakCellCache, Object) |
| 5264 DECLARE_ELEMENT_ACCESSORS(InliningPositions, PodArray<InliningPosition>) | |
| 5236 | 5265 |
| 5237 #undef DECLARE_ELEMENT_ACCESSORS | 5266 #undef DECLARE_ELEMENT_ACCESSORS |
| 5238 | 5267 |
| 5239 // Accessors for elements of the ith deoptimization entry. | 5268 // Accessors for elements of the ith deoptimization entry. |
| 5240 #define DECLARE_ENTRY_ACCESSORS(name, type) \ | 5269 #define DECLARE_ENTRY_ACCESSORS(name, type) \ |
| 5241 inline type* name(int i); \ | 5270 inline type* name(int i); \ |
| 5242 inline void Set##name(int i, type* value); | 5271 inline void Set##name(int i, type* value); |
| 5243 | 5272 |
| 5244 DECLARE_ENTRY_ACCESSORS(AstIdRaw, Smi) | 5273 DECLARE_ENTRY_ACCESSORS(AstIdRaw, Smi) |
| 5245 DECLARE_ENTRY_ACCESSORS(TranslationIndex, Smi) | 5274 DECLARE_ENTRY_ACCESSORS(TranslationIndex, Smi) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 5267 | 5296 |
| 5268 private: | 5297 private: |
| 5269 static int IndexForEntry(int i) { | 5298 static int IndexForEntry(int i) { |
| 5270 return kFirstDeoptEntryIndex + (i * kDeoptEntrySize); | 5299 return kFirstDeoptEntryIndex + (i * kDeoptEntrySize); |
| 5271 } | 5300 } |
| 5272 | 5301 |
| 5273 | 5302 |
| 5274 static int LengthFor(int entry_count) { return IndexForEntry(entry_count); } | 5303 static int LengthFor(int entry_count) { return IndexForEntry(entry_count); } |
| 5275 }; | 5304 }; |
| 5276 | 5305 |
| 5277 | |
| 5278 // DeoptimizationOutputData is a fixed array used to hold the deoptimization | 5306 // DeoptimizationOutputData is a fixed array used to hold the deoptimization |
| 5279 // data for code generated by the full compiler. | 5307 // data for code generated by the full compiler. |
| 5280 // The format of the these objects is | 5308 // The format of the these objects is |
| 5281 // [i * 2]: Ast ID for ith deoptimization. | 5309 // [i * 2]: Ast ID for ith deoptimization. |
| 5282 // [i * 2 + 1]: PC and state of ith deoptimization | 5310 // [i * 2 + 1]: PC and state of ith deoptimization |
| 5283 class DeoptimizationOutputData: public FixedArray { | 5311 class DeoptimizationOutputData: public FixedArray { |
| 5284 public: | 5312 public: |
| 5285 inline int DeoptPoints(); | 5313 inline int DeoptPoints(); |
| 5286 | 5314 |
| 5287 inline BailoutId AstId(int index); | 5315 inline BailoutId AstId(int index); |
| (...skipping 1865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7153 // Set eval origin for stack trace formatting. | 7181 // Set eval origin for stack trace formatting. |
| 7154 static void SetEvalOrigin(Handle<Script> script, | 7182 static void SetEvalOrigin(Handle<Script> script, |
| 7155 Handle<SharedFunctionInfo> outer, | 7183 Handle<SharedFunctionInfo> outer, |
| 7156 int eval_position); | 7184 int eval_position); |
| 7157 // Retrieve source position from where eval was called. | 7185 // Retrieve source position from where eval was called. |
| 7158 int GetEvalPosition(); | 7186 int GetEvalPosition(); |
| 7159 | 7187 |
| 7160 // Init line_ends array with source code positions of line ends. | 7188 // Init line_ends array with source code positions of line ends. |
| 7161 static void InitLineEnds(Handle<Script> script); | 7189 static void InitLineEnds(Handle<Script> script); |
| 7162 | 7190 |
| 7163 // Convert code offset into column number. | |
| 7164 static int GetColumnNumber(Handle<Script> script, int code_offset); | |
| 7165 | |
| 7166 // Convert code offset into (zero-based) line number. | |
| 7167 // The non-handlified version does not allocate, but may be much slower. | |
| 7168 static int GetLineNumber(Handle<Script> script, int code_offset); | |
| 7169 int GetLineNumber(int code_pos); | |
| 7170 | |
| 7171 // Carries information about a source position. | 7191 // Carries information about a source position. |
| 7172 struct PositionInfo { | 7192 struct PositionInfo { |
| 7173 PositionInfo() : line(-1), column(-1), line_start(-1), line_end(-1) {} | 7193 PositionInfo() : line(-1), column(-1), line_start(-1), line_end(-1) {} |
| 7174 | 7194 |
| 7175 int line; // Zero-based line number. | 7195 int line; // Zero-based line number. |
| 7176 int column; // Zero-based column number. | 7196 int column; // Zero-based column number. |
| 7177 int line_start; // Position of first character in line. | 7197 int line_start; // Position of first character in line. |
| 7178 int line_end; // Position of last (non-linebreak) character in line. | 7198 int line_end; // Position of final linebreak character in line. |
| 7179 }; | 7199 }; |
| 7180 | 7200 |
| 7181 // Specifies whether to add offsets to position infos. | 7201 // Specifies whether to add offsets to position infos. |
| 7182 enum OffsetFlag { NO_OFFSET = 0, WITH_OFFSET = 1 }; | 7202 enum OffsetFlag { NO_OFFSET = 0, WITH_OFFSET = 1 }; |
| 7183 | 7203 |
| 7184 // Retrieves information about the given position, optionally with an offset. | 7204 // Retrieves information about the given position, optionally with an offset. |
| 7185 // Returns false on failure, and otherwise writes into the given info object | 7205 // Returns false on failure, and otherwise writes into the given info object |
| 7186 // on success. | 7206 // on success. |
| 7207 // The non-handlified version does not allocate, but may be much slower. | |
| 7208 static bool GetPositionInfo(Handle<Script> script, int position, | |
| 7209 PositionInfo* info, OffsetFlag offset_flag); | |
| 7187 bool GetPositionInfo(int position, PositionInfo* info, | 7210 bool GetPositionInfo(int position, PositionInfo* info, |
| 7188 OffsetFlag offset_flag); | 7211 OffsetFlag offset_flag); |
| 7189 | 7212 |
| 7213 // Wrappers for GetPositionInfo | |
| 7214 static int GetColumnNumber(Handle<Script> script, int code_offset); | |
|
vogelheim
2016/11/07 17:53:27
The static instances get GetPositionInfo, GetColum
Tobias Tebbi
2016/11/08 10:29:07
The reason is that the non-static methods are not
| |
| 7215 int GetColumnNumber(int code_pos); | |
|
vogelheim
2016/11/07 17:53:27
const method?
[Also GetLineNumber below. And I ge
Tobias Tebbi
2016/11/08 10:29:07
Since the underlying member is not even a C++ memb
| |
| 7216 static int GetLineNumber(Handle<Script> script, int code_offset); | |
| 7217 int GetLineNumber(int code_pos); | |
| 7218 | |
| 7190 // Get the JS object wrapping the given script; create it if none exists. | 7219 // Get the JS object wrapping the given script; create it if none exists. |
| 7191 static Handle<JSObject> GetWrapper(Handle<Script> script); | 7220 static Handle<JSObject> GetWrapper(Handle<Script> script); |
| 7192 | 7221 |
| 7193 // Look through the list of existing shared function infos to find one | 7222 // Look through the list of existing shared function infos to find one |
| 7194 // that matches the function literal. Return empty handle if not found. | 7223 // that matches the function literal. Return empty handle if not found. |
| 7195 MaybeHandle<SharedFunctionInfo> FindSharedFunctionInfo(FunctionLiteral* fun); | 7224 MaybeHandle<SharedFunctionInfo> FindSharedFunctionInfo(FunctionLiteral* fun); |
| 7196 | 7225 |
| 7197 // Iterate over all script objects on the heap. | 7226 // Iterate over all script objects on the heap. |
| 7198 class Iterator { | 7227 class Iterator { |
| 7199 public: | 7228 public: |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 7222 static const int kEvalFromPositionOffset = | 7251 static const int kEvalFromPositionOffset = |
| 7223 kEvalFromSharedOffset + kPointerSize; | 7252 kEvalFromSharedOffset + kPointerSize; |
| 7224 static const int kSharedFunctionInfosOffset = | 7253 static const int kSharedFunctionInfosOffset = |
| 7225 kEvalFromPositionOffset + kPointerSize; | 7254 kEvalFromPositionOffset + kPointerSize; |
| 7226 static const int kFlagsOffset = kSharedFunctionInfosOffset + kPointerSize; | 7255 static const int kFlagsOffset = kSharedFunctionInfosOffset + kPointerSize; |
| 7227 static const int kSourceUrlOffset = kFlagsOffset + kPointerSize; | 7256 static const int kSourceUrlOffset = kFlagsOffset + kPointerSize; |
| 7228 static const int kSourceMappingUrlOffset = kSourceUrlOffset + kPointerSize; | 7257 static const int kSourceMappingUrlOffset = kSourceUrlOffset + kPointerSize; |
| 7229 static const int kSize = kSourceMappingUrlOffset + kPointerSize; | 7258 static const int kSize = kSourceMappingUrlOffset + kPointerSize; |
| 7230 | 7259 |
| 7231 private: | 7260 private: |
| 7232 int GetLineNumberWithArray(int code_pos); | |
| 7233 | |
| 7234 // Bit positions in the flags field. | 7261 // Bit positions in the flags field. |
| 7235 static const int kCompilationTypeBit = 0; | 7262 static const int kCompilationTypeBit = 0; |
| 7236 static const int kCompilationStateBit = 1; | 7263 static const int kCompilationStateBit = 1; |
| 7237 static const int kHideSourceBit = 2; | 7264 static const int kHideSourceBit = 2; |
| 7238 static const int kOriginOptionsShift = 3; | 7265 static const int kOriginOptionsShift = 3; |
| 7239 static const int kOriginOptionsSize = 3; | 7266 static const int kOriginOptionsSize = 3; |
| 7240 static const int kOriginOptionsMask = ((1 << kOriginOptionsSize) - 1) | 7267 static const int kOriginOptionsMask = ((1 << kOriginOptionsSize) - 1) |
| 7241 << kOriginOptionsShift; | 7268 << kOriginOptionsShift; |
| 7242 | 7269 |
| 7243 DISALLOW_IMPLICIT_CONSTRUCTORS(Script); | 7270 DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| (...skipping 4525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11769 } | 11796 } |
| 11770 return value; | 11797 return value; |
| 11771 } | 11798 } |
| 11772 }; | 11799 }; |
| 11773 | 11800 |
| 11774 | 11801 |
| 11775 } // NOLINT, false-positive due to second-order macros. | 11802 } // NOLINT, false-positive due to second-order macros. |
| 11776 } // NOLINT, false-positive due to second-order macros. | 11803 } // NOLINT, false-positive due to second-order macros. |
| 11777 | 11804 |
| 11778 #endif // V8_OBJECTS_H_ | 11805 #endif // V8_OBJECTS_H_ |
| OLD | NEW |