blob: 70bbaf8c9605368776baea4ff642099da533e950 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_IC_INL_H_
29#define V8_IC_INL_H_
30
31#include "ic.h"
32#include "debug.h"
33#include "macro-assembler.h"
34
35namespace v8 {
36namespace internal {
37
38
39Address IC::address() {
40 // Get the address of the call.
41 Address result = pc() - Assembler::kCallTargetAddressOffset;
42
43#ifdef ENABLE_DEBUGGER_SUPPORT
44 // First check if any break points are active if not just return the address
45 // of the call.
46 if (!Debug::has_break_points()) return result;
47
48 // At least one break point is active perform additional test to ensure that
49 // break point locations are updated correctly.
50 if (Debug::IsDebugBreak(Assembler::target_address_at(result))) {
51 // If the call site is a call to debug break then return the address in
52 // the original code instead of the address in the running code. This will
53 // cause the original code to be updated and keeps the breakpoint active in
54 // the running code.
55 return OriginalCodeAddress();
56 } else {
57 // No break point here just return the address of the call.
58 return result;
59 }
60#else
61 return result;
62#endif
63}
64
65
66Code* IC::GetTargetAtAddress(Address address) {
67 // Get the target address of the IC.
68 Address target = Assembler::target_address_at(address);
69 // Convert target address to the code object. Code::GetCodeFromTargetAddress
70 // is safe for use during GC where the map might be marked.
71 Code* result = Code::GetCodeFromTargetAddress(target);
72 ASSERT(result->is_inline_cache_stub());
73 return result;
74}
75
76
77void IC::SetTargetAtAddress(Address address, Code* target) {
78 ASSERT(target->is_inline_cache_stub());
79 Assembler::set_target_address_at(address, target->instruction_start());
80}
81
82
Steve Block8defd9f2010-07-08 12:39:36 +010083InlineCacheHolderFlag IC::GetCodeCacheForObject(Object* object,
84 JSObject* holder) {
85 if (object->IsJSObject()) {
86 return GetCodeCacheForObject(JSObject::cast(object), holder);
87 }
Steve Blocka7e24c12009-10-30 11:49:00 +000088 // If the object is a value, we use the prototype map for the cache.
89 ASSERT(object->IsString() || object->IsNumber() || object->IsBoolean());
Steve Block8defd9f2010-07-08 12:39:36 +010090 return PROTOTYPE_MAP;
91}
92
93
94InlineCacheHolderFlag IC::GetCodeCacheForObject(JSObject* object,
95 JSObject* holder) {
96 // Fast-properties and global objects store stubs in their own maps.
97 // Slow properties objects use prototype's map (unless the property is its own
98 // when holder == object). It works because slow properties objects having
99 // the same prototype (or a prototype with the same map) and not having
100 // the property are interchangeable for such a stub.
101 if (holder != object &&
102 !object->HasFastProperties() &&
103 !object->IsJSGlobalProxy() &&
104 !object->IsJSGlobalObject()) {
105 return PROTOTYPE_MAP;
106 }
107 return OWN_MAP;
108}
109
110
111Map* IC::GetCodeCacheMap(Object* object, InlineCacheHolderFlag holder) {
112 Object* map_owner = (holder == OWN_MAP ? object : object->GetPrototype());
113 ASSERT(map_owner->IsJSObject());
114 return JSObject::cast(map_owner)->map();
Steve Blocka7e24c12009-10-30 11:49:00 +0000115}
116
117
118} } // namespace v8::internal
119
120#endif // V8_IC_INL_H_