source: webkit/trunk/JavaScriptCore/runtime/JSCell.h@ 38857

Last change on this file since 38857 was 38473, checked in by [email protected], 17 years ago

2008-11-16 Geoffrey Garen <[email protected]>

Reviewed by a few people on squirrelfish-dev.


Renamed CTI => JIT.

  • VM/CTI.cpp: (JSC::JIT::killLastResultRegister): (JSC::JIT::emitGetVirtualRegister): (JSC::JIT::emitGetVirtualRegisters): (JSC::JIT::emitPutCTIArgFromVirtualRegister): (JSC::JIT::emitPutCTIArg): (JSC::JIT::emitGetCTIArg): (JSC::JIT::emitPutCTIArgConstant): (JSC::JIT::getConstantImmediateNumericArg): (JSC::JIT::emitPutCTIParam): (JSC::JIT::emitGetCTIParam): (JSC::JIT::emitPutToCallFrameHeader): (JSC::JIT::emitGetFromCallFrameHeader): (JSC::JIT::emitPutVirtualRegister): (JSC::JIT::emitInitRegister): (JSC::JIT::printBytecodeOperandTypes): (JSC::JIT::emitAllocateNumber): (JSC::JIT::emitNakedCall): (JSC::JIT::emitNakedFastCall): (JSC::JIT::emitCTICall): (JSC::JIT::emitJumpSlowCaseIfNotJSCell): (JSC::JIT::linkSlowCaseIfNotJSCell): (JSC::JIT::emitJumpSlowCaseIfNotImmNum): (JSC::JIT::emitJumpSlowCaseIfNotImmNums): (JSC::JIT::getDeTaggedConstantImmediate): (JSC::JIT::emitFastArithDeTagImmediate): (JSC::JIT::emitFastArithDeTagImmediateJumpIfZero): (JSC::JIT::emitFastArithReTagImmediate): (JSC::JIT::emitFastArithPotentiallyReTagImmediate): (JSC::JIT::emitFastArithImmToInt): (JSC::JIT::emitFastArithIntToImmOrSlowCase): (JSC::JIT::emitFastArithIntToImmNoCheck): (JSC::JIT::emitArithIntToImmWithJump): (JSC::JIT::emitTagAsBoolImmediate): (JSC::JIT::JIT): (JSC::JIT::compileOpCallInitializeCallFrame): (JSC::JIT::compileOpCallSetupArgs): (JSC::JIT::compileOpCallEvalSetupArgs): (JSC::JIT::compileOpConstructSetupArgs): (JSC::JIT::compileOpCall): (JSC::JIT::compileOpStrictEq): (JSC::JIT::emitSlowScriptCheck): (JSC::JIT::putDoubleResultToJSNumberCellOrJSImmediate): (JSC::JIT::compileBinaryArithOp): (JSC::JIT::compileBinaryArithOpSlowCase): (JSC::JIT::privateCompileMainPass): (JSC::JIT::privateCompileLinkPass): (JSC::JIT::privateCompileSlowCases): (JSC::JIT::privateCompile): (JSC::JIT::privateCompileGetByIdSelf): (JSC::JIT::privateCompileGetByIdProto): (JSC::JIT::privateCompileGetByIdChain): (JSC::JIT::privateCompilePutByIdReplace): (JSC::JIT::privateCompilePutByIdTransition): (JSC::JIT::unlinkCall): (JSC::JIT::linkCall): (JSC::JIT::privateCompileCTIMachineTrampolines): (JSC::JIT::freeCTIMachineTrampolines): (JSC::JIT::patchGetByIdSelf): (JSC::JIT::patchPutByIdReplace): (JSC::JIT::privateCompilePatchGetArrayLength): (JSC::JIT::emitGetVariableObjectRegister): (JSC::JIT::emitPutVariableObjectRegister):
  • VM/CTI.h: (JSC::JIT::compile): (JSC::JIT::compileGetByIdSelf): (JSC::JIT::compileGetByIdProto): (JSC::JIT::compileGetByIdChain): (JSC::JIT::compilePutByIdReplace): (JSC::JIT::compilePutByIdTransition): (JSC::JIT::compileCTIMachineTrampolines): (JSC::JIT::compilePatchGetArrayLength):
  • VM/CodeBlock.cpp: (JSC::CodeBlock::unlinkCallers):
  • VM/Machine.cpp: (JSC::Interpreter::initialize): (JSC::Interpreter::~Interpreter): (JSC::Interpreter::execute): (JSC::Interpreter::tryCTICachePutByID): (JSC::Interpreter::tryCTICacheGetByID): (JSC::Interpreter::cti_op_call_JSFunction): (JSC::Interpreter::cti_vm_dontLazyLinkCall): (JSC::Interpreter::cti_vm_lazyLinkCall):
  • VM/Machine.h:
  • VM/RegisterFile.h:
  • parser/Nodes.h:
  • runtime/JSArray.h:
  • runtime/JSCell.h:
  • runtime/JSFunction.h:
  • runtime/JSImmediate.h:
  • runtime/JSNumberCell.h:
  • runtime/JSObject.h:
  • runtime/JSString.h:
  • runtime/JSVariableObject.h:
  • runtime/ScopeChain.h:
  • runtime/Structure.h:
  • runtime/TypeInfo.h:
  • runtime/UString.h:
  • Property svn:eol-style set to native
File size: 10.2 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2004, 2005, 2007, 2008 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef JSCell_h
24#define JSCell_h
25
26#include "Structure.h"
27#include "JSValue.h"
28#include "Collector.h"
29
30namespace JSC {
31
32 class JSCell : public JSValue {
33 friend class JIT;
34 friend class GetterSetter;
35 friend class Heap;
36 friend class JSNumberCell;
37 friend class JSObject;
38 friend class JSPropertyNameIterator;
39 friend class JSString;
40 friend class JSValue;
41 friend class Interpreter;
42
43 private:
44 explicit JSCell(Structure*);
45 virtual ~JSCell();
46
47 public:
48 // Querying the type.
49 bool isNumber() const;
50 bool isString() const;
51 bool isObject() const;
52 virtual bool isGetterSetter() const;
53 virtual bool isObject(const ClassInfo*) const;
54
55 Structure* structure() const;
56
57 // Extracting the value.
58 bool getNumber(double&) const;
59 double getNumber() const; // NaN if not a number
60 bool getString(UString&) const;
61 UString getString() const; // null string if not a string
62 JSObject* getObject(); // NULL if not an object
63 const JSObject* getObject() const; // NULL if not an object
64
65 virtual CallType getCallData(CallData&);
66 virtual ConstructType getConstructData(ConstructData&);
67
68 // Extracting integer values.
69 virtual bool getUInt32(uint32_t&) const;
70 virtual bool getTruncatedInt32(int32_t&) const;
71 virtual bool getTruncatedUInt32(uint32_t&) const;
72
73 // Basic conversions.
74 virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const = 0;
75 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*&) = 0;
76 virtual bool toBoolean(ExecState*) const = 0;
77 virtual double toNumber(ExecState*) const = 0;
78 virtual UString toString(ExecState*) const = 0;
79 virtual JSObject* toObject(ExecState*) const = 0;
80
81 // Garbage collection.
82 void* operator new(size_t, ExecState*);
83 void* operator new(size_t, JSGlobalData*);
84 void* operator new(size_t, void* placementNewDestination) { return placementNewDestination; }
85 virtual void mark();
86 bool marked() const;
87
88 // Object operations, with the toObject operation included.
89 virtual const ClassInfo* classInfo() const;
90 virtual void put(ExecState*, const Identifier& propertyName, JSValue*, PutPropertySlot&);
91 virtual void put(ExecState*, unsigned propertyName, JSValue*);
92 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
93 virtual bool deleteProperty(ExecState*, unsigned propertyName);
94
95 virtual JSObject* toThisObject(ExecState*) const;
96 virtual UString toThisString(ExecState*) const;
97 virtual JSString* toThisJSString(ExecState*);
98 virtual JSValue* getJSNumber();
99 void* vptr() { return *reinterpret_cast<void**>(this); }
100
101 private:
102 // Base implementation; for non-object classes implements getPropertySlot.
103 bool fastGetOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
104 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
105 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
106
107 Structure* m_structure;
108 };
109
110 JSCell* asCell(JSValue*);
111
112 inline JSCell* asCell(JSValue* value)
113 {
114 ASSERT(!JSImmediate::isImmediate(value));
115 return static_cast<JSCell*>(value);
116 }
117
118 inline JSCell::JSCell(Structure* structure)
119 : m_structure(structure)
120 {
121 }
122
123 inline JSCell::~JSCell()
124 {
125 }
126
127 inline bool JSCell::isNumber() const
128 {
129 return Heap::isNumber(const_cast<JSCell*>(this));
130 }
131
132 inline bool JSCell::isObject() const
133 {
134 return m_structure->typeInfo().type() == ObjectType;
135 }
136
137 inline bool JSCell::isString() const
138 {
139 return m_structure->typeInfo().type() == StringType;
140 }
141
142 inline Structure* JSCell::structure() const
143 {
144 return m_structure;
145 }
146
147 inline bool JSCell::marked() const
148 {
149 return Heap::isCellMarked(this);
150 }
151
152 inline void JSCell::mark()
153 {
154 return Heap::markCell(this);
155 }
156
157 ALWAYS_INLINE JSCell* JSValue::asCell() const
158 {
159 ASSERT(!JSImmediate::isImmediate(asValue()));
160 return reinterpret_cast<JSCell*>(const_cast<JSValue*>(this));
161 }
162
163 inline void* JSCell::operator new(size_t size, JSGlobalData* globalData)
164 {
165#ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
166 return globalData->heap.inlineAllocate(size);
167#else
168 return globalData->heap.allocate(size);
169#endif
170 }
171
172 // --- JSValue inlines ----------------------------
173
174 inline bool JSValue::isNumber() const
175 {
176 return JSImmediate::isNumber(asValue()) || (!JSImmediate::isImmediate(asValue()) && asCell()->isNumber());
177 }
178
179 inline bool JSValue::isString() const
180 {
181 return !JSImmediate::isImmediate(asValue()) && asCell()->isString();
182 }
183
184 inline bool JSValue::isGetterSetter() const
185 {
186 return !JSImmediate::isImmediate(asValue()) && asCell()->isGetterSetter();
187 }
188
189 inline bool JSValue::isObject() const
190 {
191 return !JSImmediate::isImmediate(asValue()) && asCell()->isObject();
192 }
193
194 inline double JSValue::getNumber() const
195 {
196 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toDouble(asValue()) : asCell()->getNumber();
197 }
198
199 inline bool JSValue::getString(UString& s) const
200 {
201 return !JSImmediate::isImmediate(asValue()) && asCell()->getString(s);
202 }
203
204 inline UString JSValue::getString() const
205 {
206 return JSImmediate::isImmediate(asValue()) ? UString() : asCell()->getString();
207 }
208
209 inline JSObject* JSValue::getObject() const
210 {
211 return JSImmediate::isImmediate(asValue()) ? 0 : asCell()->getObject();
212 }
213
214 inline CallType JSValue::getCallData(CallData& callData)
215 {
216 return JSImmediate::isImmediate(asValue()) ? CallTypeNone : asCell()->getCallData(callData);
217 }
218
219 inline ConstructType JSValue::getConstructData(ConstructData& constructData)
220 {
221 return JSImmediate::isImmediate(asValue()) ? ConstructTypeNone : asCell()->getConstructData(constructData);
222 }
223
224 ALWAYS_INLINE bool JSValue::getUInt32(uint32_t& v) const
225 {
226 return JSImmediate::isImmediate(asValue()) ? JSImmediate::getUInt32(asValue(), v) : asCell()->getUInt32(v);
227 }
228
229 ALWAYS_INLINE bool JSValue::getTruncatedInt32(int32_t& v) const
230 {
231 return JSImmediate::isImmediate(asValue()) ? JSImmediate::getTruncatedInt32(asValue(), v) : asCell()->getTruncatedInt32(v);
232 }
233
234 inline bool JSValue::getTruncatedUInt32(uint32_t& v) const
235 {
236 return JSImmediate::isImmediate(asValue()) ? JSImmediate::getTruncatedUInt32(asValue(), v) : asCell()->getTruncatedUInt32(v);
237 }
238
239 inline void JSValue::mark()
240 {
241 asCell()->mark(); // callers should check !marked() before calling mark(), so this should only be called with cells
242 }
243
244 inline bool JSValue::marked() const
245 {
246 return JSImmediate::isImmediate(asValue()) || asCell()->marked();
247 }
248
249 inline JSValue* JSValue::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
250 {
251 return JSImmediate::isImmediate(asValue()) ? asValue() : asCell()->toPrimitive(exec, preferredType);
252 }
253
254 inline bool JSValue::getPrimitiveNumber(ExecState* exec, double& number, JSValue*& value)
255 {
256 if (JSImmediate::isImmediate(asValue())) {
257 number = JSImmediate::toDouble(asValue());
258 value = asValue();
259 return true;
260 }
261 return asCell()->getPrimitiveNumber(exec, number, value);
262 }
263
264 inline bool JSValue::toBoolean(ExecState* exec) const
265 {
266 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toBoolean(asValue()) : asCell()->toBoolean(exec);
267 }
268
269 ALWAYS_INLINE double JSValue::toNumber(ExecState* exec) const
270 {
271 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toDouble(asValue()) : asCell()->toNumber(exec);
272 }
273
274 inline UString JSValue::toString(ExecState* exec) const
275 {
276 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toString(asValue()) : asCell()->toString(exec);
277 }
278
279 inline JSObject* JSValue::toObject(ExecState* exec) const
280 {
281 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toObject(asValue(), exec) : asCell()->toObject(exec);
282 }
283
284 inline JSObject* JSValue::toThisObject(ExecState* exec) const
285 {
286 if (UNLIKELY(JSImmediate::isImmediate(asValue())))
287 return JSImmediate::toThisObject(asValue(), exec);
288 return asCell()->toThisObject(exec);
289 }
290
291 inline bool JSValue::needsThisConversion() const
292 {
293 if (UNLIKELY(JSImmediate::isImmediate(asValue())))
294 return true;
295 return asCell()->structure()->typeInfo().needsThisConversion();
296 }
297
298 inline UString JSValue::toThisString(ExecState* exec) const
299 {
300 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toString(asValue()) : asCell()->toThisString(exec);
301 }
302
303 inline JSValue* JSValue::getJSNumber()
304 {
305
306 return JSImmediate::isNumber(asValue()) ? asValue() : JSImmediate::isImmediate(asValue()) ? noValue() : asCell()->getJSNumber();
307 }
308
309} // namespace JSC
310
311#endif // JSCell_h
Note: See TracBrowser for help on using the repository browser.