Changeset 197833 in webkit for trunk/Source/JavaScriptCore/dfg/DFGLazyJSValue.cpp
- Timestamp:
- Mar 8, 2016, 9:16:47 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/dfg/DFGLazyJSValue.cpp
r173069 r197833 1 1 /* 2 * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.2 * Copyright (C) 2013, 2014, 2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 #if ENABLE(DFG_JIT) 30 30 31 #include "CCallHelpers.h" 32 #include "DFGGraph.h" 31 33 #include "JSCInlines.h" 34 #include "LinkBuffer.h" 32 35 33 36 namespace JSC { namespace DFG { 34 37 38 LazyJSValue LazyJSValue::newString(Graph& graph, const String& string) 39 { 40 LazyJSValue result; 41 result.m_kind = NewStringImpl; 42 result.u.stringImpl = graph.m_localStrings.add(string).iterator->impl(); 43 return result; 44 } 45 35 46 JSValue LazyJSValue::getValue(VM& vm) const 36 47 { … … 41 52 return jsSingleCharacterString(&vm, u.character); 42 53 case KnownStringImpl: 54 case NewStringImpl: 43 55 return jsString(&vm, u.stringImpl); 44 56 } … … 74 86 75 87 return triState(WTF::equal(stringImpl, string)); 88 } 89 90 const StringImpl* LazyJSValue::tryGetStringImpl() const 91 { 92 switch (m_kind) { 93 case KnownStringImpl: 94 case NewStringImpl: 95 return u.stringImpl; 96 97 case KnownValue: 98 if (JSString* string = jsDynamicCast<JSString*>(value()->value())) 99 return string->tryGetValueImpl(); 100 return nullptr; 101 102 default: 103 return nullptr; 104 } 105 } 106 107 String LazyJSValue::tryGetString(Graph& graph) const 108 { 109 switch (m_kind) { 110 case NewStringImpl: 111 return u.stringImpl; 112 113 case SingleCharacterString: 114 return String(&u.character, 1); 115 116 default: 117 if (const StringImpl* string = tryGetStringImpl()) { 118 unsigned ginormousStringLength = 10000; 119 if (string->length() > ginormousStringLength) 120 return String(); 121 122 auto result = graph.m_copiedStrings.add(string, String()); 123 if (result.isNewEntry) 124 result.iterator->value = string->isolatedCopy(); 125 return result.iterator->value; 126 } 127 128 return String(); 129 } 76 130 } 77 131 … … 86 140 return equalToSingleCharacter(value()->value(), other.character()); 87 141 case KnownStringImpl: 142 case NewStringImpl: 88 143 return equalToStringImpl(value()->value(), other.stringImpl()); 89 144 } … … 94 149 return triState(character() == other.character()); 95 150 case KnownStringImpl: 151 case NewStringImpl: 96 152 if (other.stringImpl()->length() != 1) 97 153 return FalseTriState; … … 102 158 break; 103 159 case KnownStringImpl: 160 case NewStringImpl: 104 161 switch (other.m_kind) { 105 162 case KnownStringImpl: 163 case NewStringImpl: 106 164 return triState(WTF::equal(stringImpl(), other.stringImpl())); 107 165 default: … … 144 202 } 145 203 204 void LazyJSValue::emit(CCallHelpers& jit, JSValueRegs result) const 205 { 206 if (m_kind == KnownValue) { 207 jit.moveValue(value()->value(), result); 208 return; 209 } 210 211 // It must be some kind of cell. 212 #if USE(JSVALUE32_64) 213 jit.move(CCallHelpers::TrustedImm32(JSValue::CellTag), result.tagGPR()); 214 #endif 215 CCallHelpers::DataLabelPtr label = jit.moveWithPatch( 216 CCallHelpers::TrustedImmPtr(static_cast<size_t>(0xd1e7beeflu)), 217 result.payloadGPR()); 218 219 LazyJSValue thisValue = *this; 220 221 // Once we do this, we're committed. Otherwise we leak memory. Note that we call ref/deref 222 // manually to ensure that there is no concurrency shadiness. We are doing something here 223 // that might be rather brutal: transfering ownership of this string. 224 if (m_kind == NewStringImpl) 225 thisValue.u.stringImpl->ref(); 226 227 CodeBlock* codeBlock = jit.codeBlock(); 228 229 jit.addLinkTask( 230 [codeBlock, label, thisValue] (LinkBuffer& linkBuffer) { 231 JSValue realValue = thisValue.getValue(linkBuffer.vm()); 232 RELEASE_ASSERT(realValue.isCell()); 233 234 codeBlock->addConstant(realValue); 235 236 if (thisValue.m_kind == NewStringImpl) 237 thisValue.u.stringImpl->deref(); 238 239 linkBuffer.patch(label, realValue.asCell()); 240 }); 241 } 242 146 243 void LazyJSValue::dumpInContext(PrintStream& out, DumpContext* context) const 147 244 { … … 156 253 return; 157 254 case KnownStringImpl: 158 out.print("Lazy:String(", stringImpl(), ")"); 255 out.print("Lazy:KnownString(", stringImpl(), ")"); 256 return; 257 case NewStringImpl: 258 out.print("Lazy:NewString(", stringImpl(), ")"); 159 259 return; 160 260 }
Note:
See TracChangeset
for help on using the changeset viewer.