1 // Copyright 2019 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_HEAP_MEMORY_MEASUREMENT_INL_H_
6 #define V8_HEAP_MEMORY_MEASUREMENT_INL_H_
7
8 #include "src/heap/memory-measurement.h"
9 #include "src/objects/contexts-inl.h"
10 #include "src/objects/contexts.h"
11 #include "src/objects/instance-type-inl.h"
12 #include "src/objects/instance-type.h"
13 #include "src/objects/map-inl.h"
14 #include "src/objects/map.h"
15
16 namespace v8 {
17 namespace internal {
18
Infer(Isolate * isolate,Map map,HeapObject object,Address * native_context)19 bool NativeContextInferrer::Infer(Isolate* isolate, Map map, HeapObject object,
20 Address* native_context) {
21 switch (map.visitor_id()) {
22 case kVisitContext:
23 return InferForContext(isolate, Context::cast(object), native_context);
24 case kVisitNativeContext:
25 *native_context = object.ptr();
26 return true;
27 case kVisitJSFunction:
28 return InferForJSFunction(isolate, JSFunction::cast(object),
29 native_context);
30 case kVisitJSApiObject:
31 case kVisitJSArrayBuffer:
32 case kVisitJSObject:
33 case kVisitJSObjectFast:
34 case kVisitJSTypedArray:
35 case kVisitJSWeakCollection:
36 return InferForJSObject(isolate, map, JSObject::cast(object),
37 native_context);
38 default:
39 return false;
40 }
41 }
42
HasExternalBytes(Map map)43 V8_INLINE bool NativeContextStats::HasExternalBytes(Map map) {
44 InstanceType instance_type = map.instance_type();
45 return (instance_type == JS_ARRAY_BUFFER_TYPE ||
46 InstanceTypeChecker::IsExternalString(instance_type));
47 }
48
IncrementSize(Address context,Map map,HeapObject object,size_t size)49 V8_INLINE void NativeContextStats::IncrementSize(Address context, Map map,
50 HeapObject object,
51 size_t size) {
52 size_by_context_[context] += size;
53 if (HasExternalBytes(map)) {
54 IncrementExternalSize(context, map, object);
55 }
56 }
57
58 } // namespace internal
59 } // namespace v8
60
61 #endif // V8_HEAP_MEMORY_MEASUREMENT_INL_H_
62