Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Side by Side Diff: src/runtime/runtime-ptr.cc

Issue 1292283005: Prototype CL for faster DOM accessors. Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: #ifdef + feedback Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime/runtime.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 // Implmement runtime functions for Ptr* intrinsics, which are meant for
6 // direct access of API object in embedder-supplied code.
7 //
8 // These intrinsics in this file are rather experimental and not included in
9 // any default builds.
10 #ifdef V8_JS_ACCESSORS
11
12 #include "src/v8.h"
13
14 #include "src/arguments.h"
15 #include "src/runtime/runtime-utils.h"
16
17 namespace v8 {
18 namespace internal {
19
20 namespace {
21
22 // Helper functions & definitions to handle our 'external pointer' pseudo
23 // type. Essentially, we're using the "aligned pointer in Smi" hack to
24 // transport a C++ pointer between our intrinsics below.
25
26 #define CONVERT_PTR_ARG_CHECKED(name, index) \
27 RUNTIME_ASSERT(args[index]->IsSmi()); \
28 intptr_t name = fromObject(args.arguments()[index]);
29
30 typedef intptr_t aligned_ptr_t;
31
32
33 static aligned_ptr_t fromObject(Object* value) {
34 DCHECK(value->IsSmi());
35 return reinterpret_cast<aligned_ptr_t>(value);
36 }
37
38
39 static Object* fromAlignedPtr(aligned_ptr_t value) {
Toon Verwaest 2015/09/30 13:57:19 Camelcase function names should start with upperca
40 Object* object = reinterpret_cast<Object*>(value);
41 DCHECK(object->IsSmi());
42 return object;
43 }
44
45
46 static aligned_ptr_t loadAsPtr(aligned_ptr_t value) {
47 return *reinterpret_cast<aligned_ptr_t*>(value);
48 }
49
50
51 static int32_t loadAsInt32(aligned_ptr_t value) {
52 return *reinterpret_cast<int32_t*>(value);
53 }
54
55
56 static void checkAlignedOffset(int offset) { DCHECK((offset % 4) == 0); }
57
58
59 static Object* objectFromAlignedPtr(aligned_ptr_t value) {
60 Object* object = reinterpret_cast<Object*>(value);
61 DCHECK(!object->IsSmi());
62 return object;
63 }
64
65 } // anonymous namespace
66
67
68 RUNTIME_FUNCTION(Runtime_PtrGetFromInternalField) {
69 HandleScope scope(isolate);
70 DCHECK(args.length() == 2);
71 CONVERT_ARG_HANDLE_CHECKED(JSObject, wrapper, 0);
72 CONVERT_SMI_ARG_CHECKED(field_number, 1);
73 Object* object = wrapper->GetInternalField(field_number);
74 DCHECK(object->IsSmi());
75 return object;
76 }
77
78
79 RUNTIME_FUNCTION(Runtime_PtrLoadOffset) {
80 HandleScope scope(isolate);
81 DCHECK(args.length() == 2);
82 CONVERT_PTR_ARG_CHECKED(ptr, 0);
83 CONVERT_SMI_ARG_CHECKED(offset, 1);
84 checkAlignedOffset(offset);
85 return fromAlignedPtr(loadAsPtr(ptr + offset));
86 }
87
88
89 RUNTIME_FUNCTION(Runtime_PtrLoadOffsetInt) {
90 HandleScope scope(isolate);
91 DCHECK(args.length() == 2);
92 CONVERT_PTR_ARG_CHECKED(ptr, 0);
93 CONVERT_SMI_ARG_CHECKED(offset, 1);
94 checkAlignedOffset(offset);
95 return Smi::FromInt(loadAsInt32(ptr + offset));
96 }
97
98
99 RUNTIME_FUNCTION(Runtime_PtrLoadOffsetObj) {
100 HandleScope scope(isolate);
101 DCHECK(args.length() == 1);
102 CONVERT_PTR_ARG_CHECKED(ptr, 0);
103 return objectFromAlignedPtr(loadAsPtr(ptr));
104 }
105
106
107 RUNTIME_FUNCTION(Runtime_PtrIsNull) {
108 HandleScope scope(isolate);
109 DCHECK(args.length() == 1);
110 CONVERT_PTR_ARG_CHECKED(ptr, 0);
111 return (ptr == 0) ? isolate->heap()->true_value()
Toon Verwaest 2015/09/30 13:57:18 return isolate->heap()->ToBoolean(ptr == nullptr);
112 : isolate->heap()->false_value();
113 }
114
115 } // namespace internal
116 } // namespace v8
117
118 #endif // V8_JS_ACCESSORS
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698