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

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: Created 5 years, 4 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..c1d24cea0e647e7bd9129ca7ebeb90c1f17d8b81
--- /dev/null
+++ b/src/runtime/runtime-ptr.cc
@@ -0,0 +1,111 @@
+// 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.
+
+#include "src/v8.h"
+
+#include "src/arguments.h"
+#include "src/runtime/runtime-utils.h"
+
+// Implmement runtime functions for direct DOM element access.
+
+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);
epertoso 2015/09/25 08:22:53 just return reinterpret_cast<aligned_ptr>(value).
vogelheim 2015/09/29 11:15:17 Done. For some reason, I was dead sure that you c
+}
+
+
+static Object* fromAlignedPtr(aligned_ptr_t value) {
+ Object* object = *reinterpret_cast<Object**>(&value);
epertoso 2015/09/25 08:22:53 As above, just reinterpret_cast<Object*>(value) is
vogelheim 2015/09/29 11:15:17 Done.
+ 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);
epertoso 2015/09/25 08:22:53 And here too :).
vogelheim 2015/09/29 11:15:17 Done.
+ DCHECK(!object->IsSmi());
+ return object;
+}
+
+} // anonymous namespace
+
+
+RUNTIME_FUNCTION(Runtime_PtrGetFromInternalField) {
+ HandleScope scope(isolate);
epertoso 2015/09/25 08:22:53 I think is that these functions should be UNREACHA
vogelheim 2015/09/29 11:15:17 Disagree. The reason why I want them (#ifdef-ed) i
+ 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) {
jochen (gone - plz use gerrit) 2015/09/25 11:20:12 why not PtrTestIntAtOffset() or something?
vogelheim 2015/09/29 11:15:17 Meanwhile, Enrico has done a good bit of work with
+ 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()
+ : isolate->heap()->false_value();
+}
+
+} // namespace internal
+} // namespace v8
« 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