void ProcessingInstruction::checkStyleSheet() { if (m_target == "xml-stylesheet" && document().frame() && parentNode() == &document()) { // see http://www.w3.org/TR/xml-stylesheet/ // ### support stylesheet included in a fragment of this (or another) document // ### make sure this gets called when adding from javascript bool attrsOk; const HashMap<String, String> attrs = parseAttributes(data(), attrsOk); if (!attrsOk) return; HashMap<String, String>::const_iterator i = attrs.find("type"); String type; if (i != attrs.end()) type = i->value; m_isCSS = type.isEmpty() || type == "text/css"; #if ENABLE(XSLT) m_isXSL = (type == "text/xml" || type == "text/xsl" || type == "application/xml" || type == "application/xhtml+xml" || type == "application/rss+xml" || type == "application/atom+xml"); if (!m_isCSS && !m_isXSL) #else if (!m_isCSS) #endif return; String href = attrs.get("href"); String alternate = attrs.get("alternate"); m_alternate = alternate == "yes"; m_title = attrs.get("title"); m_media = attrs.get("media"); if (m_alternate && m_title.isEmpty()) return; if (href.length() > 1 && href[0] == '#') { m_localHref = href.substring(1); #if ENABLE(XSLT) // We need to make a synthetic XSLStyleSheet that is embedded. It needs to be able // to kick off import/include loads that can hang off some parent sheet. if (m_isXSL) { URL finalURL(ParsedURLString, m_localHref); m_sheet = XSLStyleSheet::createEmbedded(this, finalURL); m_loading = false; } #endif } else { if (m_cachedSheet) { m_cachedSheet->removeClient(*this); m_cachedSheet = nullptr; } String url = document().completeURL(href).string(); if (!dispatchBeforeLoadEvent(url)) return; m_loading = true; document().styleScope().addPendingSheet(); #if ENABLE(XSLT) if (m_isXSL) { auto options = CachedResourceLoader::defaultCachedResourceOptions(); options.mode = FetchOptions::Mode::SameOrigin; m_cachedSheet = document().cachedResourceLoader().requestXSLStyleSheet({ResourceRequest(document().completeURL(href)), options}); } else #endif { String charset = attrs.get("charset"); CachedResourceRequest request(document().completeURL(href), CachedResourceLoader::defaultCachedResourceOptions(), std::nullopt, charset.isEmpty() ? document().charset() : WTFMove(charset)); m_cachedSheet = document().cachedResourceLoader().requestCSSStyleSheet(WTFMove(request)); } if (m_cachedSheet) m_cachedSheet->addClient(*this); else { // The request may have been denied if (for example) the stylesheet is local and the document is remote. m_loading = false; document().styleScope().removePendingSheet(); #if ENABLE(XSLT) if (m_isXSL) document().styleScope().flushPendingUpdate(); #endif } } } }
static void compileStub( unsigned exitID, JITCode* jitCode, OSRExit& exit, VM* vm, CodeBlock* codeBlock) { StackMaps::Record* record = nullptr; for (unsigned i = jitCode->stackmaps.records.size(); i--;) { record = &jitCode->stackmaps.records[i]; if (record->patchpointID == exit.m_stackmapID) break; } RELEASE_ASSERT(record->patchpointID == exit.m_stackmapID); // This code requires framePointerRegister is the same as callFrameRegister static_assert(MacroAssembler::framePointerRegister == GPRInfo::callFrameRegister, "MacroAssembler::framePointerRegister and GPRInfo::callFrameRegister must be the same"); CCallHelpers jit(vm, codeBlock); // We need scratch space to save all registers, to build up the JS stack, to deal with unwind // fixup, pointers to all of the objects we materialize, and the elements inside those objects // that we materialize. // Figure out how much space we need for those object allocations. unsigned numMaterializations = 0; size_t maxMaterializationNumArguments = 0; for (ExitTimeObjectMaterialization* materialization : exit.m_materializations) { numMaterializations++; maxMaterializationNumArguments = std::max( maxMaterializationNumArguments, materialization->properties().size()); } ScratchBuffer* scratchBuffer = vm->scratchBufferForSize( sizeof(EncodedJSValue) * ( exit.m_values.size() + numMaterializations + maxMaterializationNumArguments) + requiredScratchMemorySizeInBytes() + codeBlock->calleeSaveRegisters()->size() * sizeof(uint64_t)); EncodedJSValue* scratch = scratchBuffer ? static_cast<EncodedJSValue*>(scratchBuffer->dataBuffer()) : 0; EncodedJSValue* materializationPointers = scratch + exit.m_values.size(); EncodedJSValue* materializationArguments = materializationPointers + numMaterializations; char* registerScratch = bitwise_cast<char*>(materializationArguments + maxMaterializationNumArguments); uint64_t* unwindScratch = bitwise_cast<uint64_t*>(registerScratch + requiredScratchMemorySizeInBytes()); HashMap<ExitTimeObjectMaterialization*, EncodedJSValue*> materializationToPointer; unsigned materializationCount = 0; for (ExitTimeObjectMaterialization* materialization : exit.m_materializations) { materializationToPointer.add( materialization, materializationPointers + materializationCount++); } // Note that we come in here, the stack used to be as LLVM left it except that someone called pushToSave(). // We don't care about the value they saved. But, we do appreciate the fact that they did it, because we use // that slot for saveAllRegisters(). saveAllRegisters(jit, registerScratch); // Bring the stack back into a sane form and assert that it's sane. jit.popToRestore(GPRInfo::regT0); jit.checkStackPointerAlignment(); if (vm->m_perBytecodeProfiler && codeBlock->jitCode()->dfgCommon()->compilation) { Profiler::Database& database = *vm->m_perBytecodeProfiler; Profiler::Compilation* compilation = codeBlock->jitCode()->dfgCommon()->compilation.get(); Profiler::OSRExit* profilerExit = compilation->addOSRExit( exitID, Profiler::OriginStack(database, codeBlock, exit.m_codeOrigin), exit.m_kind, exit.m_kind == UncountableInvalidation); jit.add64(CCallHelpers::TrustedImm32(1), CCallHelpers::AbsoluteAddress(profilerExit->counterAddress())); } // The remaining code assumes that SP/FP are in the same state that they were in the FTL's // call frame. // Get the call frame and tag thingies. // Restore the exiting function's callFrame value into a regT4 jit.move(MacroAssembler::TrustedImm64(TagTypeNumber), GPRInfo::tagTypeNumberRegister); jit.move(MacroAssembler::TrustedImm64(TagMask), GPRInfo::tagMaskRegister); // Do some value profiling. if (exit.m_profileDataFormat != DataFormatNone) { record->locations[0].restoreInto(jit, jitCode->stackmaps, registerScratch, GPRInfo::regT0); reboxAccordingToFormat( exit.m_profileDataFormat, jit, GPRInfo::regT0, GPRInfo::regT1, GPRInfo::regT2); if (exit.m_kind == BadCache || exit.m_kind == BadIndexingType) { CodeOrigin codeOrigin = exit.m_codeOriginForExitProfile; if (ArrayProfile* arrayProfile = jit.baselineCodeBlockFor(codeOrigin)->getArrayProfile(codeOrigin.bytecodeIndex)) { jit.load32(MacroAssembler::Address(GPRInfo::regT0, JSCell::structureIDOffset()), GPRInfo::regT1); jit.store32(GPRInfo::regT1, arrayProfile->addressOfLastSeenStructureID()); jit.load8(MacroAssembler::Address(GPRInfo::regT0, JSCell::indexingTypeOffset()), GPRInfo::regT1); jit.move(MacroAssembler::TrustedImm32(1), GPRInfo::regT2); jit.lshift32(GPRInfo::regT1, GPRInfo::regT2); jit.or32(GPRInfo::regT2, MacroAssembler::AbsoluteAddress(arrayProfile->addressOfArrayModes())); } } if (!!exit.m_valueProfile) jit.store64(GPRInfo::regT0, exit.m_valueProfile.getSpecFailBucket(0)); } // Materialize all objects. Don't materialize an object until all // of the objects it needs have been materialized. We break cycles // by populating objects late - we only consider an object as // needing another object if the later is needed for the // allocation of the former. HashSet<ExitTimeObjectMaterialization*> toMaterialize; for (ExitTimeObjectMaterialization* materialization : exit.m_materializations) toMaterialize.add(materialization); while (!toMaterialize.isEmpty()) { unsigned previousToMaterializeSize = toMaterialize.size(); Vector<ExitTimeObjectMaterialization*> worklist; worklist.appendRange(toMaterialize.begin(), toMaterialize.end()); for (ExitTimeObjectMaterialization* materialization : worklist) { // Check if we can do anything about this right now. bool allGood = true; for (ExitPropertyValue value : materialization->properties()) { if (!value.value().isObjectMaterialization()) continue; if (!value.location().neededForMaterialization()) continue; if (toMaterialize.contains(value.value().objectMaterialization())) { // Gotta skip this one, since it needs a // materialization that hasn't been materialized. allGood = false; break; } } if (!allGood) continue; // All systems go for materializing the object. First we // recover the values of all of its fields and then we // call a function to actually allocate the beast. // We only recover the fields that are needed for the allocation. for (unsigned propertyIndex = materialization->properties().size(); propertyIndex--;) { const ExitPropertyValue& property = materialization->properties()[propertyIndex]; const ExitValue& value = property.value(); if (!property.location().neededForMaterialization()) continue; compileRecovery( jit, value, record, jitCode->stackmaps, registerScratch, materializationToPointer); jit.storePtr(GPRInfo::regT0, materializationArguments + propertyIndex); } // This call assumes that we don't pass arguments on the stack. jit.setupArgumentsWithExecState( CCallHelpers::TrustedImmPtr(materialization), CCallHelpers::TrustedImmPtr(materializationArguments)); jit.move(CCallHelpers::TrustedImmPtr(bitwise_cast<void*>(operationMaterializeObjectInOSR)), GPRInfo::nonArgGPR0); jit.call(GPRInfo::nonArgGPR0); jit.storePtr(GPRInfo::returnValueGPR, materializationToPointer.get(materialization)); // Let everyone know that we're done. toMaterialize.remove(materialization); } // We expect progress! This ensures that we crash rather than looping infinitely if there // is something broken about this fixpoint. Or, this could happen if we ever violate the // "materializations form a DAG" rule. RELEASE_ASSERT(toMaterialize.size() < previousToMaterializeSize); } // Now that all the objects have been allocated, we populate them // with the correct values. This time we can recover all the // fields, including those that are only needed for the allocation. for (ExitTimeObjectMaterialization* materialization : exit.m_materializations) { for (unsigned propertyIndex = materialization->properties().size(); propertyIndex--;) { const ExitValue& value = materialization->properties()[propertyIndex].value(); compileRecovery( jit, value, record, jitCode->stackmaps, registerScratch, materializationToPointer); jit.storePtr(GPRInfo::regT0, materializationArguments + propertyIndex); } // This call assumes that we don't pass arguments on the stack jit.setupArgumentsWithExecState( CCallHelpers::TrustedImmPtr(materialization), CCallHelpers::TrustedImmPtr(materializationToPointer.get(materialization)), CCallHelpers::TrustedImmPtr(materializationArguments)); jit.move(CCallHelpers::TrustedImmPtr(bitwise_cast<void*>(operationPopulateObjectInOSR)), GPRInfo::nonArgGPR0); jit.call(GPRInfo::nonArgGPR0); } // Save all state from wherever the exit data tells us it was, into the appropriate place in // the scratch buffer. This also does the reboxing. for (unsigned index = exit.m_values.size(); index--;) { compileRecovery( jit, exit.m_values[index], record, jitCode->stackmaps, registerScratch, materializationToPointer); jit.store64(GPRInfo::regT0, scratch + index); } // Henceforth we make it look like the exiting function was called through a register // preservation wrapper. This implies that FP must be nudged down by a certain amount. Then // we restore the various things according to either exit.m_values or by copying from the // old frame, and finally we save the various callee-save registers into where the // restoration thunk would restore them from. // Before we start messing with the frame, we need to set aside any registers that the // FTL code was preserving. for (unsigned i = codeBlock->calleeSaveRegisters()->size(); i--;) { RegisterAtOffset entry = codeBlock->calleeSaveRegisters()->at(i); jit.load64( MacroAssembler::Address(MacroAssembler::framePointerRegister, entry.offset()), GPRInfo::regT0); jit.store64(GPRInfo::regT0, unwindScratch + i); } jit.load32(CCallHelpers::payloadFor(JSStack::ArgumentCount), GPRInfo::regT2); // Let's say that the FTL function had failed its arity check. In that case, the stack will // contain some extra stuff. // // We compute the padded stack space: // // paddedStackSpace = roundUp(codeBlock->numParameters - regT2 + 1) // // The stack will have regT2 + CallFrameHeaderSize stuff. // We want to make the stack look like this, from higher addresses down: // // - argument padding // - actual arguments // - call frame header // This code assumes that we're dealing with FunctionCode. RELEASE_ASSERT(codeBlock->codeType() == FunctionCode); jit.add32( MacroAssembler::TrustedImm32(-codeBlock->numParameters()), GPRInfo::regT2, GPRInfo::regT3); MacroAssembler::Jump arityIntact = jit.branch32( MacroAssembler::GreaterThanOrEqual, GPRInfo::regT3, MacroAssembler::TrustedImm32(0)); jit.neg32(GPRInfo::regT3); jit.add32(MacroAssembler::TrustedImm32(1 + stackAlignmentRegisters() - 1), GPRInfo::regT3); jit.and32(MacroAssembler::TrustedImm32(-stackAlignmentRegisters()), GPRInfo::regT3); jit.add32(GPRInfo::regT3, GPRInfo::regT2); arityIntact.link(&jit); CodeBlock* baselineCodeBlock = jit.baselineCodeBlockFor(exit.m_codeOrigin); // First set up SP so that our data doesn't get clobbered by signals. unsigned conservativeStackDelta = (exit.m_values.numberOfLocals() + baselineCodeBlock->calleeSaveSpaceAsVirtualRegisters()) * sizeof(Register) + maxFrameExtentForSlowPathCall; conservativeStackDelta = WTF::roundUpToMultipleOf( stackAlignmentBytes(), conservativeStackDelta); jit.addPtr( MacroAssembler::TrustedImm32(-conservativeStackDelta), MacroAssembler::framePointerRegister, MacroAssembler::stackPointerRegister); jit.checkStackPointerAlignment(); RegisterSet allFTLCalleeSaves = RegisterSet::ftlCalleeSaveRegisters(); RegisterAtOffsetList* baselineCalleeSaves = baselineCodeBlock->calleeSaveRegisters(); for (Reg reg = Reg::first(); reg <= Reg::last(); reg = reg.next()) { if (!allFTLCalleeSaves.get(reg)) continue; unsigned unwindIndex = codeBlock->calleeSaveRegisters()->indexOf(reg); RegisterAtOffset* baselineRegisterOffset = baselineCalleeSaves->find(reg); if (reg.isGPR()) { GPRReg regToLoad = baselineRegisterOffset ? GPRInfo::regT0 : reg.gpr(); if (unwindIndex == UINT_MAX) { // The FTL compilation didn't preserve this register. This means that it also // didn't use the register. So its value at the beginning of OSR exit should be // preserved by the thunk. Luckily, we saved all registers into the register // scratch buffer, so we can restore them from there. jit.load64(registerScratch + offsetOfReg(reg), regToLoad); } else { // The FTL compilation preserved the register. Its new value is therefore // irrelevant, but we can get the value that was preserved by using the unwind // data. We've already copied all unwind-able preserved registers into the unwind // scratch buffer, so we can get it from there. jit.load64(unwindScratch + unwindIndex, regToLoad); } if (baselineRegisterOffset) jit.store64(regToLoad, MacroAssembler::Address(MacroAssembler::framePointerRegister, baselineRegisterOffset->offset())); } else { FPRReg fpRegToLoad = baselineRegisterOffset ? FPRInfo::fpRegT0 : reg.fpr(); if (unwindIndex == UINT_MAX) jit.loadDouble(MacroAssembler::TrustedImmPtr(registerScratch + offsetOfReg(reg)), fpRegToLoad); else jit.loadDouble(MacroAssembler::TrustedImmPtr(unwindScratch + unwindIndex), fpRegToLoad); if (baselineRegisterOffset) jit.storeDouble(fpRegToLoad, MacroAssembler::Address(MacroAssembler::framePointerRegister, baselineRegisterOffset->offset())); } } size_t baselineVirtualRegistersForCalleeSaves = baselineCodeBlock->calleeSaveSpaceAsVirtualRegisters(); // Now get state out of the scratch buffer and place it back into the stack. The values are // already reboxed so we just move them. for (unsigned index = exit.m_values.size(); index--;) { VirtualRegister reg = exit.m_values.virtualRegisterForIndex(index); if (reg.isLocal() && reg.toLocal() < static_cast<int>(baselineVirtualRegistersForCalleeSaves)) continue; jit.load64(scratch + index, GPRInfo::regT0); jit.store64(GPRInfo::regT0, AssemblyHelpers::addressFor(reg)); } handleExitCounts(jit, exit); reifyInlinedCallFrames(jit, exit); adjustAndJumpToTarget(jit, exit, false); LinkBuffer patchBuffer(*vm, jit, codeBlock); exit.m_code = FINALIZE_CODE_IF( shouldDumpDisassembly() || Options::verboseOSR() || Options::verboseFTLOSRExit(), patchBuffer, ("FTL OSR exit #%u (%s, %s) from %s, with operands = %s, and record = %s", exitID, toCString(exit.m_codeOrigin).data(), exitKindToString(exit.m_kind), toCString(*codeBlock).data(), toCString(ignoringContext<DumpContext>(exit.m_values)).data(), toCString(*record).data())); }
static void compileRecovery( CCallHelpers& jit, const ExitValue& value, StackMaps::Record* record, StackMaps& stackmaps, char* registerScratch, const HashMap<ExitTimeObjectMaterialization*, EncodedJSValue*>& materializationToPointer) { switch (value.kind()) { case ExitValueDead: jit.move(MacroAssembler::TrustedImm64(JSValue::encode(jsUndefined())), GPRInfo::regT0); break; case ExitValueConstant: jit.move(MacroAssembler::TrustedImm64(JSValue::encode(value.constant())), GPRInfo::regT0); break; case ExitValueArgument: record->locations[value.exitArgument().argument()].restoreInto( jit, stackmaps, registerScratch, GPRInfo::regT0); break; case ExitValueInJSStack: case ExitValueInJSStackAsInt32: case ExitValueInJSStackAsInt52: case ExitValueInJSStackAsDouble: jit.load64(AssemblyHelpers::addressFor(value.virtualRegister()), GPRInfo::regT0); break; case ExitValueRecovery: record->locations[value.rightRecoveryArgument()].restoreInto( jit, stackmaps, registerScratch, GPRInfo::regT1); record->locations[value.leftRecoveryArgument()].restoreInto( jit, stackmaps, registerScratch, GPRInfo::regT0); switch (value.recoveryOpcode()) { case AddRecovery: switch (value.recoveryFormat()) { case DataFormatInt32: jit.add32(GPRInfo::regT1, GPRInfo::regT0); break; case DataFormatInt52: jit.add64(GPRInfo::regT1, GPRInfo::regT0); break; default: RELEASE_ASSERT_NOT_REACHED(); break; } break; case SubRecovery: switch (value.recoveryFormat()) { case DataFormatInt32: jit.sub32(GPRInfo::regT1, GPRInfo::regT0); break; case DataFormatInt52: jit.sub64(GPRInfo::regT1, GPRInfo::regT0); break; default: RELEASE_ASSERT_NOT_REACHED(); break; } break; default: RELEASE_ASSERT_NOT_REACHED(); break; } break; case ExitValueMaterializeNewObject: jit.loadPtr(materializationToPointer.get(value.objectMaterialization()), GPRInfo::regT0); break; default: RELEASE_ASSERT_NOT_REACHED(); break; } reboxAccordingToFormat( value.dataFormat(), jit, GPRInfo::regT0, GPRInfo::regT1, GPRInfo::regT2); }
void SamplingTool::dump(ExecState* exec) { // Tidies up SunSpider output by removing short scripts - such a small number of samples would likely not be useful anyhow. if (m_sampleCount < 10) return; // (1) Build and sort 'opcodeSampleInfo' array. OpcodeSampleInfo opcodeSampleInfo[numOpcodeIDs]; for (int i = 0; i < numOpcodeIDs; ++i) { opcodeSampleInfo[i].opcode = static_cast<OpcodeID>(i); opcodeSampleInfo[i].count = m_opcodeSamples[i]; opcodeSampleInfo[i].countInCTIFunctions = m_opcodeSamplesInCTIFunctions[i]; } qsort(opcodeSampleInfo, numOpcodeIDs, sizeof(OpcodeSampleInfo), compareOpcodeIndicesSampling); // (2) Print Opcode sampling results. printf("\nOpcode samples [*]\n"); printf(" sample %% of %% of | cti cti %%\n"); printf("opcode count VM total | count of self\n"); printf("------------------------------------------------------- | ----------------\n"); for (int i = 0; i < numOpcodeIDs; ++i) { long long count = opcodeSampleInfo[i].count; if (!count) continue; OpcodeID opcode = opcodeSampleInfo[i].opcode; const char* opcodeName = opcodeNames[opcode]; const char* opcodePadding = padOpcodeName(opcode, 28); double percentOfVM = (static_cast<double>(count) * 100) / m_opcodeSampleCount; double percentOfTotal = (static_cast<double>(count) * 100) / m_sampleCount; long long countInCTIFunctions = opcodeSampleInfo[i].countInCTIFunctions; double percentInCTIFunctions = (static_cast<double>(countInCTIFunctions) * 100) / count; fprintf(stdout, "%s:%s%-6lld %.3f%%\t%.3f%%\t | %-6lld %.3f%%\n", opcodeName, opcodePadding, count, percentOfVM, percentOfTotal, countInCTIFunctions, percentInCTIFunctions); } printf("\n[*] Samples inside host code are not charged to any Opcode.\n\n"); printf("\tSamples inside VM:\t\t%lld / %lld (%.3f%%)\n", m_opcodeSampleCount, m_sampleCount, (static_cast<double>(m_opcodeSampleCount) * 100) / m_sampleCount); printf("\tSamples inside host code:\t%lld / %lld (%.3f%%)\n\n", m_sampleCount - m_opcodeSampleCount, m_sampleCount, (static_cast<double>(m_sampleCount - m_opcodeSampleCount) * 100) / m_sampleCount); printf("\tsample count:\tsamples inside this opcode\n"); printf("\t%% of VM:\tsample count / all opcode samples\n"); printf("\t%% of total:\tsample count / all samples\n"); printf("\t--------------\n"); printf("\tcti count:\tsamples inside a CTI function called by this opcode\n"); printf("\tcti %% of self:\tcti count / sample count\n"); // (3) Build and sort 'codeBlockSamples' array. int scopeCount = m_scopeSampleMap->size(); Vector<ScopeSampleRecord*> codeBlockSamples(scopeCount); ScopeSampleRecordMap::iterator iter = m_scopeSampleMap->begin(); for (int i = 0; i < scopeCount; ++i, ++iter) codeBlockSamples[i] = iter->second; qsort(codeBlockSamples.begin(), scopeCount, sizeof(ScopeSampleRecord*), compareScopeSampleRecords); // (4) Print data from 'codeBlockSamples' array. printf("\nCodeBlock samples\n\n"); for (int i = 0; i < scopeCount; ++i) { ScopeSampleRecord* record = codeBlockSamples[i]; CodeBlock* codeBlock = record->m_codeBlock; double blockPercent = (record->m_sampleCount * 100.0) / m_sampleCount; if (blockPercent >= 1) { Instruction* code = codeBlock->instructions.begin(); printf("#%d: %s:%d: %d / %lld (%.3f%%)\n", i + 1, record->m_scope->sourceURL().UTF8String().c_str(), codeBlock->lineNumberForVPC(code), record->m_sampleCount, m_sampleCount, blockPercent); if (i < 10) { HashMap<unsigned,unsigned> lineCounts; codeBlock->dump(exec); printf(" Opcode and line number samples [*]\n\n"); for (unsigned op = 0; op < record->m_size; ++op) { int count = record->m_samples[op]; if (count) { printf(" [% 4d] has sample count: % 4d\n", op, count); unsigned line = codeBlock->lineNumberForVPC(code+op); lineCounts.set(line, (lineCounts.contains(line) ? lineCounts.get(line) : 0) + count); } } printf("\n"); int linesCount = lineCounts.size(); Vector<LineCountInfo> lineCountInfo(linesCount); int lineno = 0; for (HashMap<unsigned,unsigned>::iterator iter = lineCounts.begin(); iter != lineCounts.end(); ++iter, ++lineno) { lineCountInfo[lineno].line = iter->first; lineCountInfo[lineno].count = iter->second; } qsort(lineCountInfo.begin(), linesCount, sizeof(LineCountInfo), compareLineCountInfoSampling); for (lineno = 0; lineno < linesCount; ++lineno) { printf(" Line #%d has sample count %d.\n", lineCountInfo[lineno].line, lineCountInfo[lineno].count); } printf("\n"); printf(" [*] Samples inside host code are charged to the calling Opcode.\n"); printf(" Samples on a call / return boundary are not charged to a specific opcode or line.\n\n"); printf(" Samples on a call / return boundary: %d / %d (%.3f%%)\n\n", record->m_sampleCount - record->m_opcodeSampleCount, record->m_sampleCount, (static_cast<double>(record->m_sampleCount - record->m_opcodeSampleCount) * 100) / record->m_sampleCount); } } } }
FontData* CSSFontSelector::getFontData(const FontDescription& fontDescription, const AtomicString& familyName) { if (m_fontFaces.isEmpty()) { if (familyName.startsWith("-webkit-")) return fontDataForGenericFamily(m_document, fontDescription, familyName); return 0; } String family = familyName.string(); Vector<RefPtr<CSSFontFace> >* familyFontFaces = m_fontFaces.get(family); // If no face was found, then return 0 and let the OS come up with its best match for the name. if (!familyFontFaces || familyFontFaces->isEmpty()) { // If we were handed a generic family, but there was no match, go ahead and return the correct font based off our // settings. return fontDataForGenericFamily(m_document, fontDescription, familyName); } HashMap<unsigned, RefPtr<CSSSegmentedFontFace> >* segmentedFontFaceCache = m_fonts.get(family); if (!segmentedFontFaceCache) { segmentedFontFaceCache = new HashMap<unsigned, RefPtr<CSSSegmentedFontFace> >; m_fonts.set(family, segmentedFontFaceCache); } FontTraitsMask traitsMask = fontDescription.traitsMask(); RefPtr<CSSSegmentedFontFace> face = segmentedFontFaceCache->get(traitsMask); if (!face) { face = CSSSegmentedFontFace::create(this); segmentedFontFaceCache->set(traitsMask, face); // Collect all matching faces and sort them in order of preference. Vector<CSSFontFace*, 32> candidateFontFaces; for (int i = familyFontFaces->size() - 1; i >= 0; --i) { CSSFontFace* candidate = familyFontFaces->at(i).get(); unsigned candidateTraitsMask = candidate->traitsMask(); if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask)) continue; if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask)) continue; #if ENABLE(SVG_FONTS) // For SVG Fonts that specify that they only support the "normal" variant, we will assume they are incapable // of small-caps synthesis and just ignore the font face as a candidate. if (candidate->hasSVGFontFaceSource() && (traitsMask & FontVariantSmallCapsMask) && !(candidateTraitsMask & FontVariantSmallCapsMask)) continue; #endif candidateFontFaces.append(candidate); } if (Vector<RefPtr<CSSFontFace> >* familyLocallyInstalledFontFaces = m_locallyInstalledFontFaces.get(family)) { unsigned numLocallyInstalledFontFaces = familyLocallyInstalledFontFaces->size(); for (unsigned i = 0; i < numLocallyInstalledFontFaces; ++i) { CSSFontFace* candidate = familyLocallyInstalledFontFaces->at(i).get(); unsigned candidateTraitsMask = candidate->traitsMask(); if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask)) continue; if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask)) continue; candidateFontFaces.append(candidate); } } desiredTraitsMaskForComparison = traitsMask; std::stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compareFontFaces); unsigned numCandidates = candidateFontFaces.size(); for (unsigned i = 0; i < numCandidates; ++i) face->appendFontFace(candidateFontFaces[i]); } // We have a face. Ask it for a font data. If it cannot produce one, it will fail, and the OS will take over. return face->getFontData(fontDescription); }
void HashMapTest::testPut() { { HashMap<std::string, std::string> hashMap(101); hashMap.put("KEY", "VALUE"); CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to install key/value pair", std::string("VALUE"), hashMap.get("KEY")); } { // Check my actual key instance is returned HashMap<int, std::string> map; for (int i = -32767; i < 32768; i++) { map.put(i, "foobar"); } int myKey = 0; // Put a new value at the old key position map.put(myKey, "myValue"); CPPUNIT_ASSERT(map.containsKey(myKey)); CPPUNIT_ASSERT_EQUAL(std::string("myValue"), map.get(myKey)); bool found = false; Set<int>& intSet = map.keySet(); Pointer< Iterator<int> > itr(intSet.iterator()); while (itr->hasNext()) { int key = itr->next(); found = (key == myKey); if (found) { break; } } CPPUNIT_ASSERT_MESSAGE("Should find new key instance in hashashMap", found); // Add a new key instance and check it is returned CPPUNIT_ASSERT_NO_THROW(map.remove(myKey)); map.put(myKey, "myValue"); CPPUNIT_ASSERT(map.containsKey(myKey)); CPPUNIT_ASSERT_EQUAL(std::string("myValue"), map.get(myKey)); itr.reset(intSet.iterator()); while (itr->hasNext()) { int key = itr->next(); found = (key == myKey); if (found) { break; } } CPPUNIT_ASSERT_MESSAGE("Did not find new key instance in hashashMap", found); } { // Ensure keys with identical hashcode are stored separately HashMap<MyKey, std::string> map; // Put non-equal object with same hashcode MyKey aKey; CPPUNIT_ASSERT(!map.containsKey(aKey)); map.put(aKey, "value"); MyKey aKey2; CPPUNIT_ASSERT_THROW_MESSAGE( "Should have thrown NoSuchElementException", map.remove(aKey2), NoSuchElementException); MyKey aKey3; map.put(aKey3, "foobar"); CPPUNIT_ASSERT_EQUAL(std::string("foobar"), map.get(aKey3)); CPPUNIT_ASSERT_EQUAL(std::string("value"), map.get(aKey)); } }
gpointer createHTMLElementWrapper(PassRefPtr<WebCore::HTMLElement> element) { static HashMap<WTF::AtomicStringImpl*, CreateHTMLElementWrapperFunction> map; if (map.isEmpty()) { map.set(aTag.localName().impl(), createAnchorWrapper); map.set(appletTag.localName().impl(), createAppletWrapper); #if ENABLE(VIDEO) map.set(audioTag.localName().impl(), createAudioWrapper); #endif map.set(areaTag.localName().impl(), createAreaWrapper); map.set(baseTag.localName().impl(), createBaseWrapper); map.set(basefontTag.localName().impl(), createBaseFontWrapper); map.set(blockquoteTag.localName().impl(), createBlockquoteWrapper); map.set(bodyTag.localName().impl(), createBodyWrapper); map.set(brTag.localName().impl(), createBRWrapper); map.set(buttonTag.localName().impl(), createButtonWrapper); map.set(canvasTag.localName().impl(), createCanvasWrapper); map.set(captionTag.localName().impl(), createTableCaptionWrapper); map.set(colTag.localName().impl(), createTableColWrapper); map.set(delTag.localName().impl(), createModWrapper); map.set(dirTag.localName().impl(), createDirectoryWrapper); map.set(divTag.localName().impl(), createDivWrapper); map.set(dlTag.localName().impl(), createDListWrapper); map.set(embedTag.localName().impl(), createEmbedWrapper); map.set(fieldsetTag.localName().impl(), createFieldSetWrapper); map.set(fontTag.localName().impl(), createFontWrapper); map.set(formTag.localName().impl(), createFormWrapper); map.set(frameTag.localName().impl(), createFrameWrapper); map.set(framesetTag.localName().impl(), createFrameSetWrapper); map.set(h1Tag.localName().impl(), createHeadingWrapper); map.set(headTag.localName().impl(), createHeadWrapper); map.set(hrTag.localName().impl(), createHRWrapper); map.set(htmlTag.localName().impl(), createHtmlWrapper); map.set(iframeTag.localName().impl(), createIFrameWrapper); map.set(imgTag.localName().impl(), createImageWrapper); map.set(inputTag.localName().impl(), createInputWrapper); map.set(isindexTag.localName().impl(), createIsIndexWrapper); map.set(labelTag.localName().impl(), createLabelWrapper); map.set(legendTag.localName().impl(), createLegendWrapper); map.set(liTag.localName().impl(), createLIWrapper); map.set(linkTag.localName().impl(), createLinkWrapper); map.set(mapTag.localName().impl(), createMapWrapper); map.set(marqueeTag.localName().impl(), createMarqueeWrapper); map.set(menuTag.localName().impl(), createMenuWrapper); map.set(metaTag.localName().impl(), createMetaWrapper); map.set(objectTag.localName().impl(), createObjectWrapper); map.set(olTag.localName().impl(), createOListWrapper); map.set(optgroupTag.localName().impl(), createOptGroupWrapper); map.set(optionTag.localName().impl(), createOptionWrapper); map.set(pTag.localName().impl(), createParagraphWrapper); map.set(paramTag.localName().impl(), createParamWrapper); map.set(preTag.localName().impl(), createPreWrapper); map.set(qTag.localName().impl(), createQuoteWrapper); map.set(scriptTag.localName().impl(), createScriptWrapper); map.set(selectTag.localName().impl(), createSelectWrapper); map.set(styleTag.localName().impl(), createStyleWrapper); map.set(tableTag.localName().impl(), createTableWrapper); map.set(tbodyTag.localName().impl(), createTableSectionWrapper); map.set(tdTag.localName().impl(), createTableCellWrapper); map.set(textareaTag.localName().impl(), createTextAreaWrapper); map.set(titleTag.localName().impl(), createTitleWrapper); map.set(trTag.localName().impl(), createTableRowWrapper); map.set(ulTag.localName().impl(), createUListWrapper); map.set(colgroupTag.localName().impl(), createTableColWrapper); map.set(h2Tag.localName().impl(), createHeadingWrapper); map.set(h3Tag.localName().impl(), createHeadingWrapper); map.set(h4Tag.localName().impl(), createHeadingWrapper); map.set(h5Tag.localName().impl(), createHeadingWrapper); map.set(h6Tag.localName().impl(), createHeadingWrapper); map.set(imageTag.localName().impl(), createImageWrapper); map.set(insTag.localName().impl(), createModWrapper); map.set(keygenTag.localName().impl(), createSelectWrapper); map.set(listingTag.localName().impl(), createPreWrapper); map.set(tfootTag.localName().impl(), createTableSectionWrapper); map.set(thTag.localName().impl(), createTableCellWrapper); map.set(theadTag.localName().impl(), createTableSectionWrapper); map.set(xmpTag.localName().impl(), createPreWrapper); } CreateHTMLElementWrapperFunction createWrapperFunction = map.get(element->localName().impl()); if (createWrapperFunction) return createWrapperFunction(element); return wrapHTMLElement(element.get()); }
static CFStringRef getPostScriptName(CFStringRef faceName, HDC dc) { const DWORD cMaxNameTableSize = 1024 * 1024; static HashMap<String, RetainPtr<CFStringRef> > nameMap; // Check our hash first. String faceString(faceName); RetainPtr<CFStringRef> result = nameMap.get(faceString); if (result) return result.get(); // We need to obtain the PostScript name from the name table and use it instead,. DWORD bufferSize = GetFontData(dc, 'eman', 0, NULL, 0); // "name" backwards if (bufferSize == 0 || bufferSize == GDI_ERROR || bufferSize > cMaxNameTableSize) return NULL; Vector<BYTE> bufferVector(bufferSize); BYTE* buffer = bufferVector.data(); if (GetFontData(dc, 'eman', 0, buffer, bufferSize) == GDI_ERROR) return NULL; if (bufferSize < 6) return NULL; USHORT numberOfRecords = readBigEndianWord(buffer + 2); UINT stringsOffset = readBigEndianWord(buffer + 4); if (bufferSize < stringsOffset) return NULL; BYTE* strings = buffer + stringsOffset; // Now walk each name record looking for a Mac or Windows PostScript name. UINT offset = 6; for (int i = 0; i < numberOfRecords; i++) { if (bufferSize < offset + 12) return NULL; USHORT platformID = readBigEndianWord(buffer + offset); USHORT encodingID = readBigEndianWord(buffer + offset + 2); USHORT languageID = readBigEndianWord(buffer + offset + 4); USHORT nameID = readBigEndianWord(buffer + offset + 6); USHORT length = readBigEndianWord(buffer + offset + 8); USHORT nameOffset = readBigEndianWord(buffer + offset + 10); if (platformID == 3 && encodingID == 1 && languageID == 0x409 && nameID == 6) { // This is a Windows PostScript name and is therefore UTF-16. // Pass Big Endian as the encoding. if (bufferSize < stringsOffset + nameOffset + length) return NULL; result.adoptCF(CFStringCreateWithBytes(NULL, strings + nameOffset, length, kCFStringEncodingUTF16BE, false)); break; } else if (platformID == 1 && encodingID == 0 && languageID == 0 && nameID == 6) { // This is a Mac PostScript name and is therefore ASCII. // See http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6name.html if (bufferSize < stringsOffset + nameOffset + length) return NULL; result.adoptCF(CFStringCreateWithBytes(NULL, strings + nameOffset, length, kCFStringEncodingASCII, false)); break; } offset += 12; } if (result) nameMap.set(faceString, result); return result.get(); }