source: webkit/trunk/JavaScriptCore/runtime/JSCell.cpp@ 49065

Last change on this file since 49065 was 48067, checked in by Darin Adler, 16 years ago

JavaScriptCore: DateInstance object collected on ARM JIT (JSValue: WTF_USE_JSVALUE32)
https://bugs.webkit.org/show_bug.cgi?id=28909

Patch by Darin Adler <Darin Adler> on 2009-09-04
Reviewed by Geoff Garen.

Part one.

Make some improvements to garbage collection code:

1) Fix the two classes that had the default mark bit set but

should not.

2) Remove checks of the mark bit outside the MarkStack::append

function; they are redundant.

3) Make more callers use the checked asCell and asObject

casting functions rather than unchecked casts.

4) Removed some GC-related functions because these operations are

no longer things that code other than the core GC code needs
to do directly. Fixed callers that were calling them.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::markAggregate): Removed unneeded check of the mark
bit before calling MarkStack::append.

  • interpreter/Register.h: Removed unneeded marked and markChildren

functions.

  • jit/JITStubs.cpp:

(op_eq): Removed unneeded assertions, instead using checked casting
functions such as asObject.

  • runtime/ArgList.h: Added now-needed forward declaration of MarkStack.
  • runtime/GetterSetter.cpp:

(JSC::GetterSetter::markChildren): Remmoved unneeded check of the mark bit.

  • runtime/GlobalEvalFunction.h:

(JSC::GlobalEvalFunction::createStructure): Added. Fixes a bug where the
HasDefaultMark bit was set.

  • runtime/JSCell.cpp:

(JSC::JSCell::getObject): Use asObject to avoid a direct static_cast.

  • runtime/JSObject.h:

(JSC::asObject): Added an overload for JSCell* and changed the JSValue
version to call it.
(JSC::JSValue::get): Use asObject to avoid a direct static_cast.

  • runtime/JSValue.h: Moved some stray includes that were outside the

header guard inside it. Not sure how that happened! Removed the
GC-related member functions markChildren, hasChildren, marked, and
markDirect.

  • runtime/JSWrapperObject.h: Made markChildren private.

(JSC::JSWrapperObject::createStructure): Added. Fixes a bug where the
HasDefaultMark bit was set. Later we may want to optimize this for
wrapper types that never have cells in their internal values, but there
is no measured performance regression in SunSpider or V8 doing this
all the time.

  • runtime/MarkStack.cpp: Tweaked formatting.

JavaScriptGlue: * JSValueWrapper.cpp:
(JSValueWrapper::JSObjectMark): Removed a check of the mark
bit. It's OK to do more work in this case, and there is no
longer a public function to access the mark bit.

Reviewed by Geoff Garen.

  • Property svn:eol-style set to native
File size: 6.0 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 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#include "config.h"
24#include "JSCell.h"
25
26#include "JSFunction.h"
27#include "JSString.h"
28#include "JSObject.h"
29#include <wtf/MathExtras.h>
30
31namespace JSC {
32
33#if defined NAN && defined INFINITY
34
35extern const double NaN = NAN;
36extern const double Inf = INFINITY;
37
38#else // !(defined NAN && defined INFINITY)
39
40// The trick is to define the NaN and Inf globals with a different type than the declaration.
41// This trick works because the mangled name of the globals does not include the type, although
42// I'm not sure that's guaranteed. There could be alignment issues with this, since arrays of
43// characters don't necessarily need the same alignment doubles do, but for now it seems to work.
44// It would be good to figure out a 100% clean way that still avoids code that runs at init time.
45
46// Note, we have to use union to ensure alignment. Otherwise, NaN_Bytes can start anywhere,
47// while NaN_double has to be 4-byte aligned for 32-bits.
48// With -fstrict-aliasing enabled, unions are the only safe way to do type masquerading.
49
50static const union {
51 struct {
52 unsigned char NaN_Bytes[8];
53 unsigned char Inf_Bytes[8];
54 } bytes;
55
56 struct {
57 double NaN_Double;
58 double Inf_Double;
59 } doubles;
60
61} NaNInf = { {
62#if PLATFORM(BIG_ENDIAN)
63 { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 },
64 { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 }
65#elif PLATFORM(MIDDLE_ENDIAN)
66 { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 },
67 { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 }
68#else
69 { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f },
70 { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f }
71#endif
72} } ;
73
74extern const double NaN = NaNInf.doubles.NaN_Double;
75extern const double Inf = NaNInf.doubles.Inf_Double;
76
77#endif // !(defined NAN && defined INFINITY)
78
79void* JSCell::operator new(size_t size, ExecState* exec)
80{
81#ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
82 return exec->heap()->inlineAllocate(size);
83#else
84 return exec->heap()->allocate(size);
85#endif
86}
87
88bool JSCell::getUInt32(uint32_t&) const
89{
90 return false;
91}
92
93bool JSCell::getString(UString&stringValue) const
94{
95 if (!isString())
96 return false;
97 stringValue = static_cast<const JSString*>(this)->value();
98 return true;
99}
100
101UString JSCell::getString() const
102{
103 return isString() ? static_cast<const JSString*>(this)->value() : UString();
104}
105
106JSObject* JSCell::getObject()
107{
108 return isObject() ? asObject(this) : 0;
109}
110
111const JSObject* JSCell::getObject() const
112{
113 return isObject() ? static_cast<const JSObject*>(this) : 0;
114}
115
116CallType JSCell::getCallData(CallData&)
117{
118 return CallTypeNone;
119}
120
121ConstructType JSCell::getConstructData(ConstructData&)
122{
123 return ConstructTypeNone;
124}
125
126bool JSCell::getOwnPropertySlot(ExecState* exec, const Identifier& identifier, PropertySlot& slot)
127{
128 // This is not a general purpose implementation of getOwnPropertySlot.
129 // It should only be called by JSValue::get.
130 // It calls getPropertySlot, not getOwnPropertySlot.
131 JSObject* object = toObject(exec);
132 slot.setBase(object);
133 if (!object->getPropertySlot(exec, identifier, slot))
134 slot.setUndefined();
135 return true;
136}
137
138bool JSCell::getOwnPropertySlot(ExecState* exec, unsigned identifier, PropertySlot& slot)
139{
140 // This is not a general purpose implementation of getOwnPropertySlot.
141 // It should only be called by JSValue::get.
142 // It calls getPropertySlot, not getOwnPropertySlot.
143 JSObject* object = toObject(exec);
144 slot.setBase(object);
145 if (!object->getPropertySlot(exec, identifier, slot))
146 slot.setUndefined();
147 return true;
148}
149
150void JSCell::put(ExecState* exec, const Identifier& identifier, JSValue value, PutPropertySlot& slot)
151{
152 toObject(exec)->put(exec, identifier, value, slot);
153}
154
155void JSCell::put(ExecState* exec, unsigned identifier, JSValue value)
156{
157 toObject(exec)->put(exec, identifier, value);
158}
159
160bool JSCell::deleteProperty(ExecState* exec, const Identifier& identifier)
161{
162 return toObject(exec)->deleteProperty(exec, identifier);
163}
164
165bool JSCell::deleteProperty(ExecState* exec, unsigned identifier)
166{
167 return toObject(exec)->deleteProperty(exec, identifier);
168}
169
170JSObject* JSCell::toThisObject(ExecState* exec) const
171{
172 return toObject(exec);
173}
174
175UString JSCell::toThisString(ExecState* exec) const
176{
177 return toThisObject(exec)->toString(exec);
178}
179
180JSString* JSCell::toThisJSString(ExecState* exec)
181{
182 return jsString(exec, toThisString(exec));
183}
184
185const ClassInfo* JSCell::classInfo() const
186{
187 return 0;
188}
189
190JSValue JSCell::getJSNumber()
191{
192 return JSValue();
193}
194
195bool JSCell::isGetterSetter() const
196{
197 return false;
198}
199
200JSValue JSCell::toPrimitive(ExecState*, PreferredPrimitiveType) const
201{
202 ASSERT_NOT_REACHED();
203 return JSValue();
204}
205
206bool JSCell::getPrimitiveNumber(ExecState*, double&, JSValue&)
207{
208 ASSERT_NOT_REACHED();
209 return false;
210}
211
212bool JSCell::toBoolean(ExecState*) const
213{
214 ASSERT_NOT_REACHED();
215 return false;
216}
217
218double JSCell::toNumber(ExecState*) const
219{
220 ASSERT_NOT_REACHED();
221 return 0;
222}
223
224UString JSCell::toString(ExecState*) const
225{
226 ASSERT_NOT_REACHED();
227 return UString();
228}
229
230JSObject* JSCell::toObject(ExecState*) const
231{
232 ASSERT_NOT_REACHED();
233 return 0;
234}
235
236} // namespace JSC
Note: See TracBrowser for help on using the repository browser.