1 // Copyright 2018 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/compiler/js-heap-copy-reducer.h" 6 7 #include "src/compiler/common-operator.h" 8 #include "src/compiler/js-heap-broker.h" 9 #include "src/compiler/js-operator.h" 10 #include "src/heap/factory-inl.h" 11 #include "src/objects/map.h" 12 #include "src/objects/scope-info.h" 13 14 namespace v8 { 15 namespace internal { 16 namespace compiler { 17 18 // In the functions below, we call the ObjectRef (or subclass) constructor in 19 // order to trigger serialization if not yet done. 20 21 JSHeapCopyReducer::JSHeapCopyReducer(JSHeapBroker* broker) : broker_(broker) {} 22 23 JSHeapBroker* JSHeapCopyReducer::broker() { return broker_; } 24 25 Reduction JSHeapCopyReducer::Reduce(Node* node) { 26 switch (node->opcode()) { 27 case IrOpcode::kHeapConstant: { 28 ObjectRef(broker(), HeapConstantOf(node->op())); 29 break; 30 } 31 case IrOpcode::kJSCreateArray: { 32 CreateArrayParameters const& p = CreateArrayParametersOf(node->op()); 33 Handle<AllocationSite> site; 34 if (p.site().ToHandle(&site)) AllocationSiteRef(broker(), site); 35 break; 36 } 37 case IrOpcode::kJSCreateCatchContext: { 38 ScopeInfoRef(broker(), ScopeInfoOf(node->op())); 39 break; 40 } 41 case IrOpcode::kJSCreateClosure: { 42 CreateClosureParameters const& p = CreateClosureParametersOf(node->op()); 43 SharedFunctionInfoRef(broker(), p.shared_info()); 44 HeapObjectRef(broker(), p.feedback_cell()); 45 HeapObjectRef(broker(), p.code()); 46 break; 47 } 48 case IrOpcode::kJSCreateEmptyLiteralArray: { 49 // TODO(neis, jarin) Force serialization of the entire feedback vector 50 // rather than just the one element. 51 FeedbackParameter const& p = FeedbackParameterOf(node->op()); 52 FeedbackVectorRef(broker(), p.feedback().vector()); 53 Handle<Object> feedback( 54 p.feedback().vector()->Get(p.feedback().slot())->ToObject(), 55 broker()->isolate()); 56 ObjectRef(broker(), feedback); 57 break; 58 } 59 case IrOpcode::kJSCreateFunctionContext: { 60 CreateFunctionContextParameters const& p = 61 CreateFunctionContextParametersOf(node->op()); 62 ScopeInfoRef(broker(), p.scope_info()); 63 break; 64 } 65 case IrOpcode::kJSCreateLiteralArray: 66 case IrOpcode::kJSCreateLiteralObject: { 67 CreateLiteralParameters const& p = CreateLiteralParametersOf(node->op()); 68 ObjectRef(broker(), p.feedback().vector()); 69 break; 70 } 71 case IrOpcode::kJSLoadNamed: 72 case IrOpcode::kJSStoreNamed: { 73 NamedAccess const& p = NamedAccessOf(node->op()); 74 NameRef(broker(), p.name()); 75 break; 76 } 77 default: 78 break; 79 } 80 return NoChange(); 81 } 82 83 } // namespace compiler 84 } // namespace internal 85 } // namespace v8 86