• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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 #ifndef V8_IC_HANDLER_CONFIGURATION_INL_H_
6 #define V8_IC_HANDLER_CONFIGURATION_INL_H_
7 
8 #include "src/ic/handler-configuration.h"
9 
10 #include "src/field-index-inl.h"
11 #include "src/objects-inl.h"
12 
13 namespace v8 {
14 namespace internal {
15 
LoadField(Isolate * isolate,FieldIndex field_index)16 Handle<Object> LoadHandler::LoadField(Isolate* isolate,
17                                       FieldIndex field_index) {
18   int config = KindBits::encode(kForFields) |
19                IsInobjectBits::encode(field_index.is_inobject()) |
20                IsDoubleBits::encode(field_index.is_double()) |
21                FieldOffsetBits::encode(field_index.offset());
22   return handle(Smi::FromInt(config), isolate);
23 }
24 
LoadConstant(Isolate * isolate,int descriptor)25 Handle<Object> LoadHandler::LoadConstant(Isolate* isolate, int descriptor) {
26   int config = KindBits::encode(kForConstants) |
27                IsAccessorInfoBits::encode(false) |
28                DescriptorValueIndexBits::encode(
29                    DescriptorArray::ToValueIndex(descriptor));
30   return handle(Smi::FromInt(config), isolate);
31 }
32 
LoadApiGetter(Isolate * isolate,int descriptor)33 Handle<Object> LoadHandler::LoadApiGetter(Isolate* isolate, int descriptor) {
34   int config = KindBits::encode(kForConstants) |
35                IsAccessorInfoBits::encode(true) |
36                DescriptorValueIndexBits::encode(
37                    DescriptorArray::ToValueIndex(descriptor));
38   return handle(Smi::FromInt(config), isolate);
39 }
40 
EnableAccessCheckOnReceiver(Isolate * isolate,Handle<Object> smi_handler)41 Handle<Object> LoadHandler::EnableAccessCheckOnReceiver(
42     Isolate* isolate, Handle<Object> smi_handler) {
43   int config = Smi::cast(*smi_handler)->value();
44 #ifdef DEBUG
45   Kind kind = KindBits::decode(config);
46   DCHECK_NE(kForElements, kind);
47 #endif
48   config = DoAccessCheckOnReceiverBits::update(config, true);
49   return handle(Smi::FromInt(config), isolate);
50 }
51 
EnableNegativeLookupOnReceiver(Isolate * isolate,Handle<Object> smi_handler)52 Handle<Object> LoadHandler::EnableNegativeLookupOnReceiver(
53     Isolate* isolate, Handle<Object> smi_handler) {
54   int config = Smi::cast(*smi_handler)->value();
55 #ifdef DEBUG
56   Kind kind = KindBits::decode(config);
57   DCHECK_NE(kForElements, kind);
58 #endif
59   config = DoNegativeLookupOnReceiverBits::update(config, true);
60   return handle(Smi::FromInt(config), isolate);
61 }
62 
LoadNonExistent(Isolate * isolate,bool do_negative_lookup_on_receiver)63 Handle<Object> LoadHandler::LoadNonExistent(
64     Isolate* isolate, bool do_negative_lookup_on_receiver) {
65   int config =
66       KindBits::encode(kForNonExistent) |
67       DoNegativeLookupOnReceiverBits::encode(do_negative_lookup_on_receiver);
68   return handle(Smi::FromInt(config), isolate);
69 }
70 
LoadElement(Isolate * isolate,ElementsKind elements_kind,bool convert_hole_to_undefined,bool is_js_array)71 Handle<Object> LoadHandler::LoadElement(Isolate* isolate,
72                                         ElementsKind elements_kind,
73                                         bool convert_hole_to_undefined,
74                                         bool is_js_array) {
75   int config = KindBits::encode(kForElements) |
76                ElementsKindBits::encode(elements_kind) |
77                ConvertHoleBits::encode(convert_hole_to_undefined) |
78                IsJsArrayBits::encode(is_js_array);
79   return handle(Smi::FromInt(config), isolate);
80 }
81 
StoreField(Isolate * isolate,Kind kind,int descriptor,FieldIndex field_index,Representation representation,bool extend_storage)82 Handle<Object> StoreHandler::StoreField(Isolate* isolate, Kind kind,
83                                         int descriptor, FieldIndex field_index,
84                                         Representation representation,
85                                         bool extend_storage) {
86   StoreHandler::FieldRepresentation field_rep;
87   switch (representation.kind()) {
88     case Representation::kSmi:
89       field_rep = StoreHandler::kSmi;
90       break;
91     case Representation::kDouble:
92       field_rep = StoreHandler::kDouble;
93       break;
94     case Representation::kHeapObject:
95       field_rep = StoreHandler::kHeapObject;
96       break;
97     case Representation::kTagged:
98       field_rep = StoreHandler::kTagged;
99       break;
100     default:
101       UNREACHABLE();
102       return Handle<Object>::null();
103   }
104   int value_index = DescriptorArray::ToValueIndex(descriptor);
105 
106   DCHECK(kind == kStoreField || kind == kTransitionToField ||
107          (kind == kStoreConstField && FLAG_track_constant_fields));
108   DCHECK_IMPLIES(extend_storage, kind == kTransitionToField);
109   DCHECK_IMPLIES(field_index.is_inobject(), !extend_storage);
110 
111   int config = StoreHandler::KindBits::encode(kind) |
112                StoreHandler::ExtendStorageBits::encode(extend_storage) |
113                StoreHandler::IsInobjectBits::encode(field_index.is_inobject()) |
114                StoreHandler::FieldRepresentationBits::encode(field_rep) |
115                StoreHandler::DescriptorValueIndexBits::encode(value_index) |
116                StoreHandler::FieldOffsetBits::encode(field_index.offset());
117   return handle(Smi::FromInt(config), isolate);
118 }
119 
StoreField(Isolate * isolate,int descriptor,FieldIndex field_index,PropertyConstness constness,Representation representation)120 Handle<Object> StoreHandler::StoreField(Isolate* isolate, int descriptor,
121                                         FieldIndex field_index,
122                                         PropertyConstness constness,
123                                         Representation representation) {
124   DCHECK_IMPLIES(!FLAG_track_constant_fields, constness == kMutable);
125   Kind kind = constness == kMutable ? kStoreField : kStoreConstField;
126   return StoreField(isolate, kind, descriptor, field_index, representation,
127                     false);
128 }
129 
TransitionToField(Isolate * isolate,int descriptor,FieldIndex field_index,Representation representation,bool extend_storage)130 Handle<Object> StoreHandler::TransitionToField(Isolate* isolate, int descriptor,
131                                                FieldIndex field_index,
132                                                Representation representation,
133                                                bool extend_storage) {
134   return StoreField(isolate, kTransitionToField, descriptor, field_index,
135                     representation, extend_storage);
136 }
137 
TransitionToConstant(Isolate * isolate,int descriptor)138 Handle<Object> StoreHandler::TransitionToConstant(Isolate* isolate,
139                                                   int descriptor) {
140   DCHECK(!FLAG_track_constant_fields);
141   int value_index = DescriptorArray::ToValueIndex(descriptor);
142   int config =
143       StoreHandler::KindBits::encode(StoreHandler::kTransitionToConstant) |
144       StoreHandler::DescriptorValueIndexBits::encode(value_index);
145   return handle(Smi::FromInt(config), isolate);
146 }
147 
148 }  // namespace internal
149 }  // namespace v8
150 
151 #endif  // V8_IC_HANDLER_CONFIGURATION_INL_H_
152