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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime/runtime.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-ptr.cc
diff --git a/src/runtime/runtime-ptr.cc b/src/runtime/runtime-ptr.cc
new file mode 100644
index 0000000000000000000000000000000000000000..56f763a9a45eade5d501488e3c16f6a3d1b00cb5
--- /dev/null
+++ b/src/runtime/runtime-ptr.cc
@@ -0,0 +1,118 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Implmement runtime functions for Ptr* intrinsics, which are meant for
+// direct access of API object in embedder-supplied code.
+//
+// These intrinsics in this file are rather experimental and not included in
+// any default builds.
+#ifdef V8_JS_ACCESSORS
+
+#include "src/v8.h"
+
+#include "src/arguments.h"
+#include "src/runtime/runtime-utils.h"
+
+namespace v8 {
+namespace internal {
+
+namespace {
+
+// Helper functions & definitions to handle our 'external pointer' pseudo
+// type. Essentially, we're using the "aligned pointer in Smi" hack to
+// transport a C++ pointer between our intrinsics below.
+
+#define CONVERT_PTR_ARG_CHECKED(name, index) \
+ RUNTIME_ASSERT(args[index]->IsSmi()); \
+ intptr_t name = fromObject(args.arguments()[index]);
+
+typedef intptr_t aligned_ptr_t;
+
+
+static aligned_ptr_t fromObject(Object* value) {
+ DCHECK(value->IsSmi());
+ return reinterpret_cast<aligned_ptr_t>(value);
+}
+
+
+static Object* fromAlignedPtr(aligned_ptr_t value) {
Toon Verwaest 2015/09/30 13:57:19 Camelcase function names should start with upperca
+ Object* object = reinterpret_cast<Object*>(value);
+ DCHECK(object->IsSmi());
+ return object;
+}
+
+
+static aligned_ptr_t loadAsPtr(aligned_ptr_t value) {
+ return *reinterpret_cast<aligned_ptr_t*>(value);
+}
+
+
+static int32_t loadAsInt32(aligned_ptr_t value) {
+ return *reinterpret_cast<int32_t*>(value);
+}
+
+
+static void checkAlignedOffset(int offset) { DCHECK((offset % 4) == 0); }
+
+
+static Object* objectFromAlignedPtr(aligned_ptr_t value) {
+ Object* object = reinterpret_cast<Object*>(value);
+ DCHECK(!object->IsSmi());
+ return object;
+}
+
+} // anonymous namespace
+
+
+RUNTIME_FUNCTION(Runtime_PtrGetFromInternalField) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 2);
+ CONVERT_ARG_HANDLE_CHECKED(JSObject, wrapper, 0);
+ CONVERT_SMI_ARG_CHECKED(field_number, 1);
+ Object* object = wrapper->GetInternalField(field_number);
+ DCHECK(object->IsSmi());
+ return object;
+}
+
+
+RUNTIME_FUNCTION(Runtime_PtrLoadOffset) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 2);
+ CONVERT_PTR_ARG_CHECKED(ptr, 0);
+ CONVERT_SMI_ARG_CHECKED(offset, 1);
+ checkAlignedOffset(offset);
+ return fromAlignedPtr(loadAsPtr(ptr + offset));
+}
+
+
+RUNTIME_FUNCTION(Runtime_PtrLoadOffsetInt) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 2);
+ CONVERT_PTR_ARG_CHECKED(ptr, 0);
+ CONVERT_SMI_ARG_CHECKED(offset, 1);
+ checkAlignedOffset(offset);
+ return Smi::FromInt(loadAsInt32(ptr + offset));
+}
+
+
+RUNTIME_FUNCTION(Runtime_PtrLoadOffsetObj) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 1);
+ CONVERT_PTR_ARG_CHECKED(ptr, 0);
+ return objectFromAlignedPtr(loadAsPtr(ptr));
+}
+
+
+RUNTIME_FUNCTION(Runtime_PtrIsNull) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 1);
+ CONVERT_PTR_ARG_CHECKED(ptr, 0);
+ return (ptr == 0) ? isolate->heap()->true_value()
Toon Verwaest 2015/09/30 13:57:18 return isolate->heap()->ToBoolean(ptr == nullptr);
+ : isolate->heap()->false_value();
+}
+
+} // namespace internal
+} // namespace v8
+
+#endif // V8_JS_ACCESSORS
« 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