• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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/heap/local-factory.h"
6 
7 #include "src/common/globals.h"
8 #include "src/execution/local-isolate.h"
9 #include "src/handles/handles.h"
10 #include "src/heap/concurrent-allocator-inl.h"
11 #include "src/numbers/hash-seed-inl.h"
12 #include "src/objects/fixed-array.h"
13 #include "src/objects/heap-object.h"
14 #include "src/objects/string.h"
15 #include "src/roots/roots-inl.h"
16 #include "src/strings/string-hasher.h"
17 
18 namespace v8 {
19 namespace internal {
20 
LocalFactory(Isolate * isolate)21 LocalFactory::LocalFactory(Isolate* isolate) : roots_(isolate) {}
22 
AddToScriptList(Handle<Script> shared)23 void LocalFactory::AddToScriptList(Handle<Script> shared) {
24 // TODO(leszeks): Actually add the script to the main Isolate's script list,
25 // in a thread-safe way.
26 //
27 // At the moment, we have to do one final fix-up during off-thread
28 // finalization, where we add the created script to the script list, but this
29 // relies on there being exactly one script created during the lifetime of
30 // this LocalFactory.
31 //
32 // For now, prevent accidentaly creating more scripts that don't get added to
33 // the script list with a simple DCHECK.
34 #ifdef DEBUG
35   DCHECK(!a_script_was_added_to_the_script_list_);
36   a_script_was_added_to_the_script_list_ = true;
37 #endif
38 }
39 
AllocateRaw(int size,AllocationType allocation,AllocationAlignment alignment)40 HeapObject LocalFactory::AllocateRaw(int size, AllocationType allocation,
41                                      AllocationAlignment alignment) {
42   DCHECK_EQ(allocation, AllocationType::kOld);
43   return HeapObject::FromAddress(isolate()->heap()->AllocateRawOrFail(
44       size, allocation, AllocationOrigin::kRuntime, alignment));
45 }
46 
47 }  // namespace internal
48 }  // namespace v8
49