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

Side by Side Diff: src/handles.h

Issue 12049012: Avoid handle dereference during graph optimization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « src/compiler.cc ('k') | src/handles-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 // Constructor for handling automatic up casting. 52 // Constructor for handling automatic up casting.
53 // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected. 53 // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected.
54 template <class S> Handle(Handle<S> handle) { 54 template <class S> Handle(Handle<S> handle) {
55 #ifdef DEBUG 55 #ifdef DEBUG
56 T* a = NULL; 56 T* a = NULL;
57 S* b = NULL; 57 S* b = NULL;
58 a = b; // Fake assignment to enforce type checks. 58 a = b; // Fake assignment to enforce type checks.
59 USE(a); 59 USE(a);
60 #endif 60 #endif
61 location_ = reinterpret_cast<T**>(handle.location()); 61 location_ = reinterpret_cast<T**>(handle.location_);
62 } 62 }
63 63
64 INLINE(T* operator ->() const) { return operator*(); } 64 INLINE(T* operator ->() const) { return operator*(); }
65 65
66 // Check if this handle refers to the exact same object as the other handle. 66 // Check if this handle refers to the exact same object as the other handle.
67 bool is_identical_to(const Handle<T> other) const { 67 bool is_identical_to(const Handle<T> other) const {
68 return operator*() == *other; 68 return *location_ == *other.location_;
69 } 69 }
70 70
71 // Provides the C++ dereference operator. 71 // Provides the C++ dereference operator.
72 INLINE(T* operator*() const); 72 INLINE(T* operator*() const);
73 73
74 // Returns the address to where the raw pointer is stored. 74 // Returns the address to where the raw pointer is stored.
75 T** location() const { 75 INLINE(T** location() const);
76 ASSERT(location_ == NULL ||
77 reinterpret_cast<Address>(*location_) != kZapValue);
78 return location_;
79 }
80 76
81 template <class S> static Handle<T> cast(Handle<S> that) { 77 template <class S> static Handle<T> cast(Handle<S> that) {
82 T::cast(*that); 78 T::cast(*that);
83 return Handle<T>(reinterpret_cast<T**>(that.location())); 79 return Handle<T>(reinterpret_cast<T**>(that.location()));
84 } 80 }
85 81
86 static Handle<T> null() { return Handle<T>(); } 82 static Handle<T> null() { return Handle<T>(); }
87 bool is_null() const { return location_ == NULL; } 83 bool is_null() const { return location_ == NULL; }
88 84
89 // Closes the given scope, but lets this handle escape. See 85 // Closes the given scope, but lets this handle escape. See
90 // implementation in api.h. 86 // implementation in api.h.
91 inline Handle<T> EscapeFrom(v8::HandleScope* scope); 87 inline Handle<T> EscapeFrom(v8::HandleScope* scope);
92 88
93 private: 89 private:
94 T** location_; 90 T** location_;
91
92 // Handles of different classes are allowed to access each other's location_.
93 template<class S> friend class Handle;
95 }; 94 };
96 95
97 96
98 // Convenience wrapper. 97 // Convenience wrapper.
99 template<class T> 98 template<class T>
100 inline Handle<T> handle(T* t, Isolate* isolate) { 99 inline Handle<T> handle(T* t, Isolate* isolate) {
101 return Handle<T>(t, isolate); 100 return Handle<T>(t, isolate);
102 } 101 }
103 102
104 103
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 ~NoHandleAllocation() {} 331 ~NoHandleAllocation() {}
333 #else 332 #else
334 inline NoHandleAllocation(); 333 inline NoHandleAllocation();
335 inline ~NoHandleAllocation(); 334 inline ~NoHandleAllocation();
336 private: 335 private:
337 int level_; 336 int level_;
338 bool active_; 337 bool active_;
339 #endif 338 #endif
340 }; 339 };
341 340
341
342 class NoHandleDereference BASE_EMBEDDED {
343 public:
344 #ifndef DEBUG
345 NoHandleDereference() {}
346 ~NoHandleDereference() {}
347 #else
348 inline NoHandleDereference();
349 inline ~NoHandleDereference();
350 private:
351 bool old_state_;
352 #endif
353 };
354
355
356 class AllowHandleDereference BASE_EMBEDDED {
357 public:
358 #ifndef DEBUG
359 AllowHandleDereference() {}
360 ~AllowHandleDereference() {}
361 #else
362 inline AllowHandleDereference();
363 inline ~AllowHandleDereference();
364 private:
365 bool old_state_;
366 #endif
367 };
368
342 } } // namespace v8::internal 369 } } // namespace v8::internal
343 370
344 #endif // V8_HANDLES_H_ 371 #endif // V8_HANDLES_H_
OLDNEW
« no previous file with comments | « src/compiler.cc ('k') | src/handles-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698