V8 Project
factory.cc
Go to the documentation of this file.
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/factory.h"
6 
8 #include "src/base/bits.h"
9 #include "src/conversions.h"
10 #include "src/isolate-inl.h"
11 #include "src/macro-assembler.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 
17 template<typename T>
18 Handle<T> Factory::New(Handle<Map> map, AllocationSpace space) {
20  isolate(),
21  isolate()->heap()->Allocate(*map, space),
22  T);
23 }
24 
25 
26 template<typename T>
27 Handle<T> Factory::New(Handle<Map> map,
29  Handle<AllocationSite> allocation_site) {
31  isolate(),
32  isolate()->heap()->Allocate(*map, space, *allocation_site),
33  T);
34 }
35 
36 
37 Handle<HeapObject> Factory::NewFillerObject(int size,
38  bool double_align,
41  isolate(),
42  isolate()->heap()->AllocateFillerObject(size, double_align, space),
43  HeapObject);
44 }
45 
46 
47 Handle<Box> Factory::NewBox(Handle<Object> value) {
48  Handle<Box> result = Handle<Box>::cast(NewStruct(BOX_TYPE));
49  result->set_value(*value);
50  return result;
51 }
52 
53 
54 Handle<Oddball> Factory::NewOddball(Handle<Map> map,
55  const char* to_string,
56  Handle<Object> to_number,
57  byte kind) {
58  Handle<Oddball> oddball = New<Oddball>(map, OLD_POINTER_SPACE);
59  Oddball::Initialize(isolate(), oddball, to_string, to_number, kind);
60  return oddball;
61 }
62 
63 
64 Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) {
65  DCHECK(0 <= size);
67  isolate(),
68  isolate()->heap()->AllocateFixedArray(size, pretenure),
69  FixedArray);
70 }
71 
72 
73 Handle<FixedArray> Factory::NewFixedArrayWithHoles(int size,
74  PretenureFlag pretenure) {
75  DCHECK(0 <= size);
77  isolate(),
78  isolate()->heap()->AllocateFixedArrayWithFiller(size,
79  pretenure,
80  *the_hole_value()),
81  FixedArray);
82 }
83 
84 
85 Handle<FixedArray> Factory::NewUninitializedFixedArray(int size) {
87  isolate(),
88  isolate()->heap()->AllocateUninitializedFixedArray(size),
89  FixedArray);
90 }
91 
92 
93 Handle<FixedArrayBase> Factory::NewFixedDoubleArray(int size,
94  PretenureFlag pretenure) {
95  DCHECK(0 <= size);
97  isolate(),
98  isolate()->heap()->AllocateUninitializedFixedDoubleArray(size, pretenure),
99  FixedArrayBase);
100 }
101 
102 
103 Handle<FixedArrayBase> Factory::NewFixedDoubleArrayWithHoles(
104  int size,
105  PretenureFlag pretenure) {
106  DCHECK(0 <= size);
107  Handle<FixedArrayBase> array = NewFixedDoubleArray(size, pretenure);
108  if (size > 0) {
109  Handle<FixedDoubleArray> double_array =
111  for (int i = 0; i < size; ++i) {
112  double_array->set_the_hole(i);
113  }
114  }
115  return array;
116 }
117 
118 
119 Handle<ConstantPoolArray> Factory::NewConstantPoolArray(
120  const ConstantPoolArray::NumberOfEntries& small) {
121  DCHECK(small.total_count() > 0);
123  isolate(),
124  isolate()->heap()->AllocateConstantPoolArray(small),
125  ConstantPoolArray);
126 }
127 
128 
129 Handle<ConstantPoolArray> Factory::NewExtendedConstantPoolArray(
130  const ConstantPoolArray::NumberOfEntries& small,
131  const ConstantPoolArray::NumberOfEntries& extended) {
132  DCHECK(small.total_count() > 0);
133  DCHECK(extended.total_count() > 0);
135  isolate(),
136  isolate()->heap()->AllocateExtendedConstantPoolArray(small, extended),
137  ConstantPoolArray);
138 }
139 
140 
141 Handle<OrderedHashSet> Factory::NewOrderedHashSet() {
142  return OrderedHashSet::Allocate(isolate(), 4);
143 }
144 
145 
146 Handle<OrderedHashMap> Factory::NewOrderedHashMap() {
147  return OrderedHashMap::Allocate(isolate(), 4);
148 }
149 
150 
151 Handle<AccessorPair> Factory::NewAccessorPair() {
152  Handle<AccessorPair> accessors =
154  accessors->set_getter(*the_hole_value(), SKIP_WRITE_BARRIER);
155  accessors->set_setter(*the_hole_value(), SKIP_WRITE_BARRIER);
156  return accessors;
157 }
158 
159 
160 Handle<TypeFeedbackInfo> Factory::NewTypeFeedbackInfo() {
161  Handle<TypeFeedbackInfo> info =
163  info->initialize_storage();
164  return info;
165 }
166 
167 
168 // Internalized strings are created in the old generation (data space).
169 Handle<String> Factory::InternalizeUtf8String(Vector<const char> string) {
170  Utf8StringKey key(string, isolate()->heap()->HashSeed());
171  return InternalizeStringWithKey(&key);
172 }
173 
174 
175 // Internalized strings are created in the old generation (data space).
176 Handle<String> Factory::InternalizeString(Handle<String> string) {
177  if (string->IsInternalizedString()) return string;
178  return StringTable::LookupString(isolate(), string);
179 }
180 
181 
182 Handle<String> Factory::InternalizeOneByteString(Vector<const uint8_t> string) {
183  OneByteStringKey key(string, isolate()->heap()->HashSeed());
184  return InternalizeStringWithKey(&key);
185 }
186 
187 
188 Handle<String> Factory::InternalizeOneByteString(
189  Handle<SeqOneByteString> string, int from, int length) {
190  SeqOneByteSubStringKey key(string, from, length);
191  return InternalizeStringWithKey(&key);
192 }
193 
194 
195 Handle<String> Factory::InternalizeTwoByteString(Vector<const uc16> string) {
196  TwoByteStringKey key(string, isolate()->heap()->HashSeed());
197  return InternalizeStringWithKey(&key);
198 }
199 
200 
201 template<class StringTableKey>
202 Handle<String> Factory::InternalizeStringWithKey(StringTableKey* key) {
203  return StringTable::LookupKey(isolate(), key);
204 }
205 
206 
207 MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string,
208  PretenureFlag pretenure) {
209  int length = string.length();
210  if (length == 1) return LookupSingleCharacterStringFromCode(string[0]);
211  Handle<SeqOneByteString> result;
213  isolate(),
214  result,
215  NewRawOneByteString(string.length(), pretenure),
216  String);
217 
219  // Copy the characters into the new object.
220  CopyChars(SeqOneByteString::cast(*result)->GetChars(),
221  string.start(),
222  length);
223  return result;
224 }
225 
226 MaybeHandle<String> Factory::NewStringFromUtf8(Vector<const char> string,
227  PretenureFlag pretenure) {
228  // Check for ASCII first since this is the common case.
229  const char* start = string.start();
230  int length = string.length();
231  int non_ascii_start = String::NonAsciiStart(start, length);
232  if (non_ascii_start >= length) {
233  // If the string is ASCII, we do not need to convert the characters
234  // since UTF8 is backwards compatible with ASCII.
235  return NewStringFromOneByte(Vector<const uint8_t>::cast(string), pretenure);
236  }
237 
238  // Non-ASCII and we need to decode.
239  Access<UnicodeCache::Utf8Decoder>
240  decoder(isolate()->unicode_cache()->utf8_decoder());
241  decoder->Reset(string.start() + non_ascii_start,
242  length - non_ascii_start);
243  int utf16_length = decoder->Utf16Length();
244  DCHECK(utf16_length > 0);
245  // Allocate string.
246  Handle<SeqTwoByteString> result;
248  isolate(), result,
249  NewRawTwoByteString(non_ascii_start + utf16_length, pretenure),
250  String);
251  // Copy ASCII portion.
252  uint16_t* data = result->GetChars();
253  const char* ascii_data = string.start();
254  for (int i = 0; i < non_ascii_start; i++) {
255  *data++ = *ascii_data++;
256  }
257  // Now write the remainder.
258  decoder->WriteUtf16(data, utf16_length);
259  return result;
260 }
261 
262 
263 MaybeHandle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
264  PretenureFlag pretenure) {
265  int length = string.length();
266  const uc16* start = string.start();
267  if (String::IsOneByte(start, length)) {
268  if (length == 1) return LookupSingleCharacterStringFromCode(string[0]);
269  Handle<SeqOneByteString> result;
271  isolate(),
272  result,
273  NewRawOneByteString(length, pretenure),
274  String);
275  CopyChars(result->GetChars(), start, length);
276  return result;
277  } else {
278  Handle<SeqTwoByteString> result;
280  isolate(),
281  result,
282  NewRawTwoByteString(length, pretenure),
283  String);
284  CopyChars(result->GetChars(), start, length);
285  return result;
286  }
287 }
288 
289 
290 Handle<String> Factory::NewInternalizedStringFromUtf8(Vector<const char> str,
291  int chars,
292  uint32_t hash_field) {
294  isolate(),
295  isolate()->heap()->AllocateInternalizedStringFromUtf8(
296  str, chars, hash_field),
297  String);
298 }
299 
300 
301 MUST_USE_RESULT Handle<String> Factory::NewOneByteInternalizedString(
302  Vector<const uint8_t> str,
303  uint32_t hash_field) {
305  isolate(),
306  isolate()->heap()->AllocateOneByteInternalizedString(str, hash_field),
307  String);
308 }
309 
310 
311 MUST_USE_RESULT Handle<String> Factory::NewOneByteInternalizedSubString(
312  Handle<SeqOneByteString> string, int offset, int length,
313  uint32_t hash_field) {
315  isolate(), isolate()->heap()->AllocateOneByteInternalizedString(
316  Vector<const uint8_t>(string->GetChars() + offset, length),
317  hash_field),
318  String);
319 }
320 
321 
322 MUST_USE_RESULT Handle<String> Factory::NewTwoByteInternalizedString(
323  Vector<const uc16> str,
324  uint32_t hash_field) {
326  isolate(),
327  isolate()->heap()->AllocateTwoByteInternalizedString(str, hash_field),
328  String);
329 }
330 
331 
332 Handle<String> Factory::NewInternalizedStringImpl(
333  Handle<String> string, int chars, uint32_t hash_field) {
335  isolate(),
336  isolate()->heap()->AllocateInternalizedStringImpl(
337  *string, chars, hash_field),
338  String);
339 }
340 
341 
342 MaybeHandle<Map> Factory::InternalizedStringMapForString(
343  Handle<String> string) {
344  // If the string is in new space it cannot be used as internalized.
345  if (isolate()->heap()->InNewSpace(*string)) return MaybeHandle<Map>();
346 
347  // Find the corresponding internalized string map for strings.
348  switch (string->map()->instance_type()) {
349  case STRING_TYPE: return internalized_string_map();
351  return one_byte_internalized_string_map();
352  case EXTERNAL_STRING_TYPE: return external_internalized_string_map();
354  return external_one_byte_internalized_string_map();
356  return external_internalized_string_with_one_byte_data_map();
358  return short_external_internalized_string_map();
360  return short_external_one_byte_internalized_string_map();
362  return short_external_internalized_string_with_one_byte_data_map();
363  default: return MaybeHandle<Map>(); // No match found.
364  }
365 }
366 
367 
368 MaybeHandle<SeqOneByteString> Factory::NewRawOneByteString(
369  int length, PretenureFlag pretenure) {
370  if (length > String::kMaxLength || length < 0) {
371  THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), SeqOneByteString);
372  }
374  isolate(),
375  isolate()->heap()->AllocateRawOneByteString(length, pretenure),
376  SeqOneByteString);
377 }
378 
379 
380 MaybeHandle<SeqTwoByteString> Factory::NewRawTwoByteString(
381  int length, PretenureFlag pretenure) {
382  if (length > String::kMaxLength || length < 0) {
383  THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), SeqTwoByteString);
384  }
386  isolate(),
387  isolate()->heap()->AllocateRawTwoByteString(length, pretenure),
388  SeqTwoByteString);
389 }
390 
391 
392 Handle<String> Factory::LookupSingleCharacterStringFromCode(uint32_t code) {
393  if (code <= String::kMaxOneByteCharCodeU) {
394  {
395  DisallowHeapAllocation no_allocation;
396  Object* value = single_character_string_cache()->get(code);
397  if (value != *undefined_value()) {
398  return handle(String::cast(value), isolate());
399  }
400  }
401  uint8_t buffer[1];
402  buffer[0] = static_cast<uint8_t>(code);
403  Handle<String> result =
404  InternalizeOneByteString(Vector<const uint8_t>(buffer, 1));
405  single_character_string_cache()->set(code, *result);
406  return result;
407  }
409 
410  Handle<SeqTwoByteString> result = NewRawTwoByteString(1).ToHandleChecked();
411  result->SeqTwoByteStringSet(0, static_cast<uint16_t>(code));
412  return result;
413 }
414 
415 
416 // Returns true for a character in a range. Both limits are inclusive.
417 static inline bool Between(uint32_t character, uint32_t from, uint32_t to) {
418  // This makes uses of the the unsigned wraparound.
419  return character - from <= to - from;
420 }
421 
422 
424  uint16_t c1,
425  uint16_t c2) {
426  // Numeric strings have a different hash algorithm not known by
427  // LookupTwoCharsStringIfExists, so we skip this step for such strings.
428  if (!Between(c1, '0', '9') || !Between(c2, '0', '9')) {
429  Handle<String> result;
430  if (StringTable::LookupTwoCharsStringIfExists(isolate, c1, c2).
431  ToHandle(&result)) {
432  return result;
433  }
434  }
435 
436  // Now we know the length is 2, we might as well make use of that fact
437  // when building the new string.
438  if (static_cast<unsigned>(c1 | c2) <= String::kMaxOneByteCharCodeU) {
439  // We can do this.
441  1)); // because of this.
443  isolate->factory()->NewRawOneByteString(2).ToHandleChecked();
444  uint8_t* dest = str->GetChars();
445  dest[0] = static_cast<uint8_t>(c1);
446  dest[1] = static_cast<uint8_t>(c2);
447  return str;
448  } else {
450  isolate->factory()->NewRawTwoByteString(2).ToHandleChecked();
451  uc16* dest = str->GetChars();
452  dest[0] = c1;
453  dest[1] = c2;
454  return str;
455  }
456 }
457 
458 
459 template<typename SinkChar, typename StringType>
461  Handle<String> first,
462  Handle<String> second) {
463  DisallowHeapAllocation pointer_stays_valid;
464  SinkChar* sink = result->GetChars();
465  String::WriteToFlat(*first, sink, 0, first->length());
466  String::WriteToFlat(*second, sink + first->length(), 0, second->length());
467  return result;
468 }
469 
470 
471 MaybeHandle<String> Factory::NewConsString(Handle<String> left,
472  Handle<String> right) {
473  int left_length = left->length();
474  if (left_length == 0) return right;
475  int right_length = right->length();
476  if (right_length == 0) return left;
477 
478  int length = left_length + right_length;
479 
480  if (length == 2) {
481  uint16_t c1 = left->Get(0);
482  uint16_t c2 = right->Get(0);
483  return MakeOrFindTwoCharacterString(isolate(), c1, c2);
484  }
485 
486  // Make sure that an out of memory exception is thrown if the length
487  // of the new cons string is too large.
488  if (length > String::kMaxLength || length < 0) {
489  THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String);
490  }
491 
492  bool left_is_one_byte = left->IsOneByteRepresentation();
493  bool right_is_one_byte = right->IsOneByteRepresentation();
494  bool is_one_byte = left_is_one_byte && right_is_one_byte;
495  bool is_one_byte_data_in_two_byte_string = false;
496  if (!is_one_byte) {
497  // At least one of the strings uses two-byte representation so we
498  // can't use the fast case code for short one-byte strings below, but
499  // we can try to save memory if all chars actually fit in one-byte.
500  is_one_byte_data_in_two_byte_string =
501  left->HasOnlyOneByteChars() && right->HasOnlyOneByteChars();
502  if (is_one_byte_data_in_two_byte_string) {
503  isolate()->counters()->string_add_runtime_ext_to_one_byte()->Increment();
504  }
505  }
506 
507  // If the resulting string is small make a flat string.
508  if (length < ConsString::kMinLength) {
509  // Note that neither of the two inputs can be a slice because:
511  DCHECK(left->IsFlat());
512  DCHECK(right->IsFlat());
513 
515  if (is_one_byte) {
516  Handle<SeqOneByteString> result =
517  NewRawOneByteString(length).ToHandleChecked();
519  uint8_t* dest = result->GetChars();
520  // Copy left part.
521  const uint8_t* src =
522  left->IsExternalString()
523  ? Handle<ExternalOneByteString>::cast(left)->GetChars()
524  : Handle<SeqOneByteString>::cast(left)->GetChars();
525  for (int i = 0; i < left_length; i++) *dest++ = src[i];
526  // Copy right part.
527  src = right->IsExternalString()
528  ? Handle<ExternalOneByteString>::cast(right)->GetChars()
529  : Handle<SeqOneByteString>::cast(right)->GetChars();
530  for (int i = 0; i < right_length; i++) *dest++ = src[i];
531  return result;
532  }
533 
534  return (is_one_byte_data_in_two_byte_string)
535  ? ConcatStringContent<uint8_t>(
536  NewRawOneByteString(length).ToHandleChecked(), left, right)
538  NewRawTwoByteString(length).ToHandleChecked(), left, right);
539  }
540 
541  Handle<Map> map = (is_one_byte || is_one_byte_data_in_two_byte_string)
542  ? cons_one_byte_string_map()
543  : cons_string_map();
544  Handle<ConsString> result = New<ConsString>(map, NEW_SPACE);
545 
547  WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
548 
549  result->set_hash_field(String::kEmptyHashField);
550  result->set_length(length);
551  result->set_first(*left, mode);
552  result->set_second(*right, mode);
553  return result;
554 }
555 
556 
557 Handle<String> Factory::NewProperSubString(Handle<String> str,
558  int begin,
559  int end) {
560 #if VERIFY_HEAP
561  if (FLAG_verify_heap) str->StringVerify();
562 #endif
563  DCHECK(begin > 0 || end < str->length());
564 
565  str = String::Flatten(str);
566 
567  int length = end - begin;
568  if (length <= 0) return empty_string();
569  if (length == 1) {
570  return LookupSingleCharacterStringFromCode(str->Get(begin));
571  }
572  if (length == 2) {
573  // Optimization for 2-byte strings often used as keys in a decompression
574  // dictionary. Check whether we already have the string in the string
575  // table to prevent creation of many unnecessary strings.
576  uint16_t c1 = str->Get(begin);
577  uint16_t c2 = str->Get(begin + 1);
578  return MakeOrFindTwoCharacterString(isolate(), c1, c2);
579  }
580 
581  if (!FLAG_string_slices || length < SlicedString::kMinLength) {
582  if (str->IsOneByteRepresentation()) {
583  Handle<SeqOneByteString> result =
584  NewRawOneByteString(length).ToHandleChecked();
585  uint8_t* dest = result->GetChars();
587  String::WriteToFlat(*str, dest, begin, end);
588  return result;
589  } else {
590  Handle<SeqTwoByteString> result =
591  NewRawTwoByteString(length).ToHandleChecked();
592  uc16* dest = result->GetChars();
594  String::WriteToFlat(*str, dest, begin, end);
595  return result;
596  }
597  }
598 
599  int offset = begin;
600 
601  if (str->IsSlicedString()) {
602  Handle<SlicedString> slice = Handle<SlicedString>::cast(str);
603  str = Handle<String>(slice->parent(), isolate());
604  offset += slice->offset();
605  }
606 
607  DCHECK(str->IsSeqString() || str->IsExternalString());
608  Handle<Map> map = str->IsOneByteRepresentation()
609  ? sliced_one_byte_string_map()
610  : sliced_string_map();
611  Handle<SlicedString> slice = New<SlicedString>(map, NEW_SPACE);
612 
613  slice->set_hash_field(String::kEmptyHashField);
614  slice->set_length(length);
615  slice->set_parent(*str);
616  slice->set_offset(offset);
617  return slice;
618 }
619 
620 
621 MaybeHandle<String> Factory::NewExternalStringFromOneByte(
622  const ExternalOneByteString::Resource* resource) {
623  size_t length = resource->length();
624  if (length > static_cast<size_t>(String::kMaxLength)) {
625  THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String);
626  }
627 
628  Handle<Map> map = external_one_byte_string_map();
629  Handle<ExternalOneByteString> external_string =
630  New<ExternalOneByteString>(map, NEW_SPACE);
631  external_string->set_length(static_cast<int>(length));
632  external_string->set_hash_field(String::kEmptyHashField);
633  external_string->set_resource(resource);
634 
635  return external_string;
636 }
637 
638 
639 MaybeHandle<String> Factory::NewExternalStringFromTwoByte(
640  const ExternalTwoByteString::Resource* resource) {
641  size_t length = resource->length();
642  if (length > static_cast<size_t>(String::kMaxLength)) {
643  THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String);
644  }
645 
646  // For small strings we check whether the resource contains only
647  // one byte characters. If yes, we use a different string map.
648  static const size_t kOneByteCheckLengthLimit = 32;
649  bool is_one_byte = length <= kOneByteCheckLengthLimit &&
650  String::IsOneByte(resource->data(), static_cast<int>(length));
651  Handle<Map> map = is_one_byte ?
652  external_string_with_one_byte_data_map() : external_string_map();
653  Handle<ExternalTwoByteString> external_string =
654  New<ExternalTwoByteString>(map, NEW_SPACE);
655  external_string->set_length(static_cast<int>(length));
656  external_string->set_hash_field(String::kEmptyHashField);
657  external_string->set_resource(resource);
658 
659  return external_string;
660 }
661 
662 
663 Handle<Symbol> Factory::NewSymbol() {
665  isolate(),
666  isolate()->heap()->AllocateSymbol(),
667  Symbol);
668 }
669 
670 
671 Handle<Symbol> Factory::NewPrivateSymbol() {
672  Handle<Symbol> symbol = NewSymbol();
673  symbol->set_is_private(true);
674  return symbol;
675 }
676 
677 
678 Handle<Symbol> Factory::NewPrivateOwnSymbol() {
679  Handle<Symbol> symbol = NewSymbol();
680  symbol->set_is_private(true);
681  symbol->set_is_own(true);
682  return symbol;
683 }
684 
685 
686 Handle<Context> Factory::NewNativeContext() {
687  Handle<FixedArray> array = NewFixedArray(Context::NATIVE_CONTEXT_SLOTS);
688  array->set_map_no_write_barrier(*native_context_map());
689  Handle<Context> context = Handle<Context>::cast(array);
690  context->set_js_array_maps(*undefined_value());
691  DCHECK(context->IsNativeContext());
692  return context;
693 }
694 
695 
696 Handle<Context> Factory::NewGlobalContext(Handle<JSFunction> function,
697  Handle<ScopeInfo> scope_info) {
698  Handle<FixedArray> array =
699  NewFixedArray(scope_info->ContextLength(), TENURED);
700  array->set_map_no_write_barrier(*global_context_map());
701  Handle<Context> context = Handle<Context>::cast(array);
702  context->set_closure(*function);
703  context->set_previous(function->context());
704  context->set_extension(*scope_info);
705  context->set_global_object(function->context()->global_object());
706  DCHECK(context->IsGlobalContext());
707  return context;
708 }
709 
710 
711 Handle<Context> Factory::NewModuleContext(Handle<ScopeInfo> scope_info) {
712  Handle<FixedArray> array =
713  NewFixedArray(scope_info->ContextLength(), TENURED);
714  array->set_map_no_write_barrier(*module_context_map());
715  // Instance link will be set later.
716  Handle<Context> context = Handle<Context>::cast(array);
717  context->set_extension(Smi::FromInt(0));
718  return context;
719 }
720 
721 
722 Handle<Context> Factory::NewFunctionContext(int length,
723  Handle<JSFunction> function) {
725  Handle<FixedArray> array = NewFixedArray(length);
726  array->set_map_no_write_barrier(*function_context_map());
727  Handle<Context> context = Handle<Context>::cast(array);
728  context->set_closure(*function);
729  context->set_previous(function->context());
730  context->set_extension(Smi::FromInt(0));
731  context->set_global_object(function->context()->global_object());
732  return context;
733 }
734 
735 
736 Handle<Context> Factory::NewCatchContext(Handle<JSFunction> function,
737  Handle<Context> previous,
738  Handle<String> name,
739  Handle<Object> thrown_object) {
741  Handle<FixedArray> array = NewFixedArray(Context::MIN_CONTEXT_SLOTS + 1);
742  array->set_map_no_write_barrier(*catch_context_map());
743  Handle<Context> context = Handle<Context>::cast(array);
744  context->set_closure(*function);
745  context->set_previous(*previous);
746  context->set_extension(*name);
747  context->set_global_object(previous->global_object());
748  context->set(Context::THROWN_OBJECT_INDEX, *thrown_object);
749  return context;
750 }
751 
752 
753 Handle<Context> Factory::NewWithContext(Handle<JSFunction> function,
754  Handle<Context> previous,
755  Handle<JSReceiver> extension) {
756  Handle<FixedArray> array = NewFixedArray(Context::MIN_CONTEXT_SLOTS);
757  array->set_map_no_write_barrier(*with_context_map());
758  Handle<Context> context = Handle<Context>::cast(array);
759  context->set_closure(*function);
760  context->set_previous(*previous);
761  context->set_extension(*extension);
762  context->set_global_object(previous->global_object());
763  return context;
764 }
765 
766 
767 Handle<Context> Factory::NewBlockContext(Handle<JSFunction> function,
768  Handle<Context> previous,
769  Handle<ScopeInfo> scope_info) {
770  Handle<FixedArray> array =
771  NewFixedArrayWithHoles(scope_info->ContextLength());
772  array->set_map_no_write_barrier(*block_context_map());
773  Handle<Context> context = Handle<Context>::cast(array);
774  context->set_closure(*function);
775  context->set_previous(*previous);
776  context->set_extension(*scope_info);
777  context->set_global_object(previous->global_object());
778  return context;
779 }
780 
781 
782 Handle<Struct> Factory::NewStruct(InstanceType type) {
784  isolate(),
785  isolate()->heap()->AllocateStruct(type),
786  Struct);
787 }
788 
789 
790 Handle<CodeCache> Factory::NewCodeCache() {
791  Handle<CodeCache> code_cache =
793  code_cache->set_default_cache(*empty_fixed_array(), SKIP_WRITE_BARRIER);
794  code_cache->set_normal_type_cache(*undefined_value(), SKIP_WRITE_BARRIER);
795  return code_cache;
796 }
797 
798 
799 Handle<AliasedArgumentsEntry> Factory::NewAliasedArgumentsEntry(
800  int aliased_context_slot) {
801  Handle<AliasedArgumentsEntry> entry = Handle<AliasedArgumentsEntry>::cast(
802  NewStruct(ALIASED_ARGUMENTS_ENTRY_TYPE));
803  entry->set_aliased_context_slot(aliased_context_slot);
804  return entry;
805 }
806 
807 
808 Handle<DeclaredAccessorDescriptor> Factory::NewDeclaredAccessorDescriptor() {
811 }
812 
813 
814 Handle<DeclaredAccessorInfo> Factory::NewDeclaredAccessorInfo() {
815  Handle<DeclaredAccessorInfo> info =
817  NewStruct(DECLARED_ACCESSOR_INFO_TYPE));
818  info->set_flag(0); // Must clear the flag, it was initialized as undefined.
819  return info;
820 }
821 
822 
823 Handle<ExecutableAccessorInfo> Factory::NewExecutableAccessorInfo() {
824  Handle<ExecutableAccessorInfo> info =
826  NewStruct(EXECUTABLE_ACCESSOR_INFO_TYPE));
827  info->set_flag(0); // Must clear the flag, it was initialized as undefined.
828  return info;
829 }
830 
831 
832 Handle<Script> Factory::NewScript(Handle<String> source) {
833  // Generate id for this script.
834  Heap* heap = isolate()->heap();
835  int id = heap->last_script_id()->value() + 1;
836  if (!Smi::IsValid(id) || id < 0) id = 1;
837  heap->set_last_script_id(Smi::FromInt(id));
838 
839  // Create and initialize script object.
840  Handle<Foreign> wrapper = NewForeign(0, TENURED);
841  Handle<Script> script = Handle<Script>::cast(NewStruct(SCRIPT_TYPE));
842  script->set_source(*source);
843  script->set_name(heap->undefined_value());
844  script->set_id(Smi::FromInt(id));
845  script->set_line_offset(Smi::FromInt(0));
846  script->set_column_offset(Smi::FromInt(0));
847  script->set_context_data(heap->undefined_value());
848  script->set_type(Smi::FromInt(Script::TYPE_NORMAL));
849  script->set_wrapper(*wrapper);
850  script->set_line_ends(heap->undefined_value());
851  script->set_eval_from_shared(heap->undefined_value());
852  script->set_eval_from_instructions_offset(Smi::FromInt(0));
853  script->set_flags(Smi::FromInt(0));
854 
855  return script;
856 }
857 
858 
859 Handle<Foreign> Factory::NewForeign(Address addr, PretenureFlag pretenure) {
860  CALL_HEAP_FUNCTION(isolate(),
861  isolate()->heap()->AllocateForeign(addr, pretenure),
862  Foreign);
863 }
864 
865 
866 Handle<Foreign> Factory::NewForeign(const AccessorDescriptor* desc) {
867  return NewForeign((Address) desc, TENURED);
868 }
869 
870 
871 Handle<ByteArray> Factory::NewByteArray(int length, PretenureFlag pretenure) {
872  DCHECK(0 <= length);
874  isolate(),
875  isolate()->heap()->AllocateByteArray(length, pretenure),
876  ByteArray);
877 }
878 
879 
880 Handle<ExternalArray> Factory::NewExternalArray(int length,
881  ExternalArrayType array_type,
882  void* external_pointer,
883  PretenureFlag pretenure) {
884  DCHECK(0 <= length && length <= Smi::kMaxValue);
886  isolate(),
887  isolate()->heap()->AllocateExternalArray(length,
888  array_type,
889  external_pointer,
890  pretenure),
891  ExternalArray);
892 }
893 
894 
895 Handle<FixedTypedArrayBase> Factory::NewFixedTypedArray(
896  int length,
897  ExternalArrayType array_type,
898  PretenureFlag pretenure) {
899  DCHECK(0 <= length && length <= Smi::kMaxValue);
901  isolate(),
902  isolate()->heap()->AllocateFixedTypedArray(length,
903  array_type,
904  pretenure),
905  FixedTypedArrayBase);
906 }
907 
908 
909 Handle<Cell> Factory::NewCell(Handle<Object> value) {
910  AllowDeferredHandleDereference convert_to_cell;
912  isolate(),
913  isolate()->heap()->AllocateCell(*value),
914  Cell);
915 }
916 
917 
918 Handle<PropertyCell> Factory::NewPropertyCellWithHole() {
920  isolate(),
921  isolate()->heap()->AllocatePropertyCell(),
922  PropertyCell);
923 }
924 
925 
926 Handle<PropertyCell> Factory::NewPropertyCell(Handle<Object> value) {
927  AllowDeferredHandleDereference convert_to_cell;
928  Handle<PropertyCell> cell = NewPropertyCellWithHole();
929  PropertyCell::SetValueInferType(cell, value);
930  return cell;
931 }
932 
933 
934 Handle<AllocationSite> Factory::NewAllocationSite() {
935  Handle<Map> map = allocation_site_map();
936  Handle<AllocationSite> site = New<AllocationSite>(map, OLD_POINTER_SPACE);
937  site->Initialize();
938 
939  // Link the site
940  site->set_weak_next(isolate()->heap()->allocation_sites_list());
941  isolate()->heap()->set_allocation_sites_list(*site);
942  return site;
943 }
944 
945 
946 Handle<Map> Factory::NewMap(InstanceType type,
947  int instance_size,
948  ElementsKind elements_kind) {
950  isolate(),
951  isolate()->heap()->AllocateMap(type, instance_size, elements_kind),
952  Map);
953 }
954 
955 
956 Handle<JSObject> Factory::CopyJSObject(Handle<JSObject> object) {
957  CALL_HEAP_FUNCTION(isolate(),
958  isolate()->heap()->CopyJSObject(*object, NULL),
959  JSObject);
960 }
961 
962 
963 Handle<JSObject> Factory::CopyJSObjectWithAllocationSite(
964  Handle<JSObject> object,
965  Handle<AllocationSite> site) {
966  CALL_HEAP_FUNCTION(isolate(),
967  isolate()->heap()->CopyJSObject(
968  *object,
969  site.is_null() ? NULL : *site),
970  JSObject);
971 }
972 
973 
974 Handle<FixedArray> Factory::CopyFixedArrayWithMap(Handle<FixedArray> array,
975  Handle<Map> map) {
976  CALL_HEAP_FUNCTION(isolate(),
977  isolate()->heap()->CopyFixedArrayWithMap(*array, *map),
978  FixedArray);
979 }
980 
981 
982 Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) {
983  CALL_HEAP_FUNCTION(isolate(),
984  isolate()->heap()->CopyFixedArray(*array),
985  FixedArray);
986 }
987 
988 
989 Handle<FixedArray> Factory::CopyAndTenureFixedCOWArray(
990  Handle<FixedArray> array) {
991  DCHECK(isolate()->heap()->InNewSpace(*array));
992  CALL_HEAP_FUNCTION(isolate(),
993  isolate()->heap()->CopyAndTenureFixedCOWArray(*array),
994  FixedArray);
995 }
996 
997 
998 Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray(
999  Handle<FixedDoubleArray> array) {
1000  CALL_HEAP_FUNCTION(isolate(),
1001  isolate()->heap()->CopyFixedDoubleArray(*array),
1002  FixedDoubleArray);
1003 }
1004 
1005 
1006 Handle<ConstantPoolArray> Factory::CopyConstantPoolArray(
1007  Handle<ConstantPoolArray> array) {
1008  CALL_HEAP_FUNCTION(isolate(),
1009  isolate()->heap()->CopyConstantPoolArray(*array),
1010  ConstantPoolArray);
1011 }
1012 
1013 
1014 Handle<Object> Factory::NewNumber(double value,
1015  PretenureFlag pretenure) {
1016  // We need to distinguish the minus zero value and this cannot be
1017  // done after conversion to int. Doing this by comparing bit
1018  // patterns is faster than using fpclassify() et al.
1019  if (IsMinusZero(value)) return NewHeapNumber(-0.0, IMMUTABLE, pretenure);
1020 
1021  int int_value = FastD2I(value);
1022  if (value == int_value && Smi::IsValid(int_value)) {
1023  return handle(Smi::FromInt(int_value), isolate());
1024  }
1025 
1026  // Materialize the value in the heap.
1027  return NewHeapNumber(value, IMMUTABLE, pretenure);
1028 }
1029 
1030 
1031 Handle<Object> Factory::NewNumberFromInt(int32_t value,
1032  PretenureFlag pretenure) {
1033  if (Smi::IsValid(value)) return handle(Smi::FromInt(value), isolate());
1034  // Bypass NewNumber to avoid various redundant checks.
1035  return NewHeapNumber(FastI2D(value), IMMUTABLE, pretenure);
1036 }
1037 
1038 
1039 Handle<Object> Factory::NewNumberFromUint(uint32_t value,
1040  PretenureFlag pretenure) {
1041  int32_t int32v = static_cast<int32_t>(value);
1042  if (int32v >= 0 && Smi::IsValid(int32v)) {
1043  return handle(Smi::FromInt(int32v), isolate());
1044  }
1045  return NewHeapNumber(FastUI2D(value), IMMUTABLE, pretenure);
1046 }
1047 
1048 
1049 Handle<HeapNumber> Factory::NewHeapNumber(double value,
1050  MutableMode mode,
1051  PretenureFlag pretenure) {
1053  isolate(),
1054  isolate()->heap()->AllocateHeapNumber(value, mode, pretenure),
1055  HeapNumber);
1056 }
1057 
1058 
1059 MaybeHandle<Object> Factory::NewTypeError(const char* message,
1060  Vector<Handle<Object> > args) {
1061  return NewError("MakeTypeError", message, args);
1062 }
1063 
1064 
1065 MaybeHandle<Object> Factory::NewTypeError(Handle<String> message) {
1066  return NewError("$TypeError", message);
1067 }
1068 
1069 
1070 MaybeHandle<Object> Factory::NewRangeError(const char* message,
1071  Vector<Handle<Object> > args) {
1072  return NewError("MakeRangeError", message, args);
1073 }
1074 
1075 
1076 MaybeHandle<Object> Factory::NewRangeError(Handle<String> message) {
1077  return NewError("$RangeError", message);
1078 }
1079 
1080 
1081 MaybeHandle<Object> Factory::NewSyntaxError(const char* message,
1082  Handle<JSArray> args) {
1083  return NewError("MakeSyntaxError", message, args);
1084 }
1085 
1086 
1087 MaybeHandle<Object> Factory::NewSyntaxError(Handle<String> message) {
1088  return NewError("$SyntaxError", message);
1089 }
1090 
1091 
1092 MaybeHandle<Object> Factory::NewReferenceError(const char* message,
1093  Vector<Handle<Object> > args) {
1094  return NewError("MakeReferenceError", message, args);
1095 }
1096 
1097 
1098 MaybeHandle<Object> Factory::NewReferenceError(const char* message,
1099  Handle<JSArray> args) {
1100  return NewError("MakeReferenceError", message, args);
1101 }
1102 
1103 
1104 MaybeHandle<Object> Factory::NewReferenceError(Handle<String> message) {
1105  return NewError("$ReferenceError", message);
1106 }
1107 
1108 
1109 MaybeHandle<Object> Factory::NewError(const char* maker, const char* message,
1110  Vector<Handle<Object> > args) {
1111  // Instantiate a closeable HandleScope for EscapeFrom.
1112  v8::EscapableHandleScope scope(reinterpret_cast<v8::Isolate*>(isolate()));
1113  Handle<FixedArray> array = NewFixedArray(args.length());
1114  for (int i = 0; i < args.length(); i++) {
1115  array->set(i, *args[i]);
1116  }
1117  Handle<JSArray> object = NewJSArrayWithElements(array);
1118  Handle<Object> result;
1119  ASSIGN_RETURN_ON_EXCEPTION(isolate(), result,
1120  NewError(maker, message, object), Object);
1121  return result.EscapeFrom(&scope);
1122 }
1123 
1124 
1125 MaybeHandle<Object> Factory::NewEvalError(const char* message,
1126  Vector<Handle<Object> > args) {
1127  return NewError("MakeEvalError", message, args);
1128 }
1129 
1130 
1131 MaybeHandle<Object> Factory::NewError(const char* message,
1132  Vector<Handle<Object> > args) {
1133  return NewError("MakeError", message, args);
1134 }
1135 
1136 
1137 Handle<String> Factory::EmergencyNewError(const char* message,
1138  Handle<JSArray> args) {
1139  const int kBufferSize = 1000;
1140  char buffer[kBufferSize];
1141  size_t space = kBufferSize;
1142  char* p = &buffer[0];
1143 
1144  Vector<char> v(buffer, kBufferSize);
1145  StrNCpy(v, message, space);
1146  space -= Min(space, strlen(message));
1147  p = &buffer[kBufferSize] - space;
1148 
1149  for (int i = 0; i < Smi::cast(args->length())->value(); i++) {
1150  if (space > 0) {
1151  *p++ = ' ';
1152  space--;
1153  if (space > 0) {
1154  Handle<String> arg_str = Handle<String>::cast(
1155  Object::GetElement(isolate(), args, i).ToHandleChecked());
1156  SmartArrayPointer<char> arg = arg_str->ToCString();
1157  Vector<char> v2(p, static_cast<int>(space));
1158  StrNCpy(v2, arg.get(), space);
1159  space -= Min(space, strlen(arg.get()));
1160  p = &buffer[kBufferSize] - space;
1161  }
1162  }
1163  }
1164  if (space > 0) {
1165  *p = '\0';
1166  } else {
1167  buffer[kBufferSize - 1] = '\0';
1168  }
1169  return NewStringFromUtf8(CStrVector(buffer), TENURED).ToHandleChecked();
1170 }
1171 
1172 
1173 MaybeHandle<Object> Factory::NewError(const char* maker, const char* message,
1174  Handle<JSArray> args) {
1175  Handle<String> make_str = InternalizeUtf8String(maker);
1176  Handle<Object> fun_obj = Object::GetProperty(
1177  isolate()->js_builtins_object(), make_str).ToHandleChecked();
1178  // If the builtins haven't been properly configured yet this error
1179  // constructor may not have been defined. Bail out.
1180  if (!fun_obj->IsJSFunction()) {
1181  return EmergencyNewError(message, args);
1182  }
1183  Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj);
1184  Handle<Object> message_obj = InternalizeUtf8String(message);
1185  Handle<Object> argv[] = { message_obj, args };
1186 
1187  // Invoke the JavaScript factory method. If an exception is thrown while
1188  // running the factory method, use the exception as the result.
1189  Handle<Object> result;
1190  MaybeHandle<Object> exception;
1191  if (!Execution::TryCall(fun,
1192  isolate()->js_builtins_object(),
1193  arraysize(argv),
1194  argv,
1195  &exception).ToHandle(&result)) {
1196  return exception;
1197  }
1198  return result;
1199 }
1200 
1201 
1202 MaybeHandle<Object> Factory::NewError(Handle<String> message) {
1203  return NewError("$Error", message);
1204 }
1205 
1206 
1207 MaybeHandle<Object> Factory::NewError(const char* constructor,
1208  Handle<String> message) {
1209  Handle<String> constr = InternalizeUtf8String(constructor);
1210  Handle<JSFunction> fun = Handle<JSFunction>::cast(Object::GetProperty(
1211  isolate()->js_builtins_object(), constr).ToHandleChecked());
1212  Handle<Object> argv[] = { message };
1213 
1214  // Invoke the JavaScript factory method. If an exception is thrown while
1215  // running the factory method, use the exception as the result.
1216  Handle<Object> result;
1217  MaybeHandle<Object> exception;
1218  if (!Execution::TryCall(fun,
1219  isolate()->js_builtins_object(),
1220  arraysize(argv),
1221  argv,
1222  &exception).ToHandle(&result)) {
1223  return exception;
1224  }
1225  return result;
1226 }
1227 
1228 
1229 void Factory::InitializeFunction(Handle<JSFunction> function,
1230  Handle<SharedFunctionInfo> info,
1231  Handle<Context> context) {
1232  function->initialize_properties();
1233  function->initialize_elements();
1234  function->set_shared(*info);
1235  function->set_code(info->code());
1236  function->set_context(*context);
1237  function->set_prototype_or_initial_map(*the_hole_value());
1238  function->set_literals_or_bindings(*empty_fixed_array());
1239  function->set_next_function_link(*undefined_value());
1240 }
1241 
1242 
1243 Handle<JSFunction> Factory::NewFunction(Handle<Map> map,
1244  Handle<SharedFunctionInfo> info,
1245  Handle<Context> context,
1246  PretenureFlag pretenure) {
1248  Handle<JSFunction> result = New<JSFunction>(map, space);
1249  InitializeFunction(result, info, context);
1250  return result;
1251 }
1252 
1253 
1254 Handle<JSFunction> Factory::NewFunction(Handle<Map> map,
1255  Handle<String> name,
1256  MaybeHandle<Code> code) {
1257  Handle<Context> context(isolate()->native_context());
1258  Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name, code);
1259  DCHECK((info->strict_mode() == SLOPPY) &&
1260  (map.is_identical_to(isolate()->sloppy_function_map()) ||
1261  map.is_identical_to(
1262  isolate()->sloppy_function_without_prototype_map()) ||
1263  map.is_identical_to(
1264  isolate()->sloppy_function_with_readonly_prototype_map())));
1265  return NewFunction(map, info, context);
1266 }
1267 
1268 
1269 Handle<JSFunction> Factory::NewFunction(Handle<String> name) {
1270  return NewFunction(
1271  isolate()->sloppy_function_map(), name, MaybeHandle<Code>());
1272 }
1273 
1274 
1275 Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name,
1276  Handle<Code> code) {
1277  return NewFunction(
1278  isolate()->sloppy_function_without_prototype_map(), name, code);
1279 }
1280 
1281 
1282 Handle<JSFunction> Factory::NewFunction(Handle<String> name,
1283  Handle<Code> code,
1284  Handle<Object> prototype,
1285  bool read_only_prototype) {
1286  Handle<Map> map = read_only_prototype
1287  ? isolate()->sloppy_function_with_readonly_prototype_map()
1288  : isolate()->sloppy_function_map();
1289  Handle<JSFunction> result = NewFunction(map, name, code);
1290  result->set_prototype_or_initial_map(*prototype);
1291  return result;
1292 }
1293 
1294 
1295 Handle<JSFunction> Factory::NewFunction(Handle<String> name,
1296  Handle<Code> code,
1297  Handle<Object> prototype,
1298  InstanceType type,
1299  int instance_size,
1300  bool read_only_prototype) {
1301  // Allocate the function
1302  Handle<JSFunction> function = NewFunction(
1303  name, code, prototype, read_only_prototype);
1304 
1305  ElementsKind elements_kind =
1307  Handle<Map> initial_map = NewMap(type, instance_size, elements_kind);
1308  if (prototype->IsTheHole() && !function->shared()->is_generator()) {
1309  prototype = NewFunctionPrototype(function);
1310  }
1311 
1312  JSFunction::SetInitialMap(function, initial_map,
1313  Handle<JSReceiver>::cast(prototype));
1314 
1315  return function;
1316 }
1317 
1318 
1319 Handle<JSFunction> Factory::NewFunction(Handle<String> name,
1320  Handle<Code> code,
1321  InstanceType type,
1322  int instance_size) {
1323  return NewFunction(name, code, the_hole_value(), type, instance_size);
1324 }
1325 
1326 
1327 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
1328  // Make sure to use globals from the function's context, since the function
1329  // can be from a different context.
1330  Handle<Context> native_context(function->context()->native_context());
1331  Handle<Map> new_map;
1332  if (function->shared()->is_generator()) {
1333  // Generator prototypes can share maps since they don't have "constructor"
1334  // properties.
1335  new_map = handle(native_context->generator_object_prototype_map());
1336  } else {
1337  // Each function prototype gets a fresh map to avoid unwanted sharing of
1338  // maps between prototypes of different constructors.
1339  Handle<JSFunction> object_function(native_context->object_function());
1340  DCHECK(object_function->has_initial_map());
1341  new_map = handle(object_function->initial_map());
1342  }
1343 
1344  DCHECK(!new_map->is_prototype_map());
1345  Handle<JSObject> prototype = NewJSObjectFromMap(new_map);
1346 
1347  if (!function->shared()->is_generator()) {
1348  JSObject::AddProperty(prototype, constructor_string(), function, DONT_ENUM);
1349  }
1350 
1351  return prototype;
1352 }
1353 
1354 
1355 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
1356  Handle<SharedFunctionInfo> info,
1357  Handle<Context> context,
1358  PretenureFlag pretenure) {
1359  int map_index = Context::FunctionMapIndex(info->strict_mode(), info->kind());
1360  Handle<Map> map(Map::cast(context->native_context()->get(map_index)));
1361  Handle<JSFunction> result = NewFunction(map, info, context, pretenure);
1362 
1363  if (info->ic_age() != isolate()->heap()->global_ic_age()) {
1364  info->ResetForNewContext(isolate()->heap()->global_ic_age());
1365  }
1366 
1367  int index = info->SearchOptimizedCodeMap(context->native_context(),
1368  BailoutId::None());
1369  if (!info->bound() && index < 0) {
1370  int number_of_literals = info->num_literals();
1371  Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure);
1372  if (number_of_literals > 0) {
1373  // Store the native context in the literals array prefix. This
1374  // context will be used when creating object, regexp and array
1375  // literals in this function.
1377  context->native_context());
1378  }
1379  result->set_literals(*literals);
1380  }
1381 
1382  if (index > 0) {
1383  // Caching of optimized code enabled and optimized code found.
1384  FixedArray* literals = info->GetLiteralsFromOptimizedCodeMap(index);
1385  if (literals != NULL) result->set_literals(literals);
1386  Code* code = info->GetCodeFromOptimizedCodeMap(index);
1387  DCHECK(!code->marked_for_deoptimization());
1388  result->ReplaceCode(code);
1389  return result;
1390  }
1391 
1392  if (isolate()->use_crankshaft() &&
1393  FLAG_always_opt &&
1394  result->is_compiled() &&
1395  !info->is_toplevel() &&
1396  info->allows_lazy_compilation() &&
1397  !info->optimization_disabled() &&
1398  !isolate()->DebuggerHasBreakPoints()) {
1399  result->MarkForOptimization();
1400  }
1401  return result;
1402 }
1403 
1404 
1405 Handle<ScopeInfo> Factory::NewScopeInfo(int length) {
1406  Handle<FixedArray> array = NewFixedArray(length, TENURED);
1407  array->set_map_no_write_barrier(*scope_info_map());
1408  Handle<ScopeInfo> scope_info = Handle<ScopeInfo>::cast(array);
1409  return scope_info;
1410 }
1411 
1412 
1413 Handle<JSObject> Factory::NewExternal(void* value) {
1414  Handle<Foreign> foreign = NewForeign(static_cast<Address>(value));
1415  Handle<JSObject> external = NewJSObjectFromMap(external_map());
1416  external->SetInternalField(0, *foreign);
1417  return external;
1418 }
1419 
1420 
1421 Handle<Code> Factory::NewCodeRaw(int object_size, bool immovable) {
1422  CALL_HEAP_FUNCTION(isolate(),
1423  isolate()->heap()->AllocateCode(object_size, immovable),
1424  Code);
1425 }
1426 
1427 
1428 Handle<Code> Factory::NewCode(const CodeDesc& desc,
1430  Handle<Object> self_ref,
1431  bool immovable,
1432  bool crankshafted,
1433  int prologue_offset,
1434  bool is_debug) {
1435  Handle<ByteArray> reloc_info = NewByteArray(desc.reloc_size, TENURED);
1436  Handle<ConstantPoolArray> constant_pool =
1437  desc.origin->NewConstantPool(isolate());
1438 
1439  // Compute size.
1440  int body_size = RoundUp(desc.instr_size, kObjectAlignment);
1441  int obj_size = Code::SizeFor(body_size);
1442 
1443  Handle<Code> code = NewCodeRaw(obj_size, immovable);
1444  DCHECK(isolate()->code_range() == NULL ||
1445  !isolate()->code_range()->valid() ||
1446  isolate()->code_range()->contains(code->address()));
1447 
1448  // The code object has not been fully initialized yet. We rely on the
1449  // fact that no allocation will happen from this point on.
1450  DisallowHeapAllocation no_gc;
1451  code->set_gc_metadata(Smi::FromInt(0));
1452  code->set_ic_age(isolate()->heap()->global_ic_age());
1453  code->set_instruction_size(desc.instr_size);
1454  code->set_relocation_info(*reloc_info);
1455  code->set_flags(flags);
1456  code->set_raw_kind_specific_flags1(0);
1457  code->set_raw_kind_specific_flags2(0);
1458  code->set_is_crankshafted(crankshafted);
1459  code->set_deoptimization_data(*empty_fixed_array(), SKIP_WRITE_BARRIER);
1460  code->set_raw_type_feedback_info(Smi::FromInt(0));
1461  code->set_next_code_link(*undefined_value());
1462  code->set_handler_table(*empty_fixed_array(), SKIP_WRITE_BARRIER);
1463  code->set_prologue_offset(prologue_offset);
1464  if (code->kind() == Code::OPTIMIZED_FUNCTION) {
1465  code->set_marked_for_deoptimization(false);
1466  }
1467 
1468  if (is_debug) {
1469  DCHECK(code->kind() == Code::FUNCTION);
1470  code->set_has_debug_break_slots(true);
1471  }
1472 
1473  desc.origin->PopulateConstantPool(*constant_pool);
1474  code->set_constant_pool(*constant_pool);
1475 
1476  // Allow self references to created code object by patching the handle to
1477  // point to the newly allocated Code object.
1478  if (!self_ref.is_null()) *(self_ref.location()) = *code;
1479 
1480  // Migrate generated code.
1481  // The generated code can contain Object** values (typically from handles)
1482  // that are dereferenced during the copy to point directly to the actual heap
1483  // objects. These pointers can include references to the code object itself,
1484  // through the self_reference parameter.
1485  code->CopyFrom(desc);
1486 
1487 #ifdef VERIFY_HEAP
1488  if (FLAG_verify_heap) code->ObjectVerify();
1489 #endif
1490  return code;
1491 }
1492 
1493 
1494 Handle<Code> Factory::CopyCode(Handle<Code> code) {
1495  CALL_HEAP_FUNCTION(isolate(),
1496  isolate()->heap()->CopyCode(*code),
1497  Code);
1498 }
1499 
1500 
1501 Handle<Code> Factory::CopyCode(Handle<Code> code, Vector<byte> reloc_info) {
1502  CALL_HEAP_FUNCTION(isolate(),
1503  isolate()->heap()->CopyCode(*code, reloc_info),
1504  Code);
1505 }
1506 
1507 
1508 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor,
1509  PretenureFlag pretenure) {
1510  JSFunction::EnsureHasInitialMap(constructor);
1512  isolate(),
1513  isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject);
1514 }
1515 
1516 
1517 Handle<JSObject> Factory::NewJSObjectWithMemento(
1518  Handle<JSFunction> constructor,
1519  Handle<AllocationSite> site) {
1520  JSFunction::EnsureHasInitialMap(constructor);
1522  isolate(),
1523  isolate()->heap()->AllocateJSObject(*constructor, NOT_TENURED, *site),
1524  JSObject);
1525 }
1526 
1527 
1528 Handle<JSModule> Factory::NewJSModule(Handle<Context> context,
1529  Handle<ScopeInfo> scope_info) {
1530  // Allocate a fresh map. Modules do not have a prototype.
1531  Handle<Map> map = NewMap(JS_MODULE_TYPE, JSModule::kSize);
1532  // Allocate the object based on the map.
1533  Handle<JSModule> module =
1534  Handle<JSModule>::cast(NewJSObjectFromMap(map, TENURED));
1535  module->set_context(*context);
1536  module->set_scope_info(*scope_info);
1537  return module;
1538 }
1539 
1540 
1541 Handle<GlobalObject> Factory::NewGlobalObject(Handle<JSFunction> constructor) {
1542  DCHECK(constructor->has_initial_map());
1543  Handle<Map> map(constructor->initial_map());
1544  DCHECK(map->is_dictionary_map());
1545 
1546  // Make sure no field properties are described in the initial map.
1547  // This guarantees us that normalizing the properties does not
1548  // require us to change property values to PropertyCells.
1549  DCHECK(map->NextFreePropertyIndex() == 0);
1550 
1551  // Make sure we don't have a ton of pre-allocated slots in the
1552  // global objects. They will be unused once we normalize the object.
1553  DCHECK(map->unused_property_fields() == 0);
1554  DCHECK(map->inobject_properties() == 0);
1555 
1556  // Initial size of the backing store to avoid resize of the storage during
1557  // bootstrapping. The size differs between the JS global object ad the
1558  // builtins object.
1559  int initial_size = map->instance_type() == JS_GLOBAL_OBJECT_TYPE ? 64 : 512;
1560 
1561  // Allocate a dictionary object for backing storage.
1562  int at_least_space_for = map->NumberOfOwnDescriptors() * 2 + initial_size;
1563  Handle<NameDictionary> dictionary =
1564  NameDictionary::New(isolate(), at_least_space_for);
1565 
1566  // The global object might be created from an object template with accessors.
1567  // Fill these accessors into the dictionary.
1568  Handle<DescriptorArray> descs(map->instance_descriptors());
1569  for (int i = 0; i < map->NumberOfOwnDescriptors(); i++) {
1570  PropertyDetails details = descs->GetDetails(i);
1571  DCHECK(details.type() == CALLBACKS); // Only accessors are expected.
1572  PropertyDetails d = PropertyDetails(details.attributes(), CALLBACKS, i + 1);
1573  Handle<Name> name(descs->GetKey(i));
1574  Handle<Object> value(descs->GetCallbacksObject(i), isolate());
1575  Handle<PropertyCell> cell = NewPropertyCell(value);
1576  // |dictionary| already contains enough space for all properties.
1577  USE(NameDictionary::Add(dictionary, name, cell, d));
1578  }
1579 
1580  // Allocate the global object and initialize it with the backing store.
1581  Handle<GlobalObject> global = New<GlobalObject>(map, OLD_POINTER_SPACE);
1582  isolate()->heap()->InitializeJSObjectFromMap(*global, *dictionary, *map);
1583 
1584  // Create a new map for the global object.
1585  Handle<Map> new_map = Map::CopyDropDescriptors(map);
1586  new_map->set_dictionary_map(true);
1587 
1588  // Set up the global object as a normalized object.
1589  global->set_map(*new_map);
1590  global->set_properties(*dictionary);
1591 
1592  // Make sure result is a global object with properties in dictionary.
1593  DCHECK(global->IsGlobalObject() && !global->HasFastProperties());
1594  return global;
1595 }
1596 
1597 
1598 Handle<JSObject> Factory::NewJSObjectFromMap(
1599  Handle<Map> map,
1600  PretenureFlag pretenure,
1601  bool alloc_props,
1602  Handle<AllocationSite> allocation_site) {
1604  isolate(),
1605  isolate()->heap()->AllocateJSObjectFromMap(
1606  *map,
1607  pretenure,
1608  alloc_props,
1609  allocation_site.is_null() ? NULL : *allocation_site),
1610  JSObject);
1611 }
1612 
1613 
1614 Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind,
1615  PretenureFlag pretenure) {
1616  Context* native_context = isolate()->context()->native_context();
1617  JSFunction* array_function = native_context->array_function();
1618  Map* map = array_function->initial_map();
1619  Map* transition_map = isolate()->get_initial_js_array_map(elements_kind);
1620  if (transition_map != NULL) map = transition_map;
1621  return Handle<JSArray>::cast(NewJSObjectFromMap(handle(map), pretenure));
1622 }
1623 
1624 
1625 Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind,
1626  int length,
1627  int capacity,
1629  PretenureFlag pretenure) {
1630  Handle<JSArray> array = NewJSArray(elements_kind, pretenure);
1631  NewJSArrayStorage(array, length, capacity, mode);
1632  return array;
1633 }
1634 
1635 
1636 Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
1637  ElementsKind elements_kind,
1638  int length,
1639  PretenureFlag pretenure) {
1640  DCHECK(length <= elements->length());
1641  Handle<JSArray> array = NewJSArray(elements_kind, pretenure);
1642 
1643  array->set_elements(*elements);
1644  array->set_length(Smi::FromInt(length));
1646  return array;
1647 }
1648 
1649 
1650 void Factory::NewJSArrayStorage(Handle<JSArray> array,
1651  int length,
1652  int capacity,
1654  DCHECK(capacity >= length);
1655 
1656  if (capacity == 0) {
1657  array->set_length(Smi::FromInt(0));
1658  array->set_elements(*empty_fixed_array());
1659  return;
1660  }
1661 
1662  Handle<FixedArrayBase> elms;
1663  ElementsKind elements_kind = array->GetElementsKind();
1664  if (IsFastDoubleElementsKind(elements_kind)) {
1666  elms = NewFixedDoubleArray(capacity);
1667  } else {
1669  elms = NewFixedDoubleArrayWithHoles(capacity);
1670  }
1671  } else {
1672  DCHECK(IsFastSmiOrObjectElementsKind(elements_kind));
1674  elms = NewUninitializedFixedArray(capacity);
1675  } else {
1677  elms = NewFixedArrayWithHoles(capacity);
1678  }
1679  }
1680 
1681  array->set_elements(*elms);
1682  array->set_length(Smi::FromInt(length));
1683 }
1684 
1685 
1686 Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
1687  Handle<JSFunction> function) {
1688  DCHECK(function->shared()->is_generator());
1690  Handle<Map> map(function->initial_map());
1691  DCHECK(map->instance_type() == JS_GENERATOR_OBJECT_TYPE);
1693  isolate(),
1694  isolate()->heap()->AllocateJSObjectFromMap(*map),
1695  JSGeneratorObject);
1696 }
1697 
1698 
1699 Handle<JSArrayBuffer> Factory::NewJSArrayBuffer() {
1700  Handle<JSFunction> array_buffer_fun(
1701  isolate()->native_context()->array_buffer_fun());
1703  isolate(),
1704  isolate()->heap()->AllocateJSObject(*array_buffer_fun),
1705  JSArrayBuffer);
1706 }
1707 
1708 
1709 Handle<JSDataView> Factory::NewJSDataView() {
1710  Handle<JSFunction> data_view_fun(
1711  isolate()->native_context()->data_view_fun());
1713  isolate(),
1714  isolate()->heap()->AllocateJSObject(*data_view_fun),
1715  JSDataView);
1716 }
1717 
1718 
1720  Isolate* isolate) {
1721  Context* native_context = isolate->context()->native_context();
1722  switch (type) {
1723 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \
1724  case kExternal##Type##Array: \
1725  return native_context->type##_array_fun();
1726 
1728 #undef TYPED_ARRAY_FUN
1729 
1730  default:
1731  UNREACHABLE();
1732  return NULL;
1733  }
1734 }
1735 
1736 
1737 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) {
1738  Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate()));
1739 
1741  isolate(),
1742  isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
1743  JSTypedArray);
1744 }
1745 
1746 
1747 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler,
1748  Handle<Object> prototype) {
1749  // Allocate map.
1750  // TODO(rossberg): Once we optimize proxies, think about a scheme to share
1751  // maps. Will probably depend on the identity of the handler object, too.
1752  Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize);
1753  map->set_prototype(*prototype);
1754 
1755  // Allocate the proxy object.
1756  Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE);
1757  result->InitializeBody(map->instance_size(), Smi::FromInt(0));
1758  result->set_handler(*handler);
1759  result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER);
1760  return result;
1761 }
1762 
1763 
1764 Handle<JSProxy> Factory::NewJSFunctionProxy(Handle<Object> handler,
1765  Handle<Object> call_trap,
1766  Handle<Object> construct_trap,
1767  Handle<Object> prototype) {
1768  // Allocate map.
1769  // TODO(rossberg): Once we optimize proxies, think about a scheme to share
1770  // maps. Will probably depend on the identity of the handler object, too.
1771  Handle<Map> map = NewMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize);
1772  map->set_prototype(*prototype);
1773 
1774  // Allocate the proxy object.
1775  Handle<JSFunctionProxy> result = New<JSFunctionProxy>(map, NEW_SPACE);
1776  result->InitializeBody(map->instance_size(), Smi::FromInt(0));
1777  result->set_handler(*handler);
1778  result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER);
1779  result->set_call_trap(*call_trap);
1780  result->set_construct_trap(*construct_trap);
1781  return result;
1782 }
1783 
1784 
1785 void Factory::ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type,
1786  int size) {
1787  DCHECK(type == JS_OBJECT_TYPE || type == JS_FUNCTION_TYPE);
1788 
1789  // Allocate fresh map.
1790  // TODO(rossberg): Once we optimize proxies, cache these maps.
1791  Handle<Map> map = NewMap(type, size);
1792 
1793  // Check that the receiver has at least the size of the fresh object.
1794  int size_difference = proxy->map()->instance_size() - map->instance_size();
1795  DCHECK(size_difference >= 0);
1796 
1797  map->set_prototype(proxy->map()->prototype());
1798 
1799  // Allocate the backing storage for the properties.
1800  int prop_size = map->InitialPropertiesLength();
1801  Handle<FixedArray> properties = NewFixedArray(prop_size, TENURED);
1802 
1803  Heap* heap = isolate()->heap();
1804  MaybeHandle<SharedFunctionInfo> shared;
1805  if (type == JS_FUNCTION_TYPE) {
1806  OneByteStringKey key(STATIC_CHAR_VECTOR("<freezing call trap>"),
1807  heap->HashSeed());
1808  Handle<String> name = InternalizeStringWithKey(&key);
1809  shared = NewSharedFunctionInfo(name, MaybeHandle<Code>());
1810  }
1811 
1812  // In order to keep heap in consistent state there must be no allocations
1813  // before object re-initialization is finished and filler object is installed.
1814  DisallowHeapAllocation no_allocation;
1815 
1816  // Put in filler if the new object is smaller than the old.
1817  if (size_difference > 0) {
1818  Address address = proxy->address();
1819  heap->CreateFillerObjectAt(address + map->instance_size(), size_difference);
1820  heap->AdjustLiveBytes(address, -size_difference, Heap::FROM_MUTATOR);
1821  }
1822 
1823  // Reset the map for the object.
1824  proxy->synchronized_set_map(*map);
1825  Handle<JSObject> jsobj = Handle<JSObject>::cast(proxy);
1826 
1827  // Reinitialize the object from the constructor map.
1828  heap->InitializeJSObjectFromMap(*jsobj, *properties, *map);
1829 
1830  // The current native context is used to set up certain bits.
1831  // TODO(adamk): Using the current context seems wrong, it should be whatever
1832  // context the JSProxy originated in. But that context isn't stored anywhere.
1833  Handle<Context> context(isolate()->native_context());
1834 
1835  // Functions require some minimal initialization.
1836  if (type == JS_FUNCTION_TYPE) {
1837  map->set_function_with_prototype(true);
1838  Handle<JSFunction> js_function = Handle<JSFunction>::cast(proxy);
1839  InitializeFunction(js_function, shared.ToHandleChecked(), context);
1840  } else {
1841  // Provide JSObjects with a constructor.
1842  map->set_constructor(context->object_function());
1843  }
1844 }
1845 
1846 
1847 void Factory::ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> object,
1848  Handle<JSFunction> constructor) {
1849  DCHECK(constructor->has_initial_map());
1850  Handle<Map> map(constructor->initial_map(), isolate());
1851 
1852  // The proxy's hash should be retained across reinitialization.
1853  Handle<Object> hash(object->hash(), isolate());
1854 
1855  // Check that the already allocated object has the same size and type as
1856  // objects allocated using the constructor.
1857  DCHECK(map->instance_size() == object->map()->instance_size());
1858  DCHECK(map->instance_type() == object->map()->instance_type());
1859 
1860  // Allocate the backing storage for the properties.
1861  int prop_size = map->InitialPropertiesLength();
1862  Handle<FixedArray> properties = NewFixedArray(prop_size, TENURED);
1863 
1864  // In order to keep heap in consistent state there must be no allocations
1865  // before object re-initialization is finished.
1866  DisallowHeapAllocation no_allocation;
1867 
1868  // Reset the map for the object.
1869  object->synchronized_set_map(*map);
1870 
1871  Heap* heap = isolate()->heap();
1872  // Reinitialize the object from the constructor map.
1873  heap->InitializeJSObjectFromMap(*object, *properties, *map);
1874 
1875  // Restore the saved hash.
1876  object->set_hash(*hash);
1877 }
1878 
1879 
1880 void Factory::BecomeJSObject(Handle<JSProxy> proxy) {
1881  ReinitializeJSProxy(proxy, JS_OBJECT_TYPE, JSObject::kHeaderSize);
1882 }
1883 
1884 
1885 void Factory::BecomeJSFunction(Handle<JSProxy> proxy) {
1886  ReinitializeJSProxy(proxy, JS_FUNCTION_TYPE, JSFunction::kSize);
1887 }
1888 
1889 
1890 Handle<TypeFeedbackVector> Factory::NewTypeFeedbackVector(int slot_count) {
1891  // Ensure we can skip the write barrier
1892  DCHECK_EQ(isolate()->heap()->uninitialized_symbol(),
1894 
1895  if (slot_count == 0) {
1896  return Handle<TypeFeedbackVector>::cast(empty_fixed_array());
1897  }
1898 
1899  CALL_HEAP_FUNCTION(isolate(),
1900  isolate()->heap()->AllocateFixedArrayWithFiller(
1901  slot_count, TENURED,
1904 }
1905 
1906 
1907 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
1908  Handle<String> name, int number_of_literals, FunctionKind kind,
1909  Handle<Code> code, Handle<ScopeInfo> scope_info,
1910  Handle<TypeFeedbackVector> feedback_vector) {
1911  DCHECK(IsValidFunctionKind(kind));
1912  Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name, code);
1913  shared->set_scope_info(*scope_info);
1914  shared->set_feedback_vector(*feedback_vector);
1915  shared->set_kind(kind);
1916  int literals_array_size = number_of_literals;
1917  // If the function contains object, regexp or array literals,
1918  // allocate extra space for a literals array prefix containing the
1919  // context.
1920  if (number_of_literals > 0) {
1921  literals_array_size += JSFunction::kLiteralsPrefixSize;
1922  }
1923  shared->set_num_literals(literals_array_size);
1924  if (IsGeneratorFunction(kind)) {
1925  shared->set_instance_class_name(isolate()->heap()->Generator_string());
1926  shared->DisableOptimization(kGenerator);
1927  }
1928  return shared;
1929 }
1930 
1931 
1932 Handle<JSMessageObject> Factory::NewJSMessageObject(
1933  Handle<String> type,
1934  Handle<JSArray> arguments,
1935  int start_position,
1936  int end_position,
1937  Handle<Object> script,
1938  Handle<Object> stack_frames) {
1939  Handle<Map> map = message_object_map();
1940  Handle<JSMessageObject> message = New<JSMessageObject>(map, NEW_SPACE);
1941  message->set_properties(*empty_fixed_array(), SKIP_WRITE_BARRIER);
1942  message->initialize_elements();
1943  message->set_elements(*empty_fixed_array(), SKIP_WRITE_BARRIER);
1944  message->set_type(*type);
1945  message->set_arguments(*arguments);
1946  message->set_start_position(start_position);
1947  message->set_end_position(end_position);
1948  message->set_script(*script);
1949  message->set_stack_frames(*stack_frames);
1950  return message;
1951 }
1952 
1953 
1954 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
1955  Handle<String> name,
1956  MaybeHandle<Code> maybe_code) {
1957  Handle<Map> map = shared_function_info_map();
1958  Handle<SharedFunctionInfo> share = New<SharedFunctionInfo>(map,
1960 
1961  // Set pointer fields.
1962  share->set_name(*name);
1963  Handle<Code> code;
1964  if (!maybe_code.ToHandle(&code)) {
1965  code = handle(isolate()->builtins()->builtin(Builtins::kIllegal));
1966  }
1967  share->set_code(*code);
1968  share->set_optimized_code_map(Smi::FromInt(0));
1969  share->set_scope_info(ScopeInfo::Empty(isolate()));
1970  Code* construct_stub =
1971  isolate()->builtins()->builtin(Builtins::kJSConstructStubGeneric);
1972  share->set_construct_stub(construct_stub);
1973  share->set_instance_class_name(*Object_string());
1974  share->set_function_data(*undefined_value(), SKIP_WRITE_BARRIER);
1975  share->set_script(*undefined_value(), SKIP_WRITE_BARRIER);
1976  share->set_debug_info(*undefined_value(), SKIP_WRITE_BARRIER);
1977  share->set_inferred_name(*empty_string(), SKIP_WRITE_BARRIER);
1978  Handle<TypeFeedbackVector> feedback_vector = NewTypeFeedbackVector(0);
1979  share->set_feedback_vector(*feedback_vector, SKIP_WRITE_BARRIER);
1980  share->set_profiler_ticks(0);
1981  share->set_ast_node_count(0);
1982  share->set_counters(0);
1983 
1984  // Set integer fields (smi or int, depending on the architecture).
1985  share->set_length(0);
1986  share->set_formal_parameter_count(0);
1987  share->set_expected_nof_properties(0);
1988  share->set_num_literals(0);
1989  share->set_start_position_and_type(0);
1990  share->set_end_position(0);
1991  share->set_function_token_position(0);
1992  // All compiler hints default to false or 0.
1993  share->set_compiler_hints(0);
1994  share->set_opt_count_and_bailout_reason(0);
1995 
1996  return share;
1997 }
1998 
1999 
2000 static inline int NumberCacheHash(Handle<FixedArray> cache,
2001  Handle<Object> number) {
2002  int mask = (cache->length() >> 1) - 1;
2003  if (number->IsSmi()) {
2004  return Handle<Smi>::cast(number)->value() & mask;
2005  } else {
2006  DoubleRepresentation rep(number->Number());
2007  return
2008  (static_cast<int>(rep.bits) ^ static_cast<int>(rep.bits >> 32)) & mask;
2009  }
2010 }
2011 
2012 
2013 Handle<Object> Factory::GetNumberStringCache(Handle<Object> number) {
2014  DisallowHeapAllocation no_gc;
2015  int hash = NumberCacheHash(number_string_cache(), number);
2016  Object* key = number_string_cache()->get(hash * 2);
2017  if (key == *number || (key->IsHeapNumber() && number->IsHeapNumber() &&
2018  key->Number() == number->Number())) {
2019  return Handle<String>(
2020  String::cast(number_string_cache()->get(hash * 2 + 1)), isolate());
2021  }
2022  return undefined_value();
2023 }
2024 
2025 
2026 void Factory::SetNumberStringCache(Handle<Object> number,
2027  Handle<String> string) {
2028  int hash = NumberCacheHash(number_string_cache(), number);
2029  if (number_string_cache()->get(hash * 2) != *undefined_value()) {
2030  int full_size = isolate()->heap()->FullSizeNumberStringCacheLength();
2031  if (number_string_cache()->length() != full_size) {
2032  // The first time we have a hash collision, we move to the full sized
2033  // number string cache. The idea is to have a small number string
2034  // cache in the snapshot to keep boot-time memory usage down.
2035  // If we expand the number string cache already while creating
2036  // the snapshot then that didn't work out.
2037  DCHECK(!isolate()->serializer_enabled() || FLAG_extra_code != NULL);
2038  Handle<FixedArray> new_cache = NewFixedArray(full_size, TENURED);
2039  isolate()->heap()->set_number_string_cache(*new_cache);
2040  return;
2041  }
2042  }
2043  number_string_cache()->set(hash * 2, *number);
2044  number_string_cache()->set(hash * 2 + 1, *string);
2045 }
2046 
2047 
2048 Handle<String> Factory::NumberToString(Handle<Object> number,
2049  bool check_number_string_cache) {
2050  isolate()->counters()->number_to_string_runtime()->Increment();
2051  if (check_number_string_cache) {
2052  Handle<Object> cached = GetNumberStringCache(number);
2053  if (!cached->IsUndefined()) return Handle<String>::cast(cached);
2054  }
2055 
2056  char arr[100];
2057  Vector<char> buffer(arr, arraysize(arr));
2058  const char* str;
2059  if (number->IsSmi()) {
2060  int num = Handle<Smi>::cast(number)->value();
2061  str = IntToCString(num, buffer);
2062  } else {
2063  double num = Handle<HeapNumber>::cast(number)->value();
2064  str = DoubleToCString(num, buffer);
2065  }
2066 
2067  // We tenure the allocated string since it is referenced from the
2068  // number-string cache which lives in the old space.
2069  Handle<String> js_string = NewStringFromAsciiChecked(str, TENURED);
2070  SetNumberStringCache(number, js_string);
2071  return js_string;
2072 }
2073 
2074 
2075 Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) {
2076  // Get the original code of the function.
2077  Handle<Code> code(shared->code());
2078 
2079  // Create a copy of the code before allocating the debug info object to avoid
2080  // allocation while setting up the debug info object.
2081  Handle<Code> original_code(*Factory::CopyCode(code));
2082 
2083  // Allocate initial fixed array for active break points before allocating the
2084  // debug info object to avoid allocation while setting up the debug info
2085  // object.
2086  Handle<FixedArray> break_points(
2088 
2089  // Create and set up the debug info object. Debug info contains function, a
2090  // copy of the original code, the executing code and initial fixed array for
2091  // active break points.
2092  Handle<DebugInfo> debug_info =
2094  debug_info->set_shared(*shared);
2095  debug_info->set_original_code(*original_code);
2096  debug_info->set_code(*code);
2097  debug_info->set_break_points(*break_points);
2098 
2099  // Link debug info to function.
2100  shared->set_debug_info(*debug_info);
2101 
2102  return debug_info;
2103 }
2104 
2105 
2106 Handle<JSObject> Factory::NewArgumentsObject(Handle<JSFunction> callee,
2107  int length) {
2108  bool strict_mode_callee = callee->shared()->strict_mode() == STRICT;
2109  Handle<Map> map = strict_mode_callee ? isolate()->strict_arguments_map()
2110  : isolate()->sloppy_arguments_map();
2111 
2112  AllocationSiteUsageContext context(isolate(), Handle<AllocationSite>(),
2113  false);
2114  DCHECK(!isolate()->has_pending_exception());
2115  Handle<JSObject> result = NewJSObjectFromMap(map);
2116  Handle<Smi> value(Smi::FromInt(length), isolate());
2117  Object::SetProperty(result, length_string(), value, STRICT).Assert();
2118  if (!strict_mode_callee) {
2119  Object::SetProperty(result, callee_string(), callee, STRICT).Assert();
2120  }
2121  return result;
2122 }
2123 
2124 
2125 Handle<JSFunction> Factory::CreateApiFunction(
2126  Handle<FunctionTemplateInfo> obj,
2127  Handle<Object> prototype,
2128  ApiInstanceType instance_type) {
2129  Handle<Code> code = isolate()->builtins()->HandleApiCall();
2130  Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi();
2131 
2132  Handle<JSFunction> result;
2133  if (obj->remove_prototype()) {
2134  result = NewFunctionWithoutPrototype(empty_string(), code);
2135  } else {
2136  int internal_field_count = 0;
2137  if (!obj->instance_template()->IsUndefined()) {
2138  Handle<ObjectTemplateInfo> instance_template =
2139  Handle<ObjectTemplateInfo>(
2140  ObjectTemplateInfo::cast(obj->instance_template()));
2142  Smi::cast(instance_template->internal_field_count())->value();
2143  }
2144 
2145  // TODO(svenpanne) Kill ApiInstanceType and refactor things by generalizing
2146  // JSObject::GetHeaderSize.
2147  int instance_size = kPointerSize * internal_field_count;
2148  InstanceType type;
2149  switch (instance_type) {
2150  case JavaScriptObjectType:
2151  type = JS_OBJECT_TYPE;
2152  instance_size += JSObject::kHeaderSize;
2153  break;
2154  case GlobalObjectType:
2155  type = JS_GLOBAL_OBJECT_TYPE;
2156  instance_size += JSGlobalObject::kSize;
2157  break;
2158  case GlobalProxyType:
2159  type = JS_GLOBAL_PROXY_TYPE;
2160  instance_size += JSGlobalProxy::kSize;
2161  break;
2162  default:
2163  UNREACHABLE();
2164  type = JS_OBJECT_TYPE; // Keep the compiler happy.
2165  break;
2166  }
2167 
2168  result = NewFunction(empty_string(), code, prototype, type,
2169  instance_size, obj->read_only_prototype());
2170  }
2171 
2172  result->shared()->set_length(obj->length());
2173  Handle<Object> class_name(obj->class_name(), isolate());
2174  if (class_name->IsString()) {
2175  result->shared()->set_instance_class_name(*class_name);
2176  result->shared()->set_name(*class_name);
2177  }
2178  result->shared()->set_function_data(*obj);
2179  result->shared()->set_construct_stub(*construct_stub);
2180  result->shared()->DontAdaptArguments();
2181 
2182  if (obj->remove_prototype()) {
2183  DCHECK(result->shared()->IsApiFunction());
2184  DCHECK(!result->has_initial_map());
2185  DCHECK(!result->has_prototype());
2186  return result;
2187  }
2188 
2189  if (prototype->IsTheHole()) {
2190 #ifdef DEBUG
2191  LookupIterator it(handle(JSObject::cast(result->prototype())),
2192  constructor_string(),
2193  LookupIterator::OWN_SKIP_INTERCEPTOR);
2194  MaybeHandle<Object> maybe_prop = Object::GetProperty(&it);
2195  DCHECK(it.IsFound());
2196  DCHECK(maybe_prop.ToHandleChecked().is_identical_to(result));
2197 #endif
2198  } else {
2199  JSObject::AddProperty(handle(JSObject::cast(result->prototype())),
2200  constructor_string(), result, DONT_ENUM);
2201  }
2202 
2203  // Down from here is only valid for API functions that can be used as a
2204  // constructor (don't set the "remove prototype" flag).
2205 
2206  Handle<Map> map(result->initial_map());
2207 
2208  // Mark as undetectable if needed.
2209  if (obj->undetectable()) {
2210  map->set_is_undetectable();
2211  }
2212 
2213  // Mark as hidden for the __proto__ accessor if needed.
2214  if (obj->hidden_prototype()) {
2215  map->set_is_hidden_prototype();
2216  }
2217 
2218  // Mark as needs_access_check if needed.
2219  if (obj->needs_access_check()) {
2220  map->set_is_access_check_needed(true);
2221  }
2222 
2223  // Set interceptor information in the map.
2224  if (!obj->named_property_handler()->IsUndefined()) {
2225  map->set_has_named_interceptor();
2226  }
2227  if (!obj->indexed_property_handler()->IsUndefined()) {
2228  map->set_has_indexed_interceptor();
2229  }
2230 
2231  // Set instance call-as-function information in the map.
2232  if (!obj->instance_call_handler()->IsUndefined()) {
2233  map->set_has_instance_call_handler();
2234  }
2235 
2236  // Recursively copy parent instance templates' accessors,
2237  // 'data' may be modified.
2238  int max_number_of_additional_properties = 0;
2239  int max_number_of_static_properties = 0;
2240  FunctionTemplateInfo* info = *obj;
2241  while (true) {
2242  if (!info->instance_template()->IsUndefined()) {
2243  Object* props =
2244  ObjectTemplateInfo::cast(
2245  info->instance_template())->property_accessors();
2246  if (!props->IsUndefined()) {
2247  Handle<Object> props_handle(props, isolate());
2248  NeanderArray props_array(props_handle);
2249  max_number_of_additional_properties += props_array.length();
2250  }
2251  }
2252  if (!info->property_accessors()->IsUndefined()) {
2253  Object* props = info->property_accessors();
2254  if (!props->IsUndefined()) {
2255  Handle<Object> props_handle(props, isolate());
2256  NeanderArray props_array(props_handle);
2257  max_number_of_static_properties += props_array.length();
2258  }
2259  }
2260  Object* parent = info->parent_template();
2261  if (parent->IsUndefined()) break;
2262  info = FunctionTemplateInfo::cast(parent);
2263  }
2264 
2265  Map::EnsureDescriptorSlack(map, max_number_of_additional_properties);
2266 
2267  // Use a temporary FixedArray to acculumate static accessors
2268  int valid_descriptors = 0;
2269  Handle<FixedArray> array;
2270  if (max_number_of_static_properties > 0) {
2271  array = NewFixedArray(max_number_of_static_properties);
2272  }
2273 
2274  while (true) {
2275  // Install instance descriptors
2276  if (!obj->instance_template()->IsUndefined()) {
2277  Handle<ObjectTemplateInfo> instance =
2278  Handle<ObjectTemplateInfo>(
2279  ObjectTemplateInfo::cast(obj->instance_template()), isolate());
2280  Handle<Object> props = Handle<Object>(instance->property_accessors(),
2281  isolate());
2282  if (!props->IsUndefined()) {
2284  }
2285  }
2286  // Accumulate static accessors
2287  if (!obj->property_accessors()->IsUndefined()) {
2288  Handle<Object> props = Handle<Object>(obj->property_accessors(),
2289  isolate());
2290  valid_descriptors =
2291  AccessorInfo::AppendUnique(props, array, valid_descriptors);
2292  }
2293  // Climb parent chain
2294  Handle<Object> parent = Handle<Object>(obj->parent_template(), isolate());
2295  if (parent->IsUndefined()) break;
2296  obj = Handle<FunctionTemplateInfo>::cast(parent);
2297  }
2298 
2299  // Install accumulated static accessors
2300  for (int i = 0; i < valid_descriptors; i++) {
2301  Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i)));
2302  JSObject::SetAccessor(result, accessor).Assert();
2303  }
2304 
2305  DCHECK(result->shared()->IsApiFunction());
2306  return result;
2307 }
2308 
2309 
2310 Handle<MapCache> Factory::AddToMapCache(Handle<Context> context,
2311  Handle<FixedArray> keys,
2312  Handle<Map> map) {
2313  Handle<MapCache> map_cache = handle(MapCache::cast(context->map_cache()));
2314  Handle<MapCache> result = MapCache::Put(map_cache, keys, map);
2315  context->set_map_cache(*result);
2316  return result;
2317 }
2318 
2319 
2320 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
2321  Handle<FixedArray> keys) {
2322  if (context->map_cache()->IsUndefined()) {
2323  // Allocate the new map cache for the native context.
2324  Handle<MapCache> new_cache = MapCache::New(isolate(), 24);
2325  context->set_map_cache(*new_cache);
2326  }
2327  // Check to see whether there is a matching element in the cache.
2328  Handle<MapCache> cache =
2329  Handle<MapCache>(MapCache::cast(context->map_cache()));
2330  Handle<Object> result = Handle<Object>(cache->Lookup(*keys), isolate());
2331  if (result->IsMap()) return Handle<Map>::cast(result);
2332  int length = keys->length();
2333  // Create a new map and add it to the cache. Reuse the initial map of the
2334  // Object function if the literal has no predeclared properties.
2335  Handle<Map> map = length == 0
2336  ? handle(context->object_function()->initial_map())
2337  : Map::Create(isolate(), length);
2338  AddToMapCache(context, keys, map);
2339  return map;
2340 }
2341 
2342 
2343 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp,
2344  JSRegExp::Type type,
2345  Handle<String> source,
2346  JSRegExp::Flags flags,
2347  Handle<Object> data) {
2348  Handle<FixedArray> store = NewFixedArray(JSRegExp::kAtomDataSize);
2349 
2350  store->set(JSRegExp::kTagIndex, Smi::FromInt(type));
2351  store->set(JSRegExp::kSourceIndex, *source);
2352  store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value()));
2353  store->set(JSRegExp::kAtomPatternIndex, *data);
2354  regexp->set_data(*store);
2355 }
2356 
2357 void Factory::SetRegExpIrregexpData(Handle<JSRegExp> regexp,
2358  JSRegExp::Type type,
2359  Handle<String> source,
2360  JSRegExp::Flags flags,
2361  int capture_count) {
2362  Handle<FixedArray> store = NewFixedArray(JSRegExp::kIrregexpDataSize);
2363  Smi* uninitialized = Smi::FromInt(JSRegExp::kUninitializedValue);
2364  store->set(JSRegExp::kTagIndex, Smi::FromInt(type));
2365  store->set(JSRegExp::kSourceIndex, *source);
2366  store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value()));
2367  store->set(JSRegExp::kIrregexpLatin1CodeIndex, uninitialized);
2368  store->set(JSRegExp::kIrregexpUC16CodeIndex, uninitialized);
2369  store->set(JSRegExp::kIrregexpLatin1CodeSavedIndex, uninitialized);
2370  store->set(JSRegExp::kIrregexpUC16CodeSavedIndex, uninitialized);
2373  Smi::FromInt(capture_count));
2374  regexp->set_data(*store);
2375 }
2376 
2377 
2378 
2379 MaybeHandle<FunctionTemplateInfo> Factory::ConfigureInstance(
2380  Handle<FunctionTemplateInfo> desc, Handle<JSObject> instance) {
2381  // Configure the instance by adding the properties specified by the
2382  // instance template.
2383  Handle<Object> instance_template(desc->instance_template(), isolate());
2384  if (!instance_template->IsUndefined()) {
2386  isolate(),
2387  Execution::ConfigureInstance(isolate(), instance, instance_template),
2388  FunctionTemplateInfo);
2389  }
2390  return desc;
2391 }
2392 
2393 
2394 Handle<Object> Factory::GlobalConstantFor(Handle<String> name) {
2395  if (String::Equals(name, undefined_string())) return undefined_value();
2396  if (String::Equals(name, nan_string())) return nan_value();
2397  if (String::Equals(name, infinity_string())) return infinity_value();
2398  return Handle<Object>::null();
2399 }
2400 
2401 
2402 Handle<Object> Factory::ToBoolean(bool value) {
2403  return value ? true_value() : false_value();
2404 }
2405 
2406 
2407 } } // namespace v8::internal
A HandleScope which first allocates a handle in the current scope which will be later filled with the...
Definition: v8.h:855
An object reference managed by the v8 garbage collector.
Definition: v8.h:198
Isolate represents an isolated instance of the V8 engine.
Definition: v8.h:4356
A JavaScript object (ECMA-262, 4.3.3)
Definition: v8.h:2283
static int AppendUnique(Handle< Object > descriptors, Handle< FixedArray > array, int valid_descriptors)
Definition: objects.cc:3185
static BailoutId None()
Definition: utils.h:960
static int SizeFor(int body_size)
Definition: objects.h:5256
uint32_t Flags
Definition: objects.h:4929
static const int kMinLength
Definition: objects.h:9066
static int FunctionMapIndex(StrictMode strict_mode, FunctionKind kind)
Definition: contexts.h:556
Context * native_context()
Definition: contexts.cc:44
static const int kEstimatedNofBreakPointsInFunction
Definition: objects.h:10621
static MUST_USE_RESULT Handle< NameDictionary > New(Isolate *isolate, int at_least_space_for, PretenureFlag pretenure=NOT_TENURED)
Definition: objects.cc:14899
static MUST_USE_RESULT Handle< NameDictionary > Add(Handle< NameDictionary > dictionary, Handle< Name > key, Handle< Object > value, PropertyDetails details)
Definition: objects.cc:15024
v8::String::ExternalOneByteStringResource Resource
Definition: objects.h:9160
v8::String::ExternalStringResource Resource
Definition: objects.h:9196
static Handle< T > cast(Handle< S > that)
Definition: handles.h:116
static Handle< T > null()
Definition: handles.h:123
static MUST_USE_RESULT Handle< MapCache > New(Isolate *isolate, int at_least_space_for, MinimumCapacity capacity_option=USE_DEFAULT_MINIMUM_CAPACITY, PretenureFlag pretenure=NOT_TENURED)
Definition: objects.cc:13756
Context * context()
Definition: isolate.h:548
Factory * factory()
Definition: isolate.h:982
static const int kSize
Definition: objects.h:9637
static const int kLiteralNativeContextIndex
Definition: objects.h:7389
static void SetInitialMap(Handle< JSFunction > function, Handle< Map > map, Handle< Object > prototype)
Definition: objects.cc:9491
static void EnsureHasInitialMap(Handle< JSFunction > function)
Definition: objects.cc:9503
static const int kLiteralsPrefixSize
Definition: objects.h:7388
static const int kSize
Definition: objects.h:7385
static const int kSize
Definition: objects.h:7485
static const int kSize
Definition: objects.h:7429
static const int kSize
Definition: objects.h:7169
static MUST_USE_RESULT MaybeHandle< Object > SetAccessor(Handle< JSObject > object, Handle< AccessorInfo > info)
Definition: objects.cc:6188
static const int kHeaderSize
Definition: objects.h:2195
static void AddProperty(Handle< JSObject > object, Handle< Name > key, Handle< Object > value, PropertyAttributes attributes)
Definition: objects.cc:3786
static void ValidateElements(Handle< JSObject > object)
Definition: objects-inl.h:1561
static const int kSize
Definition: objects.h:9577
static const int kIrregexpUC16CodeSavedIndex
Definition: objects.h:7800
static const int kUninitializedValue
Definition: objects.h:7829
static const int kIrregexpCaptureCountIndex
Definition: objects.h:7806
static const int kFlagsIndex
Definition: objects.h:7777
static const int kIrregexpUC16CodeIndex
Definition: objects.h:7793
static const int kAtomPatternIndex
Definition: objects.h:7782
static const int kIrregexpMaxRegisterCountIndex
Definition: objects.h:7804
static const int kTagIndex
Definition: objects.h:7775
static const int kIrregexpLatin1CodeIndex
Definition: objects.h:7789
static const int kSourceIndex
Definition: objects.h:7776
static const int kIrregexpDataSize
Definition: objects.h:7808
static const int kAtomDataSize
Definition: objects.h:7784
static const int kIrregexpLatin1CodeSavedIndex
Definition: objects.h:7797
static Handle< MapCache > Put(Handle< MapCache > map_cache, Handle< FixedArray > key, Handle< Map > value)
Definition: objects.cc:14885
static void EnsureDescriptorSlack(Handle< Map > map, int slack)
Definition: objects.cc:3057
static Handle< Map > CopyDropDescriptors(Handle< Map > map)
Definition: objects.cc:6468
static void AppendCallbackDescriptors(Handle< Map > map, Handle< Object > descriptors)
Definition: objects.cc:3174
static const int kEmptyHashField
Definition: objects.h:8534
static MUST_USE_RESULT MaybeHandle< Object > GetElement(Isolate *isolate, Handle< Object > object, uint32_t index)
Definition: objects-inl.h:1113
static MUST_USE_RESULT MaybeHandle< Object > GetProperty(LookupIterator *it)
Definition: objects.cc:109
static MUST_USE_RESULT MaybeHandle< Object > SetProperty(Handle< Object > object, Handle< Name > key, Handle< Object > value, StrictMode strict_mode, StoreFromKeyed store_mode=MAY_BE_STORE_FROM_KEYED)
Definition: objects.cc:2798
static void Initialize(Isolate *isolate, Handle< Oddball > oddball, const char *to_string, Handle< Object > to_number, byte kind)
Definition: objects.cc:9596
static Handle< OrderedHashSet > Allocate(Isolate *isolate, int capacity, PretenureFlag pretenure=NOT_TENURED)
Definition: objects.cc:15412
static void SetValueInferType(Handle< PropertyCell > cell, Handle< Object > value)
Definition: objects.cc:16367
static ScopeInfo * Empty(Isolate *isolate)
Definition: scopeinfo.cc:132
static const int kMinLength
Definition: objects.h:9109
static const int kMaxValue
Definition: objects.h:1272
static Smi * FromInt(int value)
Definition: objects-inl.h:1321
static bool IsValid(intptr_t value)
Definition: objects-inl.h:1334
static Handle< String > LookupString(Isolate *isolate, Handle< String > key)
Definition: objects.cc:14706
static Handle< String > LookupKey(Isolate *isolate, HashTableKey *key)
Definition: objects.cc:14713
static MUST_USE_RESULT MaybeHandle< String > LookupTwoCharsStringIfExists(Isolate *isolate, uint16_t c1, uint16_t c2)
Definition: objects.cc:14689
static void WriteToFlat(String *source, sinkchar *sink, int from, int to)
Definition: objects.cc:8370
static int NonAsciiStart(const char *chars, int length)
Definition: objects.h:8843
static const uint32_t kMaxOneByteCharCodeU
Definition: objects.h:8812
static const int kMaxLength
Definition: objects.h:8820
static const uint32_t kMaxUtf16CodeUnitU
Definition: objects.h:8814
static Handle< String > Flatten(Handle< String > string, PretenureFlag pretenure=NOT_TENURED)
Definition: objects-inl.h:3354
static bool IsOneByte(const uc16 *chars, int length)
Definition: objects.h:8895
bool Equals(String *other)
Definition: objects-inl.h:3336
static Handle< Object > UninitializedSentinel(Isolate *isolate)
static Vector< T > cast(Vector< S > input)
Definition: vector.h:98
#define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size)
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf map
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
enable harmony numeric literals(0o77, 0b11)") DEFINE_BOOL(harmony_object_literals
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long mode(MIPS only)") DEFINE_BOOL(enable_always_align_csp
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property keys(0 means random)" "(with snapshots this option cannot override the baked-in seed)") DEFINE_BOOL(profile_deserialization
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi space(in MBytes)
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE)
Definition: heap-inl.h:634
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call, T)
Definition: isolate.h:135
#define RETURN_ON_EXCEPTION(isolate, call, T)
Definition: isolate.h:165
#define THROW_NEW_ERROR(isolate, call, T)
Definition: isolate.h:138
#define UNREACHABLE()
Definition: logging.h:30
#define DCHECK(condition)
Definition: logging.h:205
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
void USE(T)
Definition: macros.h:322
#define arraysize(array)
Definition: macros.h:86
#define MUST_USE_RESULT
Definition: macros.h:266
unsigned short uint16_t
Definition: unicode.cc:23
int int32_t
Definition: unicode.cc:24
bool IsPowerOfTwo32(uint32_t value)
Definition: bits.h:77
IN DWORD64 OUT PDWORD64 OUT PIMAGEHLP_SYMBOL64 Symbol
Vector< const char > CStrVector(const char *data)
Definition: vector.h:158
const int kPointerSize
Definition: globals.h:129
void CopyChars(sinkchar *dest, const sourcechar *src, int chars)
Definition: utils.h:1258
void StrNCpy(Vector< char > dest, const char *src, size_t n)
Definition: utils.cc:119
static bool Between(uint32_t character, uint32_t from, uint32_t to)
Definition: factory.cc:417
static Handle< String > MakeOrFindTwoCharacterString(Isolate *isolate, uint16_t c1, uint16_t c2)
Definition: factory.cc:423
bool IsValidFunctionKind(FunctionKind kind)
Definition: globals.h:784
kSerializedDataOffset kPrototypeTemplateOffset kIndexedPropertyHandlerOffset kInstanceCallHandlerOffset internal_field_count
Definition: objects-inl.h:5340
Handle< String > ConcatStringContent(Handle< StringType > result, Handle< String > first, Handle< String > second)
Definition: factory.cc:460
PerThreadAssertScopeDebugOnly< HEAP_ALLOCATION_ASSERT, false > DisallowHeapAllocation
Definition: assert-scope.h:110
@ SKIP_WRITE_BARRIER
Definition: objects.h:235
static LifetimePosition Min(LifetimePosition a, LifetimePosition b)
bool IsFastSmiOrObjectElementsKind(ElementsKind kind)
bool IsGeneratorFunction(FunctionKind kind)
Definition: globals.h:799
kSerializedDataOffset Object
Definition: objects-inl.h:5322
double FastI2D(int x)
Definition: conversions.h:64
@ EXTERNAL_STRING_TYPE
Definition: objects.h:642
@ JS_GLOBAL_PROXY_TYPE
Definition: objects.h:737
@ DECLARED_ACCESSOR_INFO_TYPE
Definition: objects.h:697
@ JS_ARRAY_TYPE
Definition: objects.h:738
@ DECLARED_ACCESSOR_DESCRIPTOR_TYPE
Definition: objects.h:696
@ JS_MODULE_TYPE
Definition: objects.h:734
@ JS_OBJECT_TYPE
Definition: objects.h:731
@ JS_GENERATOR_OBJECT_TYPE
Definition: objects.h:733
@ EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE
Definition: objects.h:646
@ ONE_BYTE_STRING_TYPE
Definition: objects.h:633
@ DEBUG_INFO_TYPE
Definition: objects.h:715
@ EXECUTABLE_ACCESSOR_INFO_TYPE
Definition: objects.h:698
@ JS_FUNCTION_TYPE
Definition: objects.h:749
@ JS_FUNCTION_PROXY_TYPE
Definition: objects.h:726
@ ACCESSOR_PAIR_TYPE
Definition: objects.h:699
@ ALIASED_ARGUMENTS_ENTRY_TYPE
Definition: objects.h:713
@ JS_GLOBAL_OBJECT_TYPE
Definition: objects.h:735
@ SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE
Definition: objects.h:653
@ CODE_CACHE_TYPE
Definition: objects.h:710
@ JS_PROXY_TYPE
Definition: objects.h:727
@ EXTERNAL_ONE_BYTE_STRING_TYPE
Definition: objects.h:644
@ SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE
Definition: objects.h:651
@ SHORT_EXTERNAL_STRING_TYPE
Definition: objects.h:649
@ TYPE_FEEDBACK_INFO_TYPE
Definition: objects.h:712
@ FAST_HOLEY_SMI_ELEMENTS
Definition: elements-kind.h:17
bool IsFastDoubleElementsKind(ElementsKind kind)
Handle< T > handle(T *t, Isolate *isolate)
Definition: handles.h:146
const intptr_t kObjectAlignment
Definition: globals.h:226
kFeedbackVectorOffset kHiddenPrototypeBit read_only_prototype
Definition: objects-inl.h:5423
byte * Address
Definition: globals.h:101
@ OLD_POINTER_SPACE
Definition: globals.h:360
int FastD2I(double x)
Definition: conversions.h:57
static void RoundUp(Vector< char > buffer, int *length, int *decimal_point)
Definition: fixed-dtoa.cc:171
static int NumberCacheHash(Handle< FixedArray > cache, Handle< Object > number)
Definition: factory.cc:2000
STATIC_ASSERT(sizeof(CPURegister)==sizeof(Register))
const char * DoubleToCString(double v, Vector< char > buffer)
Definition: conversions.cc:121
double FastUI2D(unsigned x)
Definition: conversions.h:72
static bool IsMinusZero(double value)
Definition: conversions.h:154
uint16_t uc16
Definition: globals.h:184
const char * IntToCString(int n, Vector< char > buffer)
Definition: conversions.cc:176
ArrayStorageAllocationMode
Definition: heap.h:511
@ INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE
Definition: heap.h:513
@ DONT_INITIALIZE_ARRAY_ELEMENTS
Definition: heap.h:512
PerThreadAssertScopeDebugOnly< DEFERRED_HANDLE_DEREFERENCE_ASSERT, true > AllowDeferredHandleDereference
Definition: assert-scope.h:130
static JSFunction * GetTypedArrayFun(ExternalArrayType type, Isolate *isolate)
Definition: factory.cc:1719
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
@ NewFunction
Definition: v8-debug.h:19
ExternalArrayType
Definition: v8.h:2217
#define TYPED_ARRAYS(V)
Definition: objects.h:4433
@ DONT_ENUM
#define T(name, string, precedence)
Definition: token.cc:25
#define STATIC_CHAR_VECTOR(x)
Definition: vector.h:154