Compare commits
2 Commits
DISKCACHE2
...
regalloc_c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c43d4984f | ||
|
|
cfe021ff88 |
134
mozilla/ef/Compiler/RegisterAllocator/BitSet.cpp
Normal file
134
mozilla/ef/Compiler/RegisterAllocator/BitSet.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "BitSet.h"
|
||||
|
||||
// Return the next bit after index set to true or -1 if none.
|
||||
//
|
||||
Int32 BitSet::nextOne(Int32 pos) const
|
||||
{
|
||||
++pos;
|
||||
|
||||
if (pos < 0 || Uint32(pos) >= universeSize)
|
||||
return -1;
|
||||
|
||||
Uint32 offset = getWordOffset(pos);
|
||||
Uint8 index = getBitOffset(pos);
|
||||
Word* ptr = &word[offset];
|
||||
Word currentWord = *ptr++ >> index;
|
||||
|
||||
if (currentWord != Word(0)) {
|
||||
while ((currentWord & Word(1)) == 0) {
|
||||
++index;
|
||||
currentWord >>= 1;
|
||||
}
|
||||
return (offset << nBitsInWordLog2) + index;
|
||||
}
|
||||
|
||||
Word* limit = &word[getSizeInWords(universeSize)];
|
||||
while (ptr < limit) {
|
||||
++offset;
|
||||
currentWord = *ptr++;
|
||||
if (currentWord != Word(0)) {
|
||||
index = 0;
|
||||
while ((currentWord & Word(1)) == 0) {
|
||||
++index;
|
||||
currentWord >>= 1;
|
||||
}
|
||||
return (offset << nBitsInWordLog2) + index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Return the next bit after index set to false or -1 if none.
|
||||
//
|
||||
Int32 BitSet::nextZero(Int32 pos) const
|
||||
{
|
||||
++pos;
|
||||
|
||||
if (pos < 0 || Uint32(pos) >= universeSize)
|
||||
return -1;
|
||||
|
||||
Uint32 offset = getWordOffset(pos);
|
||||
Uint8 index = getBitOffset(pos);
|
||||
Word* ptr = &word[offset];
|
||||
Word currentWord = *ptr++ >> index;
|
||||
|
||||
if (currentWord != Word(~0)) {
|
||||
for (; index < nBitsInWord; ++index) {
|
||||
if ((currentWord & Word(1)) == 0) {
|
||||
Int32 ret = (offset << nBitsInWordLog2) + index;
|
||||
return (Uint32(ret) < universeSize) ? ret : -1;
|
||||
}
|
||||
currentWord >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
Word* limit = &word[getSizeInWords(universeSize)];
|
||||
while (ptr < limit) {
|
||||
++offset;
|
||||
currentWord = *ptr++;
|
||||
if (currentWord != Word(~0)) {
|
||||
for (index = 0; index < nBitsInWord; ++index) {
|
||||
if ((currentWord & Word(1)) == 0) {
|
||||
Int32 ret = (offset << nBitsInWordLog2) + index;
|
||||
return (Uint32(ret) < universeSize) ? ret : -1;
|
||||
}
|
||||
currentWord >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
|
||||
// Print the set.
|
||||
//
|
||||
void BitSet::printPretty(LogModuleObject log)
|
||||
{
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("[ "));
|
||||
|
||||
for (Int32 i = firstOne(); i != -1; i = nextOne(i)) {
|
||||
Int32 currentBit = i;
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%d", currentBit));
|
||||
|
||||
Int32 nextBit = nextOne(currentBit);
|
||||
if (nextBit != currentBit + 1) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" "));
|
||||
continue;
|
||||
}
|
||||
|
||||
while ((nextBit != -1) && (nextBit == (currentBit + 1))) {
|
||||
currentBit = nextBit;
|
||||
nextBit = nextOne(nextBit);
|
||||
}
|
||||
|
||||
if (currentBit > (i+1))
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("-%d ", currentBit));
|
||||
else
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" %d ", currentBit));
|
||||
|
||||
i = currentBit;
|
||||
}
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("]\n"));
|
||||
}
|
||||
|
||||
#endif // DEBUG_LOG
|
||||
195
mozilla/ef/Compiler/RegisterAllocator/BitSet.h
Normal file
195
mozilla/ef/Compiler/RegisterAllocator/BitSet.h
Normal file
@@ -0,0 +1,195 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _BITSET_H_
|
||||
#define _BITSET_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "LogModule.h"
|
||||
#include "Pool.h"
|
||||
#include <string.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// BitSet -
|
||||
|
||||
class BitSet
|
||||
{
|
||||
private:
|
||||
|
||||
#if (PR_BITS_PER_WORD == 64)
|
||||
typedef Uint64 Word;
|
||||
#elif (PR_BITS_PER_WORD == 32)
|
||||
typedef Uint32 Word;
|
||||
#endif
|
||||
|
||||
static const nBitsInWord = PR_BITS_PER_WORD;
|
||||
static const nBytesInWord = PR_BYTES_PER_WORD;
|
||||
static const nBitsInWordLog2 = PR_BITS_PER_WORD_LOG2;
|
||||
static const nBytesInWordLog2 = PR_BYTES_PER_WORD_LOG2;
|
||||
|
||||
// Return the number of Word need to store the universe.
|
||||
static Uint32 getSizeInWords(Uint32 sizeOfUniverse) {return (sizeOfUniverse + (nBitsInWord - 1)) >> nBitsInWordLog2;}
|
||||
// Return the given element offset in its containing Word.
|
||||
static Uint32 getBitOffset(Uint32 element) {return element & (nBitsInWord - 1);}
|
||||
// Return the Word offset for the given element int the universe.
|
||||
static Uint32 getWordOffset(Uint32 element) {return element >> nBitsInWordLog2;}
|
||||
// Return the mask for the given bit index.
|
||||
static Word getMask(Uint8 index) {return Word(1) << index;}
|
||||
|
||||
private:
|
||||
|
||||
Uint32 universeSize; // Size of the universe
|
||||
Word* word; // universe memory.
|
||||
|
||||
private:
|
||||
|
||||
// No copy constructor.
|
||||
BitSet(const BitSet&);
|
||||
|
||||
// Check if the given set's universe is of the same size than this universe.
|
||||
void checkUniverseCompatibility(const BitSet& set) const {assert(set.universeSize == universeSize);}
|
||||
// Check if pos is valid for this set's universe.
|
||||
void checkMember(Int32 pos) const {assert(pos >=0 && Uint32(pos) < universeSize);}
|
||||
|
||||
public:
|
||||
|
||||
// Create a bitset of universeSize bits.
|
||||
BitSet(Pool& pool, Uint32 universeSize) : universeSize(universeSize) {word = new(pool) Word[getSizeInWords(universeSize)]; clear();}
|
||||
|
||||
// Return the size of this bitset.
|
||||
Uint32 getSize() const {return universeSize;}
|
||||
|
||||
// Clear the bitset.
|
||||
void clear() {memset(word, 0x00, getSizeInWords(universeSize) << nBytesInWordLog2);}
|
||||
// Clear the bit at index.
|
||||
void clear(Uint32 index) {checkMember(index); word[getWordOffset(index)] &= ~getMask(index);}
|
||||
// Set the bitset.
|
||||
void set() {memset(word, 0xFF, getSizeInWords(universeSize) << nBytesInWordLog2);}
|
||||
// Set the bit at index.
|
||||
void set(Uint32 index) {checkMember(index); word[getWordOffset(index)] |= getMask(index);}
|
||||
// Return true if the bit at index is set.
|
||||
bool test(Uint32 index) const {checkMember(index); return (word[getWordOffset(index)] & getMask(index)) != 0;}
|
||||
// Union with the given bitset.
|
||||
inline void or(const BitSet& set);
|
||||
// Intersection with the given bitset.
|
||||
inline void and(const BitSet& set);
|
||||
// Difference with the given bitset.
|
||||
inline void difference(const BitSet& set);
|
||||
// Copy set.
|
||||
inline BitSet& operator = (const BitSet& set);
|
||||
// Return true if the bitset are identical.
|
||||
friend bool operator == (const BitSet& set1, const BitSet& set2);
|
||||
// Return true if the bitset are different.
|
||||
friend bool operator != (const BitSet& set1, const BitSet& set2);
|
||||
|
||||
// Logical operators.
|
||||
BitSet& operator |= (const BitSet& set) {or(set); return *this;}
|
||||
BitSet& operator &= (const BitSet& set) {and(set); return *this;}
|
||||
BitSet& operator -= (const BitSet& set) {difference(set); return *this;}
|
||||
|
||||
// Return the first bit at set to true or -1 if none.
|
||||
Int32 firstOne() const {return nextOne(-1);}
|
||||
// Return the next bit after index set to true or -1 if none.
|
||||
Int32 nextOne(Int32 pos) const;
|
||||
// Return the first bit at set to false or -1 if none.
|
||||
Int32 firstZero() const {return nextZero(-1);}
|
||||
// Return the next bit after index set to false or -1 if none.
|
||||
Int32 nextZero(Int32 pos) const;
|
||||
|
||||
// Iterator to conform with the set API.
|
||||
typedef Int32 iterator;
|
||||
// Return true if the walk is ordered.
|
||||
static bool isOrdered() {return true;}
|
||||
// Return the iterator for the first element of this set.
|
||||
iterator begin() const {return firstOne();}
|
||||
// Return the next iterator.
|
||||
iterator advance(iterator pos) const {return nextOne(pos);}
|
||||
// Return true if the iterator is at the end of the set.
|
||||
bool done(iterator pos) const {return pos == -1;}
|
||||
// Return the element corresponding to the given iterator.
|
||||
Uint32 get(iterator pos) const {return pos;}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
// Print the set.
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
// Union with the given bitset.
|
||||
//
|
||||
inline void BitSet::or(const BitSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
Word* src = set.word;
|
||||
Word* dst = word;
|
||||
Word* limit = &src[getSizeInWords(universeSize)];
|
||||
|
||||
while (src < limit)
|
||||
*dst++ |= *src++;
|
||||
}
|
||||
|
||||
// Intersection with the given bitset.
|
||||
//
|
||||
inline void BitSet::and(const BitSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
Word* src = set.word;
|
||||
Word* dst = word;
|
||||
Word* limit = &src[getSizeInWords(universeSize)];
|
||||
|
||||
while (src < limit)
|
||||
*dst++ &= *src++;
|
||||
}
|
||||
|
||||
// Difference with the given bitset.
|
||||
//
|
||||
inline void BitSet::difference(const BitSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
Word* src = set.word;
|
||||
Word* dst = word;
|
||||
Word* limit = &src[getSizeInWords(universeSize)];
|
||||
|
||||
while (src < limit)
|
||||
*dst++ &= ~*src++;
|
||||
}
|
||||
|
||||
// Copy the given set into this set.
|
||||
//
|
||||
inline BitSet& BitSet::operator = (const BitSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
if (this != &set)
|
||||
memcpy(word, set.word, getSizeInWords(universeSize) << nBytesInWordLog2);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Return true if the given set is identical to this set.
|
||||
inline bool operator == (const BitSet& set1, const BitSet& set2)
|
||||
{
|
||||
set1.checkUniverseCompatibility(set2);
|
||||
|
||||
if (&set1 == &set2)
|
||||
return true;
|
||||
|
||||
return memcmp(set1.word, set2.word, BitSet::getSizeInWords(set1.universeSize) << BitSet::nBytesInWordLog2) == 0;
|
||||
}
|
||||
|
||||
inline bool operator != (const BitSet& set1, const BitSet& set2) {return !(set1 == set2);}
|
||||
|
||||
#endif // _BITSET_H
|
||||
159
mozilla/ef/Compiler/RegisterAllocator/Coalescing.h
Normal file
159
mozilla/ef/Compiler/RegisterAllocator/Coalescing.h
Normal file
@@ -0,0 +1,159 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _COALESCING_H_
|
||||
#define _COALESCING_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include "RegisterPressure.h"
|
||||
#include "InterferenceGraph.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "SparseSet.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
|
||||
#if 1
|
||||
// Performing an ultra conservative coalescing meens that when we look at
|
||||
// candidates (source,destination) for coalescing we need to make sure
|
||||
// that the combined interference of the source and destination register
|
||||
// will not exceed the total number of register available for the register
|
||||
// class.
|
||||
#define ULTRA_CONSERVATIVE_COALESCING
|
||||
#else
|
||||
// If we are not doing an ultra conservative coalescing we have to make sure
|
||||
// that the total number of neighbor whose degree is greater than the total
|
||||
// number of register is not greater than the total number of register.
|
||||
#undef ULTRA_CONSERVATIVE_COALESCING
|
||||
#endif
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct Coalescing
|
||||
{
|
||||
static bool coalesce(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool Coalescing<RegisterPressure>::coalesce(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
|
||||
// Initialize the lookup table
|
||||
//
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* newRange = new RegisterName[2 * rangeCount];
|
||||
RegisterName* coalescedRange = &newRange[rangeCount];
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
init(coalescedRange, rangeCount);
|
||||
|
||||
SparseSet interferences(pool, rangeCount);
|
||||
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
|
||||
bool removedInstructions = false;
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.lndList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
|
||||
// Walk the nodes in the loop nesting depth list.
|
||||
for (Int32 n = nNodes - 1; n >= 0; n--) {
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
|
||||
InstructionList::iterator it = instructions.begin();
|
||||
while (!instructions.done(it)) {
|
||||
Instruction& instruction = instructions.get(it);
|
||||
it = instructions.advance(it);
|
||||
|
||||
if ((instruction.getFlags() & ifCopy) != 0) {
|
||||
assert(instruction.getInstructionUseBegin() != instruction.getInstructionUseEnd() && instruction.getInstructionUseBegin()[0].isRegister());
|
||||
assert(instruction.getInstructionDefineBegin() != instruction.getInstructionDefineEnd() && instruction.getInstructionDefineBegin()[0].isRegister());
|
||||
|
||||
RegisterName source = findRoot(name2range[instruction.getInstructionUseBegin()[0].getRegisterName()], coalescedRange);
|
||||
RegisterName destination = findRoot(name2range[instruction.getInstructionDefineBegin()[0].getRegisterName()], coalescedRange);
|
||||
|
||||
if (source == destination) {
|
||||
instruction.remove();
|
||||
} else if (!iGraph.interfere(source, destination)) {
|
||||
InterferenceVector* sourceVector = iGraph.getInterferenceVector(source);
|
||||
InterferenceVector* destinationVector = iGraph.getInterferenceVector(destination);
|
||||
|
||||
#ifdef ULTRA_CONSERVATIVE_COALESCING
|
||||
interferences.clear();
|
||||
|
||||
InterferenceVector* vector;
|
||||
for (vector = sourceVector; vector != NULL; vector = vector->next) {
|
||||
RegisterName* neighbors = vector->neighbors;
|
||||
for (Uint32 i = 0; i < vector->count; i++)
|
||||
interferences.set(findRoot(neighbors[i], coalescedRange));
|
||||
}
|
||||
for (vector = destinationVector; vector != NULL; vector = vector->next) {
|
||||
RegisterName* neighbors = vector->neighbors;
|
||||
for (Uint32 i = 0; i < vector->count; i++)
|
||||
interferences.set(findRoot(neighbors[i], coalescedRange));
|
||||
}
|
||||
|
||||
Uint32 count = interferences.getSize();
|
||||
#else // ULTRA_CONSERVATIVE_COALESCING
|
||||
trespass("not implemented");
|
||||
Uint32 count = 0;
|
||||
#endif // ULTRA_CONSERVATIVE_COALESCING
|
||||
|
||||
if (count < 6 /* FIX: should get the number from the class */) {
|
||||
// Update the interferences vector.
|
||||
if (sourceVector == NULL) {
|
||||
iGraph.setInterferenceVector(source, destinationVector);
|
||||
sourceVector = destinationVector;
|
||||
} else if (destinationVector == NULL)
|
||||
iGraph.setInterferenceVector(destination, sourceVector);
|
||||
else {
|
||||
InterferenceVector* last = NULL;
|
||||
for (InterferenceVector* v = sourceVector; v != NULL; v = v->next)
|
||||
last = v;
|
||||
assert(last);
|
||||
last->next = destinationVector;
|
||||
iGraph.setInterferenceVector(destination, sourceVector);
|
||||
}
|
||||
// Update the interference matrix.
|
||||
for (InterferenceVector* v = sourceVector; v != NULL; v = v->next) {
|
||||
RegisterName* neighbors = v->neighbors;
|
||||
for (Uint32 i = 0; i < v->count; i++) {
|
||||
RegisterName neighbor = findRoot(neighbors[i], coalescedRange);
|
||||
iGraph.setInterference(neighbor, source);
|
||||
iGraph.setInterference(neighbor, destination);
|
||||
}
|
||||
}
|
||||
|
||||
instruction.remove();
|
||||
coalescedRange[source] = destination;
|
||||
removedInstructions = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerAllocator.rangeCount = compress(registerAllocator.name2range, coalescedRange, registerAllocator.nameCount, rangeCount);
|
||||
delete newRange;
|
||||
|
||||
return removedInstructions;
|
||||
}
|
||||
|
||||
#endif // _COALESCING_H_
|
||||
283
mozilla/ef/Compiler/RegisterAllocator/Coloring.cpp
Normal file
283
mozilla/ef/Compiler/RegisterAllocator/Coloring.cpp
Normal file
@@ -0,0 +1,283 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef NEW_LAURENTM_CODE
|
||||
|
||||
#include "Coloring.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "FastBitSet.h"
|
||||
#include "FastBitMatrix.h"
|
||||
#include "CpuInfo.h"
|
||||
|
||||
bool Coloring::
|
||||
assignRegisters(FastBitMatrix& interferenceMatrix)
|
||||
{
|
||||
PRUint32 *stackPtr = new(pool) PRUint32[vRegManager.count()];
|
||||
|
||||
return select(interferenceMatrix, stackPtr, simplify(interferenceMatrix, stackPtr));
|
||||
}
|
||||
|
||||
PRInt32 Coloring::
|
||||
getLowestSpillCostRegister(FastBitSet& bitset)
|
||||
{
|
||||
PRInt32 lowest = bitset.firstOne();
|
||||
if (lowest != -1)
|
||||
{
|
||||
Flt32 cost = vRegManager.getVirtualRegister(lowest).spillInfo.spillCost;
|
||||
for (PRInt32 r = bitset.nextOne(lowest); r != -1; r = bitset.nextOne(r))
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(r);
|
||||
if (!vReg.spillInfo.infiniteSpillCost && (vReg.spillInfo.spillCost < cost))
|
||||
{
|
||||
cost = vReg.spillInfo.spillCost;
|
||||
lowest = r;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lowest;
|
||||
}
|
||||
|
||||
PRUint32* Coloring::
|
||||
simplify(FastBitMatrix interferenceMatrix, PRUint32* stackPtr)
|
||||
{
|
||||
// first we construct the sets low and high. low contains all nodes of degree
|
||||
// inferior to the number of register available on the processor. All the
|
||||
// nodes with an high degree and a finite spill cost are placed in high.
|
||||
// Nodes of high degree and infinite spill cost are not included in either sets.
|
||||
|
||||
PRUint32 nRegisters = vRegManager.count();
|
||||
FastBitSet low(pool, nRegisters);
|
||||
FastBitSet high(pool, nRegisters);
|
||||
FastBitSet stack(pool, nRegisters);
|
||||
|
||||
for (VirtualRegisterManager::iterator i = vRegManager.begin(); !vRegManager.done(i); i = vRegManager.advance(i))
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(i);
|
||||
|
||||
if (vReg.getClass() == vrcStackSlot)
|
||||
{
|
||||
stack.set(i);
|
||||
vReg.colorRegister(nRegisters);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vReg.colorInfo.interferenceDegree < NUMBER_OF_REGISTERS)
|
||||
low.set(i);
|
||||
else // if (!vReg.spillInfo.infiniteSpillCost)
|
||||
high.set(i);
|
||||
|
||||
// Set coloring info.
|
||||
vReg.spillInfo.willSpill = false;
|
||||
|
||||
switch(vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
vReg.colorRegister(LAST_GREGISTER + 1);
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
vReg.colorRegister(LAST_FPREGISTER + 1);
|
||||
break;
|
||||
default:
|
||||
PR_ASSERT(false); // Cannot happen.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// push the stack registers
|
||||
PRInt32 j;
|
||||
for (j = stack.firstOne(); j != -1; j = stack.nextOne(j))
|
||||
*stackPtr++ = j;
|
||||
|
||||
// simplify
|
||||
while (true)
|
||||
{
|
||||
PRInt32 r;
|
||||
while ((r = getLowestSpillCostRegister(low)) != -1)
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(r);
|
||||
|
||||
/* update low and high */
|
||||
FastBitSet inter(interferenceMatrix.getRow(r), nRegisters);
|
||||
for (j = inter.firstOne(); j != -1; j = inter.nextOne(j))
|
||||
{
|
||||
VirtualRegister& neighbor = vRegManager.getVirtualRegister(j);
|
||||
// if the new interference degree of one of his neighbor becomes
|
||||
// NUMBER_OF_REGISTERS - 1 then it is added to the set 'low'.
|
||||
|
||||
PRUint32 maxInterference = 0;
|
||||
switch (neighbor.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
maxInterference = NUMBER_OF_GREGISTERS;
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
maxInterference = NUMBER_OF_FPREGISTERS;
|
||||
break;
|
||||
default:
|
||||
PR_ASSERT(false);
|
||||
}
|
||||
if ((vRegManager.getVirtualRegister(j).colorInfo.interferenceDegree-- == maxInterference))
|
||||
{
|
||||
high.clear(j);
|
||||
low.set(j);
|
||||
}
|
||||
vReg.colorInfo.interferenceDegree--;
|
||||
interferenceMatrix.clear(r, j);
|
||||
interferenceMatrix.clear(j, r);
|
||||
}
|
||||
low.clear(r);
|
||||
|
||||
// Push this register.
|
||||
*stackPtr++ = r;
|
||||
}
|
||||
if ((r = getLowestSpillCostRegister(high)) != -1)
|
||||
{
|
||||
high.clear(r);
|
||||
low.set(r);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return stackPtr;
|
||||
}
|
||||
|
||||
bool Coloring::
|
||||
select(FastBitMatrix& interferenceMatrix, PRUint32* stackBase, PRUint32* stackPtr)
|
||||
{
|
||||
PRUint32 nRegisters = vRegManager.count();
|
||||
FastBitSet usedRegisters(NUMBER_OF_REGISTERS + 1); // usedRegisters if used for both GR & FPR.
|
||||
FastBitSet preColoredRegisters(NUMBER_OF_REGISTERS + 1);
|
||||
FastBitSet usedStack(nRegisters + 1);
|
||||
bool success = true;
|
||||
Int32 lastUsedSSR = -1;
|
||||
|
||||
// select
|
||||
while (stackPtr != stackBase)
|
||||
{
|
||||
// Pop one register.
|
||||
PRUint32 r = *--stackPtr;
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(r);
|
||||
|
||||
FastBitSet neighbors(interferenceMatrix.getRow(r), nRegisters);
|
||||
|
||||
if (vReg.getClass() == vrcStackSlot)
|
||||
// Stack slots coloring.
|
||||
{
|
||||
usedStack.clear();
|
||||
|
||||
for (PRInt32 i = neighbors.firstOne(); i != -1; i = neighbors.nextOne(i))
|
||||
usedStack.set(vRegManager.getVirtualRegister(i).getColor());
|
||||
|
||||
Int32 color = usedStack.firstZero();
|
||||
vReg.colorRegister(color);
|
||||
if (color > lastUsedSSR)
|
||||
lastUsedSSR = color;
|
||||
}
|
||||
else
|
||||
// Integer & Floating point register coloring.
|
||||
{
|
||||
usedRegisters.clear();
|
||||
preColoredRegisters.clear();
|
||||
|
||||
for (PRInt32 i = neighbors.firstOne(); i != -1; i = neighbors.nextOne(i))
|
||||
{
|
||||
VirtualRegister& nvReg = vRegManager.getVirtualRegister(i);
|
||||
usedRegisters.set(nvReg.getColor());
|
||||
if (nvReg.isPreColored())
|
||||
preColoredRegisters.set(nvReg.getPreColor());
|
||||
}
|
||||
if (vReg.hasSpecialInterference)
|
||||
usedRegisters |= vReg.specialInterference;
|
||||
|
||||
PRInt8 c = -1;
|
||||
PRInt8 maxColor = 0;
|
||||
PRInt8 firstColor = 0;
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
firstColor = FIRST_GREGISTER;
|
||||
maxColor = LAST_GREGISTER;
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
firstColor = FIRST_FPREGISTER;
|
||||
maxColor = LAST_FPREGISTER;
|
||||
break;
|
||||
default:
|
||||
PR_ASSERT(false);
|
||||
}
|
||||
|
||||
if (vReg.isPreColored())
|
||||
{
|
||||
c = vReg.getPreColor();
|
||||
if (usedRegisters.test(c))
|
||||
c = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (c = usedRegisters.nextZero(firstColor - 1); (c >= 0) && (c <= maxColor) && (preColoredRegisters.test(c));
|
||||
c = usedRegisters.nextZero(c)) {}
|
||||
}
|
||||
|
||||
if ((c >= 0) && (c <= maxColor))
|
||||
{
|
||||
vReg.colorRegister(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
VirtualRegister& stackRegister = vRegManager.newVirtualRegister(vrcStackSlot);
|
||||
vReg.equivalentRegister[vrcStackSlot] = &stackRegister;
|
||||
vReg.spillInfo.willSpill = true;
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (success)
|
||||
{
|
||||
for (VirtualRegisterManager::iterator i = vRegManager.begin(); !vRegManager.done(i); i = vRegManager.advance(i))
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(i);
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
if (vReg.getColor() > LAST_GREGISTER)
|
||||
PR_ASSERT(false);
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
#if NUMBER_OF_FPREGISTERS != 0
|
||||
if (vReg.getColor() > LAST_FPREGISTER)
|
||||
PR_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
vRegManager.nUsedStackSlots = lastUsedSSR + 1;
|
||||
return success;
|
||||
}
|
||||
#endif // NEW_LAURENTM_CODE
|
||||
284
mozilla/ef/Compiler/RegisterAllocator/Coloring.h
Normal file
284
mozilla/ef/Compiler/RegisterAllocator/Coloring.h
Normal file
@@ -0,0 +1,284 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "InterferenceGraph.h"
|
||||
#include "SparseSet.h"
|
||||
#include "Spilling.h"
|
||||
#include "Splits.h"
|
||||
|
||||
UT_EXTERN_LOG_MODULE(RegAlloc);
|
||||
|
||||
template <class RegisterPressure>
|
||||
class Coloring
|
||||
{
|
||||
private:
|
||||
static RegisterName* simplify(RegisterAllocator& registerAllocator, RegisterName* coloringStack);
|
||||
static bool select(RegisterAllocator& registerAllocator, RegisterName* coloringStack, RegisterName* coloringStackPtr);
|
||||
|
||||
public:
|
||||
static bool color(RegisterAllocator& registerAllocator);
|
||||
static void finalColoring(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Coloring<RegisterPressure>::finalColoring(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
RegisterName* color = registerAllocator.color;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
usePtr->setRegisterName(color[name2range[usePtr->getRegisterName()]]);
|
||||
#ifdef DEBUG
|
||||
RegisterID rid = usePtr->getRegisterID();
|
||||
setColoredRegister(rid);
|
||||
usePtr->setRegisterID(rid);
|
||||
#endif // DEBUG
|
||||
}
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
definePtr->setRegisterName(color[name2range[definePtr->getRegisterName()]]);
|
||||
#ifdef DEBUG
|
||||
RegisterID rid = definePtr->getRegisterID();
|
||||
setColoredRegister(rid);
|
||||
definePtr->setRegisterID(rid);
|
||||
#endif // DEBUG
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool Coloring<RegisterPressure>::select(RegisterAllocator& registerAllocator, RegisterName* coloringStack, RegisterName* coloringStackPtr)
|
||||
{
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* color = new RegisterName[rangeCount];
|
||||
registerAllocator.color = color;
|
||||
|
||||
for (Uint32 r = 1; r < rangeCount; r++)
|
||||
color[r] = RegisterName(6); // FIX;
|
||||
|
||||
// Color the preColored registers.
|
||||
//
|
||||
VirtualRegisterManager& vrManager = registerAllocator.vrManager;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
PreColoredRegister* machineEnd = vrManager.getMachineRegistersEnd();
|
||||
for (PreColoredRegister* machinePtr = vrManager.getMachineRegistersBegin(); machinePtr < machineEnd; machinePtr++)
|
||||
if (machinePtr->id != invalidID) {
|
||||
color[name2range[getName(machinePtr->id)]] = machinePtr->color;
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\twill preColor range %d as %d\n", name2range[getName(machinePtr->id)], machinePtr->color));
|
||||
}
|
||||
|
||||
SpillCost* cost = registerAllocator.spillCost;
|
||||
Pool& pool = registerAllocator.pool;
|
||||
SparseSet& spill = *new(pool) SparseSet(pool, rangeCount);
|
||||
registerAllocator.willSpill = &spill;
|
||||
SparseSet neighborColors(pool, 6); // FIX
|
||||
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
|
||||
|
||||
bool coloringFailed = false;
|
||||
while (coloringStackPtr > coloringStack) {
|
||||
RegisterName range = *--coloringStackPtr;
|
||||
|
||||
if (!cost[range].infinite && cost[range].cost < 0) {
|
||||
coloringFailed = true;
|
||||
spill.set(range);
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tfailed to color %d, will spill.\n", range));
|
||||
} else {
|
||||
neighborColors.clear();
|
||||
|
||||
for (InterferenceVector* vector = iGraph.getInterferenceVector(range); vector != NULL; vector = vector->next)
|
||||
for (Int32 i = vector->count - 1; i >= 0; --i) {
|
||||
RegisterName neighborColor = color[vector->neighbors[i]];
|
||||
if (neighborColor < 6) // FIX
|
||||
neighborColors.set(neighborColor);
|
||||
}
|
||||
|
||||
if (neighborColors.getSize() == 6) { // FIX
|
||||
coloringFailed = true;
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tfailed to color %d, ", range));
|
||||
|
||||
if (!Splits<RegisterPressure>::findSplit(registerAllocator, color, range)) {
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("will spill.\n"));
|
||||
spill.set(range);
|
||||
} else
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("will split.\n"));
|
||||
} else {
|
||||
for (Uint32 i = 0; i < 6; i++) // FIX
|
||||
if (!neighborColors.test(i)) {
|
||||
fprintf(stdout, "\twill color %d as %d\n", range, i);
|
||||
color[range] = RegisterName(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
if (coloringFailed) {
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring failed:\n"));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\twill spill: "));
|
||||
spill.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
} else {
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring succeeded:\n"));
|
||||
for (Uint32 i = 1; i < rangeCount; i++)
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\trange %d colored as %d\n", i, color[i]));
|
||||
}
|
||||
#endif
|
||||
|
||||
return !coloringFailed;
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
RegisterName* Coloring<RegisterPressure>::simplify(RegisterAllocator& registerAllocator, RegisterName* coloringStack)
|
||||
{
|
||||
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
|
||||
SpillCost* spillCost = registerAllocator.spillCost;
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
|
||||
Uint32* degree = new Uint32[rangeCount];
|
||||
for (RegisterName i = RegisterName(1); i < rangeCount; i = RegisterName(i + 1)) {
|
||||
InterferenceVector* vector = iGraph.getInterferenceVector(i);
|
||||
degree[i] = (vector != NULL) ? vector->count : 0;
|
||||
}
|
||||
|
||||
Pool& pool = registerAllocator.pool;
|
||||
SparseSet low(pool, rangeCount);
|
||||
SparseSet high(pool, rangeCount);
|
||||
SparseSet highInfinite(pool, rangeCount);
|
||||
SparseSet preColored(pool, rangeCount);
|
||||
|
||||
// Get the precolored registers.
|
||||
//
|
||||
VirtualRegisterManager& vrManager = registerAllocator.vrManager;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
PreColoredRegister* machineEnd = vrManager.getMachineRegistersEnd();
|
||||
for (PreColoredRegister* machinePtr = vrManager.getMachineRegistersBegin(); machinePtr < machineEnd; machinePtr++)
|
||||
if (machinePtr->id != invalidID)
|
||||
preColored.set(name2range[getName(machinePtr->id)]);
|
||||
|
||||
// Insert the live ranges in the sets.
|
||||
//
|
||||
for (Uint32 range = 1; range < rangeCount; range++)
|
||||
if (!preColored.test(range))
|
||||
if (degree[range] < 6) // FIX
|
||||
low.set(range);
|
||||
else if (!spillCost[range].infinite)
|
||||
high.set(range);
|
||||
else
|
||||
highInfinite.set(range);
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring sets:\n\tlow = "));
|
||||
low.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\thigh = "));
|
||||
high.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\thighInfinite = "));
|
||||
highInfinite.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tpreColored = "));
|
||||
preColored.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
RegisterName* coloringStackPtr = coloringStack;
|
||||
|
||||
while (low.getSize() != 0 || high.getSize() != 0) {
|
||||
while (low.getSize() != 0) {
|
||||
RegisterName range = RegisterName(low.getOne());
|
||||
low.clear(range);
|
||||
*coloringStackPtr++ = range;
|
||||
|
||||
for (InterferenceVector* vector = iGraph.getInterferenceVector(range); vector != NULL; vector = vector->next)
|
||||
for (Int32 i = (vector->count - 1); i >= 0; --i) {
|
||||
RegisterName neighbor = vector->neighbors[i];
|
||||
degree[neighbor]--;
|
||||
|
||||
if (degree[neighbor] < 6) // FIX
|
||||
if (high.test(neighbor)) {
|
||||
high.clear(neighbor);
|
||||
low.set(neighbor);
|
||||
} else if (highInfinite.test(neighbor)) {
|
||||
highInfinite.clear(neighbor);
|
||||
low.set(neighbor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (high.getSize() != 0) {
|
||||
RegisterName best = RegisterName(high.getOne());
|
||||
double bestCost = spillCost[best].cost;
|
||||
double bestDegree = degree[best];
|
||||
|
||||
// Choose the next best candidate.
|
||||
//
|
||||
for (SparseSet::iterator i = high.begin(); !high.done(i); i = high.advance(i)) {
|
||||
RegisterName range = RegisterName(high.get(i));
|
||||
double thisCost = spillCost[range].cost;
|
||||
double thisDegree = degree[range];
|
||||
|
||||
if (thisCost * bestDegree < bestCost * thisDegree) {
|
||||
best = range;
|
||||
bestCost = thisCost;
|
||||
bestDegree = thisDegree;
|
||||
}
|
||||
}
|
||||
|
||||
high.clear(best);
|
||||
low.set(best);
|
||||
}
|
||||
}
|
||||
assert(highInfinite.getSize() == 0);
|
||||
|
||||
delete degree;
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring stack:\n\t"));
|
||||
for (RegisterName* sp = coloringStack; sp < coloringStackPtr; ++sp)
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("%d ", *sp));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\n"));
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
return coloringStackPtr;
|
||||
}
|
||||
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool Coloring<RegisterPressure>::color(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
RegisterName* coloringStack = new RegisterName[registerAllocator.rangeCount];
|
||||
return select(registerAllocator, coloringStack, simplify(registerAllocator, coloringStack));
|
||||
}
|
||||
212
mozilla/ef/Compiler/RegisterAllocator/DominatorGraph.cpp
Normal file
212
mozilla/ef/Compiler/RegisterAllocator/DominatorGraph.cpp
Normal file
@@ -0,0 +1,212 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include <string.h>
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
|
||||
#include "DominatorGraph.h"
|
||||
|
||||
DominatorGraph::DominatorGraph(ControlGraph& controlGraph) : controlGraph(controlGraph)
|
||||
{
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
GtoV = new Uint32[nNodes + 1];
|
||||
VtoG = new Uint32[nNodes + 1];
|
||||
|
||||
Uint32 v = 1;
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
VtoG[v] = n;
|
||||
GtoV[n] = v++;
|
||||
}
|
||||
|
||||
// Initialize all the 1-based arrays.
|
||||
//
|
||||
parent = new Uint32[v];
|
||||
semi = new Uint32[v];
|
||||
vertex = new Uint32[v];
|
||||
label = new Uint32[v];
|
||||
size = new Uint32[v];
|
||||
ancestor = new Uint32[v];
|
||||
child = new Uint32[v];
|
||||
dom = new Uint32[v];
|
||||
bucket = new DGLinkedList*[v];
|
||||
|
||||
memset(semi, '\0', v * sizeof(Uint32));
|
||||
memset(bucket, '\0', v * sizeof(DGLinkedList*));
|
||||
|
||||
vCount = v;
|
||||
|
||||
build();
|
||||
|
||||
delete parent;
|
||||
delete semi;
|
||||
delete vertex;
|
||||
delete label;
|
||||
delete size;
|
||||
delete ancestor;
|
||||
delete child;
|
||||
delete dom;
|
||||
delete bucket;
|
||||
}
|
||||
|
||||
Uint32 DominatorGraph::DFS(Uint32 vx, Uint32 n)
|
||||
{
|
||||
semi[vx] = ++n;
|
||||
vertex[n] = label[vx] = vx;
|
||||
ancestor[vx] = child[vx] = 0;
|
||||
size[vx] = 1;
|
||||
|
||||
|
||||
ControlNode& node = *controlGraph.dfsList[VtoG[vx]];
|
||||
ControlEdge* successorEnd = node.getSuccessorsEnd();
|
||||
for (ControlEdge* successorPtr = node.getSuccessorsBegin(); successorPtr < successorEnd; successorPtr++) {
|
||||
Uint32 w = GtoV[successorPtr->getTarget().dfsNum];
|
||||
if (semi[w] == 0) {
|
||||
parent[w] = vx;
|
||||
n = DFS(w, n);
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
void DominatorGraph::LINK(Uint32 vx, Uint32 w)
|
||||
{
|
||||
Uint32 s = w;
|
||||
|
||||
while (semi[label[w]] < semi[label[child[s]]]) {
|
||||
if (size[s] + size[child[child[s]]] >= (size[child[s]] << 1)) {
|
||||
ancestor[child[s]] = s;
|
||||
child[s] = child[child[s]];
|
||||
} else {
|
||||
size[child[s]] = size[s];
|
||||
s = ancestor[s] = child[s];
|
||||
}
|
||||
}
|
||||
label[s] = label[w];
|
||||
size[vx] += size[w];
|
||||
if(size[vx] < (size[w] << 1)) {
|
||||
Uint32 t = s;
|
||||
s = child[vx];
|
||||
child[vx] = t;
|
||||
}
|
||||
while( s != 0 ) {
|
||||
ancestor[s] = vx;
|
||||
s = child[s];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DominatorGraph::COMPRESS(Uint32 vx)
|
||||
{
|
||||
if(ancestor[ancestor[vx]] != 0) {
|
||||
COMPRESS(ancestor[vx]);
|
||||
if(semi[label[ancestor[vx]]] < semi[label[vx]])
|
||||
label[vx] = label[ancestor[vx]];
|
||||
ancestor[vx] = ancestor[ancestor[vx]];
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 DominatorGraph::EVAL(Uint32 vx)
|
||||
{
|
||||
if(ancestor[vx] == 0)
|
||||
return label[vx];
|
||||
COMPRESS(vx);
|
||||
return (semi[label[ancestor[vx]]] >= semi[label[vx]]) ? label[vx] : label[ancestor[vx]];
|
||||
}
|
||||
|
||||
void DominatorGraph::build()
|
||||
{
|
||||
Uint32 n = DFS(GtoV[0], 0);
|
||||
size[0] = label[0] = semi[0];
|
||||
|
||||
for (Uint32 i = n; i >= 2; i--) {
|
||||
Uint32 w = vertex[i];
|
||||
|
||||
ControlNode& node = *controlGraph.dfsList[VtoG[w]];
|
||||
const DoublyLinkedList<ControlEdge>& predecessors = node.getPredecessors();
|
||||
for (DoublyLinkedList<ControlEdge>::iterator p = predecessors.begin(); !predecessors.done(p); p = predecessors.advance(p)) {
|
||||
Uint32 vx = GtoV[predecessors.get(p).getSource().dfsNum];
|
||||
Uint32 u = EVAL(vx);
|
||||
|
||||
if(semi[u] < semi[w])
|
||||
semi[w] = semi[u];
|
||||
}
|
||||
|
||||
DGLinkedList* elem = new DGLinkedList();
|
||||
elem->next = bucket[vertex[semi[w]]];
|
||||
elem->index = w;
|
||||
bucket[vertex[semi[w]]] = elem;
|
||||
|
||||
LINK(parent[w], w);
|
||||
|
||||
elem = bucket[parent[w]];
|
||||
while(elem != NULL) {
|
||||
Uint32 vx = elem->index;
|
||||
Uint32 u = EVAL(vx);
|
||||
dom[vx] = (semi[u] < semi[vx]) ? u : parent[w];
|
||||
elem = elem->next;
|
||||
}
|
||||
}
|
||||
|
||||
memset(size, '\0', n * sizeof(Uint32));
|
||||
Pool& pool = controlGraph.pool;
|
||||
nodes = new(pool) DGNode[n];
|
||||
|
||||
for(Uint32 j = 2; j <= n; j++) {
|
||||
Uint32 w = vertex[j];
|
||||
Uint32 d = dom[w];
|
||||
if(d != vertex[semi[w]]) {
|
||||
d = dom[d];
|
||||
dom[w] = d;
|
||||
}
|
||||
size[d]++;
|
||||
}
|
||||
dom[GtoV[0]] = 0;
|
||||
|
||||
for (Uint32 k = 1; k <= n; k++) {
|
||||
DGNode& node = nodes[VtoG[k]];
|
||||
Uint32 count = size[k];
|
||||
node.successorsEnd = node.successorsBegin = (count) ? new(pool) Uint32[count] : (Uint32*) 0;
|
||||
}
|
||||
|
||||
for (Uint32 l = 2; l <= n; l++)
|
||||
*(nodes[VtoG[dom[l]]].successorsEnd)++ = VtoG[l];
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
void DominatorGraph::printPretty(LogModuleObject log)
|
||||
{
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Dominator Graph:\n"));
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
for (Uint32 i = 0; i < nNodes; i++) {
|
||||
DGNode& node = nodes[i];
|
||||
if (node.successorsBegin != node.successorsEnd) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\tN%d dominates ", i));
|
||||
for (Uint32* successorsPtr = node.successorsBegin; successorsPtr < node.successorsEnd; successorsPtr++)
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("N%d ", *successorsPtr));
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
|
||||
|
||||
80
mozilla/ef/Compiler/RegisterAllocator/DominatorGraph.h
Normal file
80
mozilla/ef/Compiler/RegisterAllocator/DominatorGraph.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _DOMINATOR_GRAPH_H_
|
||||
#define _DOMINATOR_GRAPH_H_
|
||||
|
||||
#include "LogModule.h"
|
||||
|
||||
class ControlGraph;
|
||||
|
||||
struct DGNode
|
||||
{
|
||||
Uint32* successorsBegin;
|
||||
Uint32* successorsEnd;
|
||||
};
|
||||
|
||||
struct DGLinkedList
|
||||
{
|
||||
DGLinkedList* next;
|
||||
Uint32 index;
|
||||
};
|
||||
|
||||
class DominatorGraph
|
||||
{
|
||||
private:
|
||||
|
||||
ControlGraph& controlGraph;
|
||||
|
||||
Uint32 vCount;
|
||||
|
||||
Uint32* VtoG;
|
||||
Uint32* GtoV;
|
||||
Uint32* parent;
|
||||
Uint32* semi;
|
||||
Uint32* vertex;
|
||||
Uint32* label;
|
||||
Uint32* size;
|
||||
Uint32* ancestor;
|
||||
Uint32* child;
|
||||
Uint32* dom;
|
||||
DGLinkedList** bucket;
|
||||
DGNode* nodes;
|
||||
|
||||
private:
|
||||
|
||||
void build();
|
||||
|
||||
Uint32 DFS(Uint32 vx, Uint32 n);
|
||||
void LINK(Uint32 vx, Uint32 w);
|
||||
void COMPRESS(Uint32 vx);
|
||||
Uint32 EVAL(Uint32 vx);
|
||||
|
||||
public:
|
||||
|
||||
DominatorGraph(ControlGraph& controlGraph);
|
||||
|
||||
Uint32* getSuccessorsBegin(Uint32 n) const {return nodes[n].successorsBegin;}
|
||||
Uint32* getSuccessorsEnd(Uint32 n) const {return nodes[n].successorsEnd;}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
#endif // _DOMINATOR_GRAPH_H_
|
||||
20
mozilla/ef/Compiler/RegisterAllocator/HashSet.cpp
Normal file
20
mozilla/ef/Compiler/RegisterAllocator/HashSet.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "HashSet.h"
|
||||
97
mozilla/ef/Compiler/RegisterAllocator/HashSet.h
Normal file
97
mozilla/ef/Compiler/RegisterAllocator/HashSet.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _HASH_SET_H_
|
||||
#define _HASH_SET_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include <string.h>
|
||||
|
||||
struct HashSetElement
|
||||
{
|
||||
Uint32 index;
|
||||
HashSetElement* next;
|
||||
};
|
||||
|
||||
class HashSet
|
||||
{
|
||||
private:
|
||||
|
||||
static const hashSize = 64;
|
||||
|
||||
// Return the hash code for the given element index.
|
||||
static Uint32 getHashCode(Uint32 index) {return index & (hashSize - 1);} // Could be better !
|
||||
|
||||
private:
|
||||
|
||||
Pool& allocationPool;
|
||||
HashSetElement** bucket;
|
||||
HashSetElement* free;
|
||||
|
||||
private:
|
||||
|
||||
// No copy constructor.
|
||||
HashSet(const HashSet&);
|
||||
// No copy operator.
|
||||
void operator = (const HashSet&);
|
||||
|
||||
public:
|
||||
|
||||
// Create a new HashSet.
|
||||
inline HashSet(Pool& pool, Uint32 universeSize);
|
||||
|
||||
// Clear the hashset.
|
||||
void clear();
|
||||
// Clear the element for the given index.
|
||||
void clear(Uint32 index);
|
||||
// Set the element for the given index.
|
||||
void set(Uint32 index);
|
||||
// Return true if the element at index is a member.
|
||||
bool test(Uint32 index) const;
|
||||
// Union with the given hashset.
|
||||
inline void or(const HashSet& set);
|
||||
// Intersection with the given hashset.
|
||||
inline void and(const HashSet& set);
|
||||
// Difference with the given hashset.
|
||||
inline void difference(const HashSet& set);
|
||||
|
||||
// Logical operators.
|
||||
HashSet& operator |= (const HashSet& set) {or(set); return *this;}
|
||||
HashSet& operator &= (const HashSet& set) {and(set); return *this;}
|
||||
HashSet& operator -= (const HashSet& set) {difference(set); return *this;}
|
||||
|
||||
// Iterator to conform with the set API.
|
||||
typedef HashSetElement* iterator;
|
||||
// Return the iterator for the first element of this set.
|
||||
iterator begin() const;
|
||||
// Return the next iterator.
|
||||
iterator advance(iterator pos) const;
|
||||
// Return true if the iterator is at the end of the set.
|
||||
bool done(iterator pos) const {return pos == NULL;}
|
||||
};
|
||||
|
||||
|
||||
inline HashSet::HashSet(Pool& pool, Uint32 /*universeSize*/)
|
||||
: allocationPool(pool), free(NULL)
|
||||
{
|
||||
bucket = new(pool) HashSetElement*[hashSize];
|
||||
memset(bucket, '\0', sizeof(HashSetElement*));
|
||||
}
|
||||
|
||||
#endif // _HASH_SET_H_
|
||||
213
mozilla/ef/Compiler/RegisterAllocator/IndexedPool.h
Normal file
213
mozilla/ef/Compiler/RegisterAllocator/IndexedPool.h
Normal file
@@ -0,0 +1,213 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _INDEXED_POOL_H_
|
||||
#define _INDEXED_POOL_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// IndexedPool<IndexedObjectSubclass> is an indexed pool of objects. The
|
||||
// template parameter 'IndexedObjectSubclass' must be a subclass of the struct
|
||||
// IndexedObject.
|
||||
//
|
||||
// When the indexed pool is ask to allocate and initialize a new object (using
|
||||
// the operator new(anIndexedPool) it will zero the memory used to store the
|
||||
// object and initialize the field 'index' of this object to its position in
|
||||
// the pool.
|
||||
//
|
||||
// An object allocated by the indexed pool can be freed by calling the method
|
||||
// IndexedPool::release(IndexedElement& objectIndex).
|
||||
//
|
||||
// example:
|
||||
//
|
||||
// IndexedPool<IndexedElement> elementPool;
|
||||
//
|
||||
// IndexedElement& element1 = *new(elementPool) IndexedElement();
|
||||
// IndexedElement& element2 = *new(elementPool) IndexedElement();
|
||||
//
|
||||
// indexedPool.release(element1);
|
||||
// IndexedElement& element3 = *new(elementPool) IndexedElement();
|
||||
//
|
||||
// At this point element1 is no longer a valid object, element2 is at
|
||||
// index 2 and element3 is at index 1.
|
||||
//
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// IndexedObject -
|
||||
//
|
||||
|
||||
template<class Object>
|
||||
struct IndexedObject
|
||||
{
|
||||
Uint32 index; // Index in the pool.
|
||||
Object* next; // Used to link IndexedObject together.
|
||||
|
||||
Uint32 getIndex() {return index;}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// IndexedPool<IndexedObject> -
|
||||
//
|
||||
|
||||
template <class IndexedObject>
|
||||
class IndexedPool
|
||||
{
|
||||
private:
|
||||
|
||||
static const blockSize = 4; // Size of one block.
|
||||
|
||||
Uint32 nBlocks; // Number of blocks in the pool.
|
||||
IndexedObject** block; // Array of block pointers.
|
||||
IndexedObject* freeObjects; // Chained list of free IndexedObjects.
|
||||
Uint32 nextIndex; // Index of the next free object in the last block.
|
||||
|
||||
private:
|
||||
|
||||
void allocateAnotherBlock();
|
||||
IndexedObject& newObject();
|
||||
|
||||
public:
|
||||
|
||||
IndexedPool() : nBlocks(0), block(NULL), freeObjects(NULL), nextIndex(1) {}
|
||||
~IndexedPool();
|
||||
|
||||
IndexedObject& get(Uint32 index) const;
|
||||
void release(IndexedObject& object);
|
||||
|
||||
void setSize(Uint32 size) {assert(size < nextIndex); nextIndex = size;}
|
||||
|
||||
// Return the universe size.
|
||||
Uint32 getSize() {return nextIndex;}
|
||||
|
||||
friend void* operator new(size_t, IndexedPool<IndexedObject>& pool); // Needs to call newObject().
|
||||
};
|
||||
|
||||
// Free all the memory allocated for this object.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
IndexedPool<IndexedObject>::~IndexedPool()
|
||||
{
|
||||
for (Uint32 n = 0; n < nBlocks; n++)
|
||||
free(&((IndexedObject **) &block[n][n*blockSize])[-(n + 1)]);
|
||||
}
|
||||
|
||||
// Release the given. This object will be iserted in the chained
|
||||
// list of free IndexedObjects. To minimize the fragmentation the chained list
|
||||
// is ordered by ascending indexes.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
void IndexedPool<IndexedObject>::release(IndexedObject& object)
|
||||
{
|
||||
Uint32 index = object.index;
|
||||
IndexedObject* list = freeObjects;
|
||||
|
||||
assert(&object == &get(index)); // Make sure that object is owned by this pool.
|
||||
|
||||
if (list == NULL) { // The list is empty.
|
||||
freeObjects = &object;
|
||||
object.next = NULL;
|
||||
} else { // The list contains at least 1 element.
|
||||
if (index < list->index) { // insert as first element.
|
||||
freeObjects = &object;
|
||||
object.next = list;
|
||||
} else { // Find this object's place.
|
||||
while ((list->next) != NULL && (list->next->index < index))
|
||||
list = list->next;
|
||||
|
||||
object.next = list->next;
|
||||
list->next = &object;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Sanity check to be sure that the list is correctly ordered.
|
||||
for (IndexedObject* obj = freeObjects; obj != NULL; obj = obj->next)
|
||||
if (obj->next != NULL)
|
||||
assert(obj->index < obj->next->index);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Create a new block of IndexedObjects. We will allocate the memory to
|
||||
// store IndexedPool::blockSize IndexedObject and the new Array of block
|
||||
// pointers.
|
||||
// The newly created IndexedObjects will not be initialized.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
void IndexedPool<IndexedObject>::allocateAnotherBlock()
|
||||
{
|
||||
void* memory = (void *) malloc((nBlocks + 1) * sizeof(Uint32) + blockSize * sizeof(IndexedObject));
|
||||
|
||||
memcpy(memory, block, nBlocks * sizeof(Uint32));
|
||||
|
||||
block = (IndexedObject **) memory;
|
||||
IndexedObject* objects = (IndexedObject *) &block[nBlocks + 1];
|
||||
|
||||
block[nBlocks] = &objects[-(nBlocks * blockSize)];
|
||||
nBlocks++;
|
||||
}
|
||||
|
||||
// Return the IndexedObject at the position 'index' in the pool.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
IndexedObject& IndexedPool<IndexedObject>::get(Uint32 index) const
|
||||
{
|
||||
Uint32 blockIndex = index / blockSize;
|
||||
assert(blockIndex < nBlocks);
|
||||
|
||||
return block[blockIndex][index];
|
||||
}
|
||||
|
||||
// Return the reference of an unused object in the pool.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
IndexedObject& IndexedPool<IndexedObject>::newObject()
|
||||
{
|
||||
if (freeObjects != NULL) {
|
||||
IndexedObject& newObject = *freeObjects;
|
||||
freeObjects = newObject.next;
|
||||
return newObject;
|
||||
}
|
||||
|
||||
Uint32 nextIndex = this->nextIndex++;
|
||||
Uint32 blockIndex = nextIndex / blockSize;
|
||||
|
||||
while (blockIndex >= nBlocks)
|
||||
allocateAnotherBlock();
|
||||
|
||||
IndexedObject& newObject = block[blockIndex][nextIndex];
|
||||
newObject.index = nextIndex;
|
||||
|
||||
return newObject;
|
||||
}
|
||||
|
||||
// Return the address of the next unsused object in the given
|
||||
// indexed pool. The field index of the newly allocated object
|
||||
// will be initialized to the corresponding index of this object
|
||||
// in the pool.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
void* operator new(size_t size, IndexedPool<IndexedObject>& pool)
|
||||
{
|
||||
assert(size == sizeof(IndexedObject));
|
||||
return (void *) &pool.newObject();
|
||||
}
|
||||
|
||||
#endif // _INDEXED_POOL_H_
|
||||
258
mozilla/ef/Compiler/RegisterAllocator/InterferenceGraph.h
Normal file
258
mozilla/ef/Compiler/RegisterAllocator/InterferenceGraph.h
Normal file
@@ -0,0 +1,258 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _INTERFERENCE_GRAPH_H_
|
||||
#define _INTERFERENCE_GRAPH_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "Primitives.h"
|
||||
#include "Instruction.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "RegisterPressure.h"
|
||||
#include "SparseSet.h"
|
||||
#include <string.h>
|
||||
|
||||
struct InterferenceVector
|
||||
{
|
||||
Uint32 count;
|
||||
InterferenceVector* next;
|
||||
RegisterName* neighbors;
|
||||
|
||||
InterferenceVector() : count(0), next(NULL) {}
|
||||
};
|
||||
|
||||
class RegisterAllocator;
|
||||
|
||||
template <class RegisterPressure>
|
||||
class InterferenceGraph
|
||||
{
|
||||
private:
|
||||
|
||||
RegisterAllocator& registerAllocator;
|
||||
|
||||
RegisterPressure::Set* interferences;
|
||||
InterferenceVector** vector;
|
||||
Uint32* offset;
|
||||
Uint32 rangeCount;
|
||||
|
||||
private:
|
||||
|
||||
// No copy constructor.
|
||||
InterferenceGraph(const InterferenceGraph&);
|
||||
// No copy operator.
|
||||
void operator = (const InterferenceGraph&);
|
||||
|
||||
// Check if reg is a member of the universe.
|
||||
void checkMember(RegisterName name) {assert(name < rangeCount);}
|
||||
// Return the edge index for the interference between name1 and name2.
|
||||
Uint32 getEdgeIndex(RegisterName name1, RegisterName name2);
|
||||
|
||||
public:
|
||||
InterferenceGraph(RegisterAllocator& registerAllocator) : registerAllocator(registerAllocator) {}
|
||||
|
||||
// Calculate the interferences.
|
||||
void build();
|
||||
// Return true if reg1 and reg2 interfere.
|
||||
bool interfere(RegisterName name1, RegisterName name2);
|
||||
// Return the interference vector for the given register or NULL if there is none.
|
||||
InterferenceVector* getInterferenceVector(RegisterName name) {return vector[name];}
|
||||
// Set the interference between name1 and name2.
|
||||
void setInterference(RegisterName name1, RegisterName name2);
|
||||
// Set the interference vector for the given register.
|
||||
void setInterferenceVector(RegisterName name, InterferenceVector* v) {vector[name] = v;}
|
||||
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
// Print the interferences.
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void InterferenceGraph<RegisterPressure>::build()
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
this->rangeCount = rangeCount;
|
||||
|
||||
// Initialize the structures.
|
||||
//
|
||||
offset = new(pool) Uint32[rangeCount + 1];
|
||||
vector = new(pool) InterferenceVector*[rangeCount];
|
||||
memset(vector, '\0', sizeof(InterferenceVector*) * rangeCount);
|
||||
|
||||
Uint32 o = 0;
|
||||
offset[0] = 0;
|
||||
for (Uint32 i = 1; i <= rangeCount; ++i) {
|
||||
offset[i] = o;
|
||||
o += i;
|
||||
}
|
||||
|
||||
interferences = new(pool) RegisterPressure::Set(pool, (rangeCount * rangeCount) / 2);
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
LivenessInfo<RegisterPressure> liveness = Liveness<RegisterPressure>::analysis(controlGraph, rangeCount, name2range);
|
||||
registerAllocator.liveness = liveness;
|
||||
SparseSet currentLive(pool, rangeCount);
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
currentLive = liveness.liveOut[n];
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
// Handle the copy instruction to avoid unnecessary interference between the 2 registers.
|
||||
if ((instruction.getFlags() & ifCopy) != 0) {
|
||||
assert(useBegin != useEnd && useBegin[0].isRegister());
|
||||
currentLive.clear(name2range[useBegin[0].getRegisterName()]);
|
||||
}
|
||||
|
||||
// Create the interferences.
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName define = name2range[definePtr->getRegisterName()];
|
||||
|
||||
for (SparseSet::iterator e = currentLive.begin(); !currentLive.done(e); e = currentLive.advance(e)) {
|
||||
RegisterName live = RegisterName(currentLive.get(e));
|
||||
|
||||
if ((live != define) && !interfere(live, define) && registerAllocator.canInterfere(live, define)) {
|
||||
|
||||
if (vector[define] == NULL)
|
||||
vector[define] = new(pool) InterferenceVector();
|
||||
vector[define]->count++;
|
||||
|
||||
if (vector[live] == NULL)
|
||||
vector[live] = new(pool) InterferenceVector();
|
||||
vector[live]->count++;
|
||||
|
||||
setInterference(live, define);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now update the liveness.
|
||||
//
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentLive.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
currentLive.set(name2range[usePtr->getRegisterName()]);
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate the memory to store the interferences.
|
||||
//
|
||||
for (Uint32 e = 0; e < rangeCount; e++)
|
||||
if (vector[e] != NULL) {
|
||||
InterferenceVector& v = *vector[e];
|
||||
v.neighbors = new(pool) RegisterName[v.count];
|
||||
v.count = 0;
|
||||
}
|
||||
|
||||
// Initialize the edges.
|
||||
//
|
||||
if (RegisterPressure::Set::isOrdered()) {
|
||||
RegisterName name1 = RegisterName(0);
|
||||
|
||||
for (RegisterPressure::Set::iterator i = interferences->begin(); !interferences->done(i); i = interferences->advance(i)) {
|
||||
Uint32 interferenceIndex = interferences->get(i);
|
||||
|
||||
while(interferenceIndex >= offset[name1 + 1])
|
||||
name1 = RegisterName(name1 + 1);
|
||||
|
||||
assert((interferenceIndex >= offset[name1]) && (interferenceIndex < offset[name1 + 1]));
|
||||
|
||||
RegisterName name2 = RegisterName(interferenceIndex - offset[name1]);
|
||||
|
||||
assert(interfere(name1, name2));
|
||||
|
||||
InterferenceVector& vector1 = *vector[name1];
|
||||
vector1.neighbors[vector1.count++] = name2;
|
||||
|
||||
InterferenceVector& vector2 = *vector[name2];
|
||||
vector2.neighbors[vector2.count++] = name1;
|
||||
}
|
||||
} else {
|
||||
trespass("not Implemented"); // FIX: need one more pass to initialize the vectors.
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
Uint32 InterferenceGraph<RegisterPressure>::getEdgeIndex(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
checkMember(name1); checkMember(name2);
|
||||
assert(name1 != name2); // This is not possible.
|
||||
return (name1 < name2) ? offset[name2] + name1 : offset[name1] + name2;
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void InterferenceGraph<RegisterPressure>::setInterference(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
interferences->set(getEdgeIndex(name1, name2));
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool InterferenceGraph<RegisterPressure>::interfere(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
return interferences->test(getEdgeIndex(name1, name2));
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
template <class RegisterPressure>
|
||||
void InterferenceGraph<RegisterPressure>::printPretty(LogModuleObject log)
|
||||
{
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Interference Vectors:\n"));
|
||||
for (Uint32 i = 1; i < rangeCount; i++) {
|
||||
if (vector[i] != NULL) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\tvr%d: (", i));
|
||||
for (InterferenceVector* v = vector[i]; v != NULL; v = v->next)
|
||||
for (Uint32 j = 0; j < v->count; j++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%d", v->neighbors[j]));
|
||||
if (v->next != NULL || j != (v->count - 1))
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (","));
|
||||
}
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (")\n"));
|
||||
}
|
||||
}
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Interference Matrix:\n"));
|
||||
for (RegisterName name1 = RegisterName(1); name1 < rangeCount; name1 = RegisterName(name1 + 1)) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\t%d:\t", name1));
|
||||
for (RegisterName name2 = RegisterName(1); name2 < rangeCount; name2 = RegisterName(name2 + 1))
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%c", ((name1 != name2) && interfere(name1, name2)) ? '1' : '0'));
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
#endif // _INTERFERENCE_GRAPH_H_
|
||||
87
mozilla/ef/Compiler/RegisterAllocator/LiveRange.h
Normal file
87
mozilla/ef/Compiler/RegisterAllocator/LiveRange.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _LIVE_RANGE_H_
|
||||
#define _LIVE_RANGE_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Primitives.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct LiveRange
|
||||
{
|
||||
static void build(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void LiveRange<RegisterPressure>::build(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
// Intialize the lookup table.
|
||||
//
|
||||
Uint32 nameCount = registerAllocator.nameCount;
|
||||
RegisterName* nameTable = new(registerAllocator.pool) RegisterName[2*nameCount];
|
||||
RegisterName* rangeName = &nameTable[nameCount];
|
||||
|
||||
init(rangeName, nameCount);
|
||||
|
||||
// Walk the graph.
|
||||
//
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
SparseSet destination(registerAllocator.pool, nameCount);
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
|
||||
destination.clear();
|
||||
for (InstructionList::iterator i = phiNodes.begin(); !phiNodes.done(i); i = phiNodes.advance(i)) {
|
||||
Instruction& phiNode = phiNodes.get(i);
|
||||
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd() && phiNode.getInstructionDefineBegin()[0].isRegister());
|
||||
destination.set(findRoot(phiNode.getInstructionDefineBegin()[0].getRegisterName(), rangeName));
|
||||
}
|
||||
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& phiNode = phiNodes.get(p);
|
||||
|
||||
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd() && phiNode.getInstructionDefineBegin()[0].isRegister());
|
||||
RegisterName destinationName = phiNode.getInstructionDefineBegin()[0].getRegisterName();
|
||||
RegisterName destinationRoot = findRoot(destinationName, rangeName);
|
||||
|
||||
InstructionUse* useEnd = phiNode.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = phiNode.getInstructionUseBegin(); usePtr < useEnd; usePtr++) {
|
||||
assert(usePtr->isRegister());
|
||||
RegisterName sourceName = usePtr->getRegisterName();
|
||||
RegisterName sourceRoot = findRoot(sourceName, rangeName);
|
||||
|
||||
if (sourceRoot != destinationRoot && !destination.test(sourceRoot))
|
||||
rangeName[sourceRoot] = destinationRoot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerAllocator.rangeCount = compress(registerAllocator.name2range, rangeName, nameCount, nameCount);
|
||||
}
|
||||
|
||||
#endif // _LIVE_RANGE_H_
|
||||
163
mozilla/ef/Compiler/RegisterAllocator/LiveRangeGraph.h
Normal file
163
mozilla/ef/Compiler/RegisterAllocator/LiveRangeGraph.h
Normal file
@@ -0,0 +1,163 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _LIVE_RANGE_GRAPH_
|
||||
#define _LIVE_RANGE_GRAPH_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterTypes.h"
|
||||
|
||||
class RegisterAllocator;
|
||||
|
||||
template <class RegisterPressure>
|
||||
class LiveRangeGraph
|
||||
{
|
||||
private:
|
||||
|
||||
RegisterAllocator& registerAllocator;
|
||||
|
||||
RegisterPressure::Set* edges;
|
||||
Uint32 rangeCount;
|
||||
|
||||
public:
|
||||
//
|
||||
//
|
||||
LiveRangeGraph(RegisterAllocator& registerAllocator) : registerAllocator(registerAllocator) {}
|
||||
|
||||
//
|
||||
//
|
||||
void build();
|
||||
|
||||
//
|
||||
//
|
||||
void addEdge(RegisterName name1, RegisterName name2);
|
||||
|
||||
//
|
||||
//
|
||||
bool haveEdge(RegisterName name1, RegisterName name2);
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
//
|
||||
//
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void LiveRangeGraph<RegisterPressure>::build()
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
this->rangeCount = rangeCount;
|
||||
|
||||
edges = new(pool) RegisterPressure::Set(pool, rangeCount * rangeCount);
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
LivenessInfo<RegisterPressure>& liveness = registerAllocator.liveness;
|
||||
SparseSet currentLive(pool, rangeCount);
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
currentLive = liveness.liveOut[n];
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
if ((instruction.getFlags() & ifCopy) != 0) {
|
||||
assert(useBegin != useEnd && useBegin[0].isRegister());
|
||||
currentLive.clear(name2range[useBegin[0].getRegisterName()]);
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName define = name2range[definePtr->getRegisterName()];
|
||||
|
||||
for (SparseSet::iterator l = currentLive.begin(); !currentLive.done(l); l = currentLive.advance(l)) {
|
||||
RegisterName live = RegisterName(currentLive.get(l));
|
||||
if (define != live && registerAllocator.canInterfere(define, live))
|
||||
addEdge(define, live);
|
||||
}
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentLive.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
currentLive.set(name2range[usePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName use = name2range[usePtr->getRegisterName()];
|
||||
|
||||
for (SparseSet::iterator l = currentLive.begin(); !currentLive.done(l); l = currentLive.advance(l)) {
|
||||
RegisterName live = RegisterName(currentLive.get(l));
|
||||
if (use != live && registerAllocator.canInterfere(use, live))
|
||||
addEdge(use, live);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void LiveRangeGraph<RegisterPressure>::addEdge(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
assert(name1 != name2);
|
||||
edges->set(name1 * rangeCount + name2);
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool LiveRangeGraph<RegisterPressure>::haveEdge(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
assert(name1 != name2);
|
||||
return edges->test(name1 * rangeCount + name2);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
template <class RegisterPressure>
|
||||
void LiveRangeGraph<RegisterPressure>::printPretty(LogModuleObject log)
|
||||
{
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Live ranges graph:\n"));
|
||||
for (RegisterName name1 = RegisterName(1); name1 < rangeCount; name1 = RegisterName(name1 + 1)) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\t%d:\t", name1));
|
||||
for (RegisterName name2 = RegisterName(1); name2 < rangeCount; name2 = RegisterName(name2 + 1))
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%c", ((name1 != name2) && haveEdge(name1, name2)) ? '1' : '0'));
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
#endif // _LIVE_RANGE_GRAPH_
|
||||
21
mozilla/ef/Compiler/RegisterAllocator/Liveness.cpp
Normal file
21
mozilla/ef/Compiler/RegisterAllocator/Liveness.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Liveness.h"
|
||||
|
||||
301
mozilla/ef/Compiler/RegisterAllocator/Liveness.h
Normal file
301
mozilla/ef/Compiler/RegisterAllocator/Liveness.h
Normal file
@@ -0,0 +1,301 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _LIVENESS_H_
|
||||
#define _LIVENESS_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterTypes.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// LivenessInfo -
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct LivenessInfo
|
||||
{
|
||||
RegisterPressure::Set* liveIn;
|
||||
RegisterPressure::Set* liveOut;
|
||||
DEBUG_LOG_ONLY(Uint32 size);
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Liveness
|
||||
//
|
||||
// The liveness is defined by the following data-flow equations:
|
||||
//
|
||||
// LiveIn(n) = LocalLive(n) U (LiveOut(n) - Killed(n)).
|
||||
// LiveOut(n) = U LiveIn(s) (s a successor of n).
|
||||
//
|
||||
// where LocalLive(n) is the set of used registers in the block n, Killed(n)
|
||||
// is the set of defined registers in the block n, LiveIn(n) is the set of
|
||||
// live registers at the begining of the block n and LiveOut(n) is the set
|
||||
// of live registers at the end of the block n.
|
||||
//
|
||||
//
|
||||
// We will compute the liveness analysis in two stages:
|
||||
//
|
||||
// 1- Build LocalLive(n) (wich is an approximation of LiveIn(n)) and Killed(n)
|
||||
// for each block n.
|
||||
// 2- Perform a backward data-flow analysis to propagate the liveness information
|
||||
// through the entire control-flow graph.
|
||||
//
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct Liveness
|
||||
{
|
||||
static LivenessInfo<RegisterPressure> analysis(ControlGraph& controlGraph, Uint32 rangeCount, const RegisterName* name2range);
|
||||
static LivenessInfo<RegisterPressure> analysis(ControlGraph& controlGraph, Uint32 nameCount);
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
LivenessInfo<RegisterPressure> Liveness<RegisterPressure>::analysis(ControlGraph& controlGraph, Uint32 rangeCount, const RegisterName* name2range)
|
||||
{
|
||||
Pool& pool = controlGraph.pool;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
// Allocate the temporary sets.
|
||||
RegisterPressure::Set* killed = new(pool) RegisterPressure::Set[nNodes](pool, rangeCount);
|
||||
|
||||
// Allocate the globals sets.
|
||||
RegisterPressure::Set* liveIn = new(pool) RegisterPressure::Set[nNodes](pool, rangeCount);
|
||||
RegisterPressure::Set* liveOut = new(pool) RegisterPressure::Set[nNodes](pool, rangeCount);
|
||||
|
||||
// First stage of the liveness analysis: Compute the sets LocalLive(stored in LiveIn) and Killed.
|
||||
//
|
||||
for (Uint32 n = 0; n < (nNodes - 1); n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
RegisterPressure::Set& currentLocalLive = liveIn[n];
|
||||
RegisterPressure::Set& currentKilled = killed[n];
|
||||
|
||||
// Find the instructions contributions to the sets LocalLive and Killed.
|
||||
//
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
// If a VirtualRegister is 'used' before being 'defined' then we add it to set LocalLive.
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
Uint32 index = name2range[usePtr->getRegisterName()];
|
||||
|
||||
if (!currentKilled.test(index))
|
||||
currentLocalLive.set(index);
|
||||
}
|
||||
|
||||
// If a Virtualregister is 'defined' then we add it to the set Killed.
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentKilled.set(name2range[definePtr->getRegisterName()]);
|
||||
}
|
||||
}
|
||||
|
||||
// Second stage of the liveness analysis: We propagate the LiveIn & LiveOut through the entire
|
||||
// control-flow graph.
|
||||
//
|
||||
RegisterPressure::Set temp(pool, rangeCount);
|
||||
|
||||
bool changed;
|
||||
do {
|
||||
changed = false;
|
||||
|
||||
// For all nodes is this graph except the endNode.
|
||||
for (Int32 n = (nNodes - 2); n >= 0; n--) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
RegisterPressure::Set& currentLiveIn = liveIn[n];
|
||||
RegisterPressure::Set& currentLiveOut = liveOut[n];
|
||||
|
||||
// Compute temp = Union of LiveIn(s) (s a successor of this node) | usedByPhiNodes(n).
|
||||
// temp will be the new LiveOut(n).
|
||||
Uint32 nSuccessors = node.nSuccessors();
|
||||
if (nSuccessors != 0) {
|
||||
temp = liveIn[node.nthSuccessor(0).getTarget().dfsNum];
|
||||
for (Uint32 s = 1; s < nSuccessors; s++)
|
||||
temp |= liveIn[node.nthSuccessor(s).getTarget().dfsNum];
|
||||
} else
|
||||
temp.clear();
|
||||
|
||||
// If temp and LiveOut(n) differ then set LiveOut(n) = temp and recalculate the
|
||||
// new LiveIn(n).
|
||||
if (currentLiveOut != temp) {
|
||||
currentLiveOut = temp;
|
||||
temp -= killed[n]; // FIX: could be optimized with one call to unionDiff !
|
||||
temp |= currentLiveIn;
|
||||
|
||||
if (currentLiveIn != temp) {
|
||||
currentLiveIn = temp;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while(changed);
|
||||
|
||||
LivenessInfo<RegisterPressure> liveness;
|
||||
liveness.liveIn = liveIn;
|
||||
liveness.liveOut = liveOut;
|
||||
DEBUG_LOG_ONLY(liveness.size = nNodes);
|
||||
return liveness;
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
LivenessInfo<RegisterPressure> Liveness<RegisterPressure>::analysis(ControlGraph& controlGraph, Uint32 nameCount)
|
||||
{
|
||||
Pool& pool = controlGraph.pool;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
// Allocate the temporary sets.
|
||||
RegisterPressure::Set* killed = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
|
||||
RegisterPressure::Set* usedByPhiNodes = NULL;
|
||||
|
||||
// Allocate the globals sets.
|
||||
RegisterPressure::Set* liveIn = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
|
||||
RegisterPressure::Set* liveOut = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
|
||||
|
||||
// First stage of the liveness analysis: Compute the sets LocalLive(stored in LiveIn) and Killed.
|
||||
//
|
||||
for (Uint32 n = 0; n < (nNodes - 1); n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
RegisterPressure::Set& currentLocalLive = liveIn[n];
|
||||
RegisterPressure::Set& currentKilled = killed[n];
|
||||
|
||||
InstructionList& phiNodes = node.getPhiNodeInstructions();
|
||||
|
||||
if ((usedByPhiNodes == NULL) && !phiNodes.empty())
|
||||
usedByPhiNodes = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
|
||||
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& phiNode = phiNodes.get(p);
|
||||
|
||||
InstructionDefine& define = phiNode.getInstructionDefineBegin()[0];
|
||||
currentKilled.set(define.getRegisterName());
|
||||
|
||||
typedef DoublyLinkedList<ControlEdge> ControlEdgeList;
|
||||
const ControlEdgeList& predecessors = node.getPredecessors();
|
||||
ControlEdgeList::iterator p = predecessors.begin();
|
||||
InstructionUse* useEnd = phiNode.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = phiNode.getInstructionUseBegin(); usePtr < useEnd; usePtr++, p = predecessors.advance(p))
|
||||
if (usePtr->isRegister())
|
||||
usedByPhiNodes[predecessors.get(p).getSource().dfsNum].set(usePtr->getRegisterName());
|
||||
}
|
||||
|
||||
// Find the instructions contributions to the sets LocalLive and Killed.
|
||||
//
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
// If a VirtualRegister is 'used' before being 'defined' then we add it to set LocalLive.
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
Uint32 index = usePtr->getRegisterName();
|
||||
|
||||
if (!currentKilled.test(index))
|
||||
currentLocalLive.set(index);
|
||||
}
|
||||
|
||||
// If a Virtualregister is 'defined' then we add it to the set Killed.
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentKilled.set(definePtr->getRegisterName());
|
||||
}
|
||||
}
|
||||
|
||||
// Second stage of the liveness analysis: We propagate the LiveIn & LiveOut through the entire
|
||||
// control-flow graph.
|
||||
//
|
||||
RegisterPressure::Set temp(pool, nameCount);
|
||||
|
||||
bool changed;
|
||||
do {
|
||||
changed = false;
|
||||
|
||||
// For all nodes is this graph except the endNode.
|
||||
for (Int32 n = (nNodes - 2); n >= 0; n--) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
RegisterPressure::Set& currentLiveIn = liveIn[n];
|
||||
RegisterPressure::Set& currentLiveOut = liveOut[n];
|
||||
|
||||
// Compute temp = Union of LiveIn(s) (s a successor of this node) | usedByPhiNodes(n).
|
||||
// temp will be the new LiveOut(n).
|
||||
Uint32 nSuccessors = node.nSuccessors();
|
||||
if (nSuccessors != 0) {
|
||||
temp = liveIn[node.nthSuccessor(0).getTarget().dfsNum];
|
||||
for (Uint32 s = 1; s < nSuccessors; s++)
|
||||
temp |= liveIn[node.nthSuccessor(s).getTarget().dfsNum];
|
||||
} else
|
||||
temp.clear();
|
||||
|
||||
// Insert the phiNodes contribution.
|
||||
if (usedByPhiNodes != NULL)
|
||||
temp |= usedByPhiNodes[n];
|
||||
|
||||
// If temp and LiveOut(n) differ then set LiveOut(n) = temp and recalculate the
|
||||
// new LiveIn(n).
|
||||
if (currentLiveOut != temp) {
|
||||
currentLiveOut = temp;
|
||||
temp -= killed[n]; // FIX: could be optimized with one call to unionDiff !
|
||||
temp |= currentLiveIn;
|
||||
|
||||
if (currentLiveIn != temp) {
|
||||
currentLiveIn = temp;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while(changed);
|
||||
|
||||
LivenessInfo<RegisterPressure> liveness;
|
||||
liveness.liveIn = liveIn;
|
||||
liveness.liveOut = liveOut;
|
||||
DEBUG_LOG_ONLY(liveness.size = nNodes);
|
||||
return liveness;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
template <class RegisterPressure>
|
||||
void LivenessInfo<RegisterPressure>::printPretty(LogModuleObject log)
|
||||
{
|
||||
for (Uint32 n = 0; n < size; n++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Node N%d:\n\tliveIn = ", n));
|
||||
liveIn[n].printPretty(log);
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\tliveOut = "));
|
||||
liveOut[n].printPretty(log);
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
#endif // _LIVENESS_H_
|
||||
40
mozilla/ef/Compiler/RegisterAllocator/Makefile
Normal file
40
mozilla/ef/Compiler/RegisterAllocator/Makefile
Normal file
@@ -0,0 +1,40 @@
|
||||
#! gmake
|
||||
|
||||
DEPTH = ../..
|
||||
|
||||
MODULE_NAME = RegisterAllocator
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
INCLUDES += \
|
||||
-I$(DEPTH)/Utilities/General \
|
||||
-I$(DEPTH)/Utilities/zlib \
|
||||
-I$(DEPTH)/Runtime/ClassReader \
|
||||
-I$(DEPTH)/Runtime/NativeMethods \
|
||||
-I$(DEPTH)/Runtime/System \
|
||||
-I$(DEPTH)/Runtime/ClassInfo \
|
||||
-I$(DEPTH)/Runtime/FileReader \
|
||||
-I$(DEPTH)/Compiler/PrimitiveGraph \
|
||||
-I$(DEPTH)/Compiler/FrontEnd \
|
||||
-I$(DEPTH)/Compiler/Optimizer \
|
||||
-I$(DEPTH)/Compiler/CodeGenerator \
|
||||
-I$(DEPTH)/Compiler/CodeGenerator/md \
|
||||
-I$(DEPTH)/Compiler/CodeGenerator/md/$(CPU_ARCH) \
|
||||
-I$(DEPTH)/Compiler/RegisterAllocator \
|
||||
-I$(DEPTH)/Driver/StandAloneJava \
|
||||
-I$(DEPTH)/Debugger \
|
||||
$(NULL)
|
||||
|
||||
CXXSRCS = \
|
||||
RegisterAllocator.cpp \
|
||||
RegisterAllocatorTools.cpp \
|
||||
DominatorGraph.cpp \
|
||||
VirtualRegister.cpp \
|
||||
BitSet.cpp \
|
||||
SparseSet.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
||||
libs:: $(MODULE)
|
||||
392
mozilla/ef/Compiler/RegisterAllocator/PhiNodeRemover.h
Normal file
392
mozilla/ef/Compiler/RegisterAllocator/PhiNodeRemover.h
Normal file
@@ -0,0 +1,392 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _PHI_NODE_REMOVER_H_
|
||||
#define _PHI_NODE_REMOVER_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "DominatorGraph.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "RegisterPressure.h"
|
||||
#include "Liveness.h"
|
||||
#include "Instruction.h"
|
||||
#include "InstructionEmitter.h"
|
||||
#include "SparseSet.h"
|
||||
#include <string.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterNameNode -
|
||||
|
||||
struct RegisterNameNode
|
||||
{
|
||||
RegisterNameNode* next;
|
||||
RegisterName newName;
|
||||
Uint32 nextPushed;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// CopyData -
|
||||
|
||||
struct CopyData
|
||||
{
|
||||
RegisterName source;
|
||||
RegisterClassKind classKind;
|
||||
Uint32 useCount;
|
||||
bool isLiveOut;
|
||||
RegisterName sourceNameToUse;
|
||||
RegisterName temporaryName;
|
||||
RegisterNameNode* newName;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// PhiNodeRemover<RegisterPressure> -
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct PhiNodeRemover
|
||||
{
|
||||
// Replace the phi nodes by copy instructions.
|
||||
static void replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter);
|
||||
};
|
||||
|
||||
// Split some of the critical edges and return true if there are still some
|
||||
// in the graph after that.
|
||||
//
|
||||
static bool splitCriticalEdges(ControlGraph& /*cg*/)
|
||||
{
|
||||
// FIX: not implemented.
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void pushName(Pool& pool, RegisterNameNode** stack, SparseSet& pushed, Uint32* nodeListPointer, RegisterName oldName, RegisterName newName)
|
||||
{
|
||||
RegisterNameNode& newNode = *new(pool) RegisterNameNode();
|
||||
|
||||
if (pushed.test(oldName))
|
||||
(*stack)->newName = newName;
|
||||
else {
|
||||
newNode.newName = newName;
|
||||
newNode.nextPushed = *nodeListPointer;
|
||||
*nodeListPointer = oldName;
|
||||
newNode.next = *stack;
|
||||
*stack = &newNode;
|
||||
pushed.set(oldName);
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void PhiNodeRemover<RegisterPressure>::replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter)
|
||||
{
|
||||
Pool& pool = controlGraph.pool;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
// Initialize the local variables.
|
||||
//
|
||||
|
||||
// When we insert the copies we will also need to create new VirtualRegisters for
|
||||
// the insertion of temporaries. The maximum number of temporary register will not
|
||||
// exceed the number of phiNodes in the primitive graph.
|
||||
Uint32 nameCount = vrManager.getSize();
|
||||
Uint32 maxNameCount = nameCount;
|
||||
for (Uint32 n = 0; n < nNodes; n++)
|
||||
maxNameCount += nodes[n]->getPhiNodes().length();
|
||||
|
||||
// If the CFG contains some critical edges (backward edge which source has more than one
|
||||
// outgoing edge and destination has more than one incomimg edge) then we need the liveness
|
||||
// information to be able to insert temporary copies.
|
||||
RegisterPressure::Set* liveOut = NULL;
|
||||
if (splitCriticalEdges(controlGraph))
|
||||
liveOut = Liveness<LowRegisterPressure>::analysis(controlGraph, nameCount).liveOut;
|
||||
|
||||
DominatorGraph dGraph(controlGraph);
|
||||
|
||||
SparseSet pushed(pool, maxNameCount);
|
||||
SparseSet destinationList(pool, maxNameCount);
|
||||
SparseSet workList(pool, maxNameCount);
|
||||
|
||||
CopyData* copyStats = new(pool) CopyData[maxNameCount];
|
||||
memset(copyStats, '\0', maxNameCount*sizeof(CopyData));
|
||||
|
||||
struct NodeStack {
|
||||
Uint32* next;
|
||||
Uint32* limit;
|
||||
Uint32 pushedList;
|
||||
};
|
||||
|
||||
// Allocate the node stack and initialize the node stack pointer.
|
||||
NodeStack* nodeStack = new(pool) NodeStack[nNodes + 1];
|
||||
NodeStack* nodeStackPtr = nodeStack;
|
||||
|
||||
// We start by the begin node.
|
||||
Uint32 startNode = 0;
|
||||
Uint32* next = &startNode;
|
||||
Uint32* limit = &startNode + 1;
|
||||
|
||||
while (true) {
|
||||
|
||||
if (next == limit) {
|
||||
// If there are no more node in the sibling, we have to pop the current
|
||||
// frame from the stack and update the copyStats of the pushed nodes.
|
||||
//
|
||||
if (nodeStackPtr == nodeStack)
|
||||
// We are at the bottom of the stack and there are no more nodes
|
||||
// to look at. We are done !
|
||||
break;
|
||||
|
||||
--nodeStackPtr;
|
||||
// We are done with all the children of this node in the dominator tree.
|
||||
// We need to update the copy information of all the new names pushed
|
||||
// during the walk over this node.
|
||||
Uint32 pushedList = nodeStackPtr->pushedList;
|
||||
while (pushedList != 0) {
|
||||
Uint32 nextName = copyStats[pushedList].newName->nextPushed;
|
||||
copyStats[pushedList].newName = copyStats[pushedList].newName->next;
|
||||
pushedList = nextName;
|
||||
}
|
||||
|
||||
// restore the previous frame.
|
||||
next = nodeStackPtr->next;
|
||||
limit = nodeStackPtr->limit;
|
||||
} else {
|
||||
Uint32 currentNode = *next++;
|
||||
Uint32 pushedList = 0;
|
||||
|
||||
|
||||
// Initialize the sets.
|
||||
pushed.clear();
|
||||
destinationList.clear();
|
||||
|
||||
// STEP1:
|
||||
// Walk the instruction list and to replace all the instruction uses with their new name.
|
||||
// If the instruction is a phi node and its defined register is alive at the end of this
|
||||
// block then we push the defined register into the stack.
|
||||
//
|
||||
ControlNode& node = *nodes[currentNode];
|
||||
RegisterPressure::Set* currentLiveOut = (liveOut != NULL) ? &liveOut[currentNode] : (RegisterPressure::Set*) 0;
|
||||
|
||||
InstructionList& phiNodes = node.getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& phiNode = phiNodes.get(p);
|
||||
|
||||
InstructionUse* useEnd = phiNode.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = phiNode.getInstructionUseBegin(); usePtr < useEnd; usePtr++) {
|
||||
assert(usePtr->isRegister());
|
||||
RegisterName name = usePtr->getRegisterName();
|
||||
|
||||
if (copyStats[name].newName != NULL && copyStats[name].newName->newName != name)
|
||||
usePtr->setRegisterName(copyStats[name].newName->newName);
|
||||
}
|
||||
|
||||
if (currentLiveOut != NULL) {
|
||||
// This is a phi node and we have to push its defined name if it is live
|
||||
// at the end of the node. We only need to do this if the CFG has critical edges.
|
||||
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd() && phiNode.getInstructionDefineBegin()[0].isRegister());
|
||||
RegisterName name = phiNode.getInstructionDefineBegin()[0].getRegisterName();
|
||||
|
||||
if (currentLiveOut->test(name))
|
||||
pushName(pool, &(copyStats[name].newName), pushed, &pushedList, name, name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName name = usePtr->getRegisterName();
|
||||
|
||||
if (copyStats[name].newName != NULL && copyStats[name].newName->newName != name)
|
||||
usePtr->setRegisterName(copyStats[name].newName->newName);
|
||||
}
|
||||
}
|
||||
|
||||
// STEP2:
|
||||
// Look at this node's successors' phiNodes. We keep track of the number of time
|
||||
// a VR will be used by another copy instruction and insert each definition into the
|
||||
// destinationList. This is the only pass over this node's successors as we will
|
||||
// get all the information we need in the CopyData structures.
|
||||
//
|
||||
ControlEdge* successorEdgeEnd = node.getSuccessorsEnd();
|
||||
for (ControlEdge* successorEdgePtr = node.getSuccessorsBegin(); successorEdgePtr < successorEdgeEnd; successorEdgePtr++) {
|
||||
Uint32 useIndex = successorEdgePtr->getIndex();
|
||||
ControlNode& successor = successorEdgePtr->getTarget();
|
||||
|
||||
// Look at its phi nodes. The phi nodes are at the top of the instruction list. We exit
|
||||
// as soon as we find an instruction which is not a phi node
|
||||
InstructionList& phiNodes = successor.getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& phiNode = phiNodes.get(p);
|
||||
|
||||
assert((phiNode.getInstructionUseBegin() + useIndex) < phiNode.getInstructionUseEnd());
|
||||
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd());
|
||||
|
||||
InstructionUse& source = phiNode.getInstructionUseBegin()[useIndex];
|
||||
InstructionDefine& destination = phiNode.getInstructionDefineBegin()[0];
|
||||
|
||||
assert(source.isRegister() && destination.isRegister());
|
||||
|
||||
RegisterName sourceName = source.getRegisterName();
|
||||
RegisterName destinationName = destination.getRegisterName();
|
||||
|
||||
// Get the correct name for the source.
|
||||
if (copyStats[sourceName].newName != NULL)
|
||||
sourceName = copyStats[sourceName].newName->newName;
|
||||
|
||||
// Update the CopyData structures.
|
||||
if ((sourceName != rnInvalid) && (sourceName != destinationName)) {
|
||||
copyStats[destinationName].source = sourceName;
|
||||
copyStats[destinationName].classKind = destination.getRegisterClass();
|
||||
copyStats[destinationName].isLiveOut = (currentLiveOut != NULL) ? currentLiveOut->test(destinationName) : false;
|
||||
copyStats[destinationName].sourceNameToUse = destinationName;
|
||||
copyStats[sourceName].sourceNameToUse = sourceName;
|
||||
copyStats[sourceName].useCount++;
|
||||
destinationList.set(destinationName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// STEP3:
|
||||
// Insert into the worklist only the destination registers that will be not used in
|
||||
// another copy instruction in this block.
|
||||
//
|
||||
assert(workList.getSize() == 0);
|
||||
for (SparseSet::iterator d = destinationList.begin(); !destinationList.done(d); d = destinationList.advance(d)) {
|
||||
Uint32 dest = destinationList.get(d);
|
||||
if (copyStats[dest].useCount == 0)
|
||||
workList.set(dest);
|
||||
}
|
||||
|
||||
// STEP4:
|
||||
// Insert the copy instructions.
|
||||
//
|
||||
Uint32 destinationListSize = destinationList.getSize();
|
||||
InstructionList::iterator endOfTheNode = instructions.end();
|
||||
|
||||
// Find the right place to insert the copy instructions.
|
||||
if (destinationListSize != 0)
|
||||
while (instructions.get(endOfTheNode).getFlags() & ifControl)
|
||||
endOfTheNode = instructions.retreat(endOfTheNode);
|
||||
|
||||
while (destinationListSize != 0) {
|
||||
while(workList.getSize()) {
|
||||
RegisterName destinationName = RegisterName(workList.getOne());
|
||||
RegisterName sourceName = copyStats[destinationName].source;
|
||||
|
||||
workList.clear(destinationName);
|
||||
if (copyStats[destinationName].isLiveOut && !copyStats[destinationName].temporaryName) {
|
||||
// Lost copy problem.
|
||||
copyStats[destinationName].isLiveOut = false;
|
||||
|
||||
RegisterName sourceName = destinationName;
|
||||
RegisterClassKind classKind = copyStats[sourceName].classKind;
|
||||
RegisterName destinationName = getName(vrManager.newVirtualRegister(classKind));
|
||||
assert(destinationName < maxNameCount);
|
||||
|
||||
copyStats[destinationName].classKind = classKind;
|
||||
copyStats[sourceName].useCount = 0;
|
||||
|
||||
// We need to insert a copy to a temporary register to keep the
|
||||
// source register valid at the end of the node defining it.
|
||||
// This copy will be inserted right after the phi node defining it.
|
||||
RegisterName from = copyStats[sourceName].sourceNameToUse;
|
||||
Instruction* definingPhiNode = vrManager.getVirtualRegister(from).getDefiningInstruction();
|
||||
assert(definingPhiNode && (definingPhiNode->getFlags() & ifPhiNode) != 0);
|
||||
|
||||
RegisterID fromID = buildRegisterID(from, classKind);
|
||||
RegisterID toID = buildRegisterID(destinationName, classKind);
|
||||
Instruction& copy = emitter.newCopy(*definingPhiNode->getPrimitive(), fromID, toID);
|
||||
vrManager.getVirtualRegister(destinationName).setDefiningInstruction(copy);
|
||||
definingPhiNode->getPrimitive()->getContainer()->getInstructions().addFirst(copy);
|
||||
|
||||
copyStats[sourceName].temporaryName = destinationName;
|
||||
copyStats[sourceName].sourceNameToUse = destinationName;
|
||||
pushName(pool, &(copyStats[sourceName].newName), pushed, &pushedList, sourceName, destinationName);
|
||||
}
|
||||
|
||||
// Insert the copy instruction at the end of the current node.
|
||||
RegisterName from = copyStats[sourceName].sourceNameToUse;
|
||||
|
||||
RegisterClassKind classKind = copyStats[destinationName].classKind;
|
||||
RegisterID fromID = buildRegisterID(from, classKind);
|
||||
RegisterID toID = buildRegisterID(destinationName, classKind);
|
||||
Instruction& copy = emitter.newCopy(*vrManager.getVirtualRegister(from).getDefiningInstruction()->getPrimitive(), fromID, toID);
|
||||
instructions.insertAfter(copy, endOfTheNode);
|
||||
endOfTheNode = instructions.advance(endOfTheNode);
|
||||
|
||||
copyStats[sourceName].useCount = 0;
|
||||
if (destinationList.test(sourceName) && copyStats[sourceName].isLiveOut)
|
||||
pushName(pool, &(copyStats[sourceName].newName), pushed, &pushedList, sourceName, destinationName);
|
||||
copyStats[sourceName].isLiveOut = false;
|
||||
copyStats[sourceName].sourceNameToUse = destinationName;
|
||||
|
||||
if (destinationList.test(sourceName))
|
||||
workList.set(sourceName);
|
||||
destinationList.clear(destinationName);
|
||||
}
|
||||
|
||||
destinationListSize = destinationList.getSize();
|
||||
if (destinationListSize != 0) {
|
||||
RegisterName sourceName = RegisterName(destinationList.getOne());
|
||||
RegisterName destinationName;
|
||||
|
||||
if (!copyStats[sourceName].temporaryName) {
|
||||
// Cycle problem.
|
||||
RegisterClassKind classKind = copyStats[sourceName].classKind;
|
||||
destinationName = getName(vrManager.newVirtualRegister(classKind));
|
||||
assert(destinationName < maxNameCount);
|
||||
|
||||
copyStats[destinationName].classKind = classKind;
|
||||
copyStats[sourceName].temporaryName = destinationName;
|
||||
|
||||
// Insert the copy instruction at the end of the current node.
|
||||
RegisterName from = copyStats[sourceName].sourceNameToUse;
|
||||
|
||||
RegisterID fromID = buildRegisterID(from, classKind);
|
||||
RegisterID toID = buildRegisterID(destinationName, classKind);
|
||||
Instruction& copy = emitter.newCopy(*vrManager.getVirtualRegister(from).getDefiningInstruction()->getPrimitive(), fromID, toID);
|
||||
vrManager.getVirtualRegister(destinationName).setDefiningInstruction(copy);
|
||||
instructions.insertAfter(copy, endOfTheNode);
|
||||
endOfTheNode = instructions.advance(endOfTheNode);
|
||||
} else
|
||||
destinationName = copyStats[sourceName].temporaryName;
|
||||
|
||||
copyStats[sourceName].useCount = 0;
|
||||
copyStats[sourceName].isLiveOut = false;
|
||||
copyStats[sourceName].sourceNameToUse = destinationName;
|
||||
pushName(pool, &(copyStats[sourceName].newName), pushed, &pushedList, sourceName, destinationName);
|
||||
|
||||
workList.set(sourceName);
|
||||
}
|
||||
}
|
||||
|
||||
nodeStackPtr->pushedList = pushedList;
|
||||
nodeStackPtr->next = next;
|
||||
nodeStackPtr->limit = limit;
|
||||
++nodeStackPtr;
|
||||
next = dGraph.getSuccessorsBegin(currentNode);
|
||||
limit = dGraph.getSuccessorsEnd(currentNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _PHI_NODE_REMOVER_H_
|
||||
155
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocator.cpp
Normal file
155
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocator.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "LogModule.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterPressure.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
#include "PhiNodeRemover.h"
|
||||
#include "LiveRange.h"
|
||||
#include "Liveness.h"
|
||||
#include "InterferenceGraph.h"
|
||||
#include "LiveRangeGraph.h"
|
||||
#include "Coalescing.h"
|
||||
#include "Spilling.h"
|
||||
#include "Coloring.h"
|
||||
#include "Splits.h"
|
||||
|
||||
class Pool;
|
||||
class ControlGraph;
|
||||
class VirtualRegisterManager;
|
||||
class InstructionEmitter;
|
||||
|
||||
UT_DEFINE_LOG_MODULE(RegAlloc);
|
||||
|
||||
void RegisterAllocator::allocateRegisters(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter)
|
||||
{
|
||||
// Insert the phi node instructions. We want to do this to have a single defined register per instruction.
|
||||
// If we keep the PhiNode (as a DataNode) and a PhiNode is of DoubleWordKind then we have to execute
|
||||
// some special code for the high word annotation.
|
||||
//
|
||||
RegisterAllocatorTools::insertPhiNodeInstructions(controlGraph, emitter);
|
||||
|
||||
// Perform some tests on the instruction graph.
|
||||
//
|
||||
DEBUG_ONLY(RegisterAllocatorTools::testTheInstructionGraph(controlGraph, vrManager));
|
||||
|
||||
// Replace the phi node instructions by their equivalent copy instructions.
|
||||
//
|
||||
PhiNodeRemover<LowRegisterPressure>::replacePhiNodes(controlGraph, vrManager, emitter);
|
||||
|
||||
// Do the register allocation.
|
||||
//
|
||||
RegisterAllocator registerAllocator(pool, controlGraph, vrManager, emitter);
|
||||
registerAllocator.doGraphColoring();
|
||||
}
|
||||
|
||||
void RegisterAllocator::doGraphColoring()
|
||||
{
|
||||
// Initialize the liverange map.
|
||||
//
|
||||
initLiveRanges();
|
||||
|
||||
// Build the live ranges. We do this to compress the number of RegisterNames
|
||||
// used in the insterference graph.
|
||||
//
|
||||
LiveRange<LowRegisterPressure>::build(*this);
|
||||
|
||||
// Remove unnecessary copies.
|
||||
//
|
||||
RegisterAllocatorTools::removeUnnecessaryCopies(*this);
|
||||
|
||||
for (Uint8 loop = 0; loop < 10; loop++) {
|
||||
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("********* RegisterAllocator loop %d *********\n", loop));
|
||||
|
||||
while(true) {
|
||||
// Build the interference graph.
|
||||
//
|
||||
iGraph.build();
|
||||
|
||||
// Coalesce the copy instructions.
|
||||
//
|
||||
if (!Coalescing<LowRegisterPressure>::coalesce(*this))
|
||||
break;
|
||||
}
|
||||
|
||||
// Print the interference graph.
|
||||
//
|
||||
DEBUG_LOG_ONLY(iGraph.printPretty(UT_LOG_MODULE(RegAlloc)));
|
||||
|
||||
// Calculate the spill costs.
|
||||
//
|
||||
Spilling<LowRegisterPressure>::calculateSpillCosts(*this);
|
||||
DEBUG_LOG_ONLY(RegisterAllocatorTools::printSpillCosts(*this));
|
||||
|
||||
// Calculate the split costs.
|
||||
//
|
||||
Splits<LowRegisterPressure>::calculateSplitCosts(*this);
|
||||
DEBUG_LOG_ONLY(RegisterAllocatorTools::printSplitCosts(*this));
|
||||
|
||||
// Build the live range graph.
|
||||
//
|
||||
lGraph.build();
|
||||
DEBUG_LOG_ONLY(lGraph.printPretty(UT_LOG_MODULE(RegAlloc)));
|
||||
|
||||
// Color the graph. If it succeeds then we're done with the
|
||||
// register allocation.
|
||||
//
|
||||
if (Coloring<LowRegisterPressure>::color(*this)) {
|
||||
// Write the final colors in the instruction graph.
|
||||
//
|
||||
Coloring<LowRegisterPressure>::finalColoring(*this);
|
||||
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("********** RegisterAllocator done **********\n"));
|
||||
DEBUG_LOG_ONLY(RegisterAllocatorTools::printInstructions(*this));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to spill some registers.
|
||||
//
|
||||
Spilling<LowRegisterPressure>::insertSpillCode(*this);
|
||||
|
||||
// Insert the split instructions.
|
||||
//
|
||||
Splits<LowRegisterPressure>::insertSplitCode(*this);
|
||||
|
||||
// Update the live ranges.
|
||||
//
|
||||
// FIX
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
RegisterAllocatorTools::updateInstructionGraph(*this);
|
||||
RegisterAllocatorTools::printInstructions(*this);
|
||||
#endif
|
||||
fprintf(stderr, "!!! Coloring failed after 10 loops !!!\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
void RegisterAllocator::initLiveRanges()
|
||||
{
|
||||
Uint32 count = this->nameCount;
|
||||
RegisterName* name2range = new(pool) RegisterName[nameCount];
|
||||
for (RegisterName r = RegisterName(1); r < count; r = RegisterName(r + 1))
|
||||
name2range[r] = r;
|
||||
this->name2range = name2range;
|
||||
rangeCount = count;
|
||||
}
|
||||
88
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocator.h
Normal file
88
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocator.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_ALLOCATOR_H_
|
||||
#define _REGISTER_ALLOCATOR_H_
|
||||
|
||||
class Pool;
|
||||
class ControlGraph;
|
||||
class InstructionEmitter;
|
||||
struct SpillCost;
|
||||
struct SplitCost;
|
||||
|
||||
#include "Liveness.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "RegisterPressure.h" // This should included by Backend.cpp
|
||||
#include "InterferenceGraph.h"
|
||||
#include "LiveRangeGraph.h"
|
||||
|
||||
//template <class RegisterPressure>
|
||||
class RegisterAllocator
|
||||
{
|
||||
public:
|
||||
|
||||
Pool& pool; //
|
||||
ControlGraph& controlGraph; //
|
||||
VirtualRegisterManager& vrManager; //
|
||||
InstructionEmitter& emitter; //
|
||||
|
||||
RegisterName* name2range; //
|
||||
RegisterName* color; //
|
||||
SpillCost* spillCost; //
|
||||
SparseSet* willSpill; //
|
||||
SplitCost* splitCost; //
|
||||
NameLinkedList** splitAround; //
|
||||
InterferenceGraph<LowRegisterPressure> iGraph; //
|
||||
LiveRangeGraph<LowRegisterPressure> lGraph; //
|
||||
LivenessInfo<LowRegisterPressure> liveness; //
|
||||
Uint32 nameCount; //
|
||||
Uint32 rangeCount; //
|
||||
bool splitFound; //
|
||||
|
||||
private:
|
||||
|
||||
//
|
||||
//
|
||||
void doGraphColoring();
|
||||
|
||||
public:
|
||||
|
||||
//
|
||||
//
|
||||
inline RegisterAllocator(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter);
|
||||
|
||||
//
|
||||
//
|
||||
bool canInterfere(RegisterName /*name1*/, RegisterName /*name2*/) const {return true;}
|
||||
|
||||
//
|
||||
//
|
||||
void initLiveRanges();
|
||||
|
||||
//
|
||||
//
|
||||
static void allocateRegisters(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter);
|
||||
};
|
||||
|
||||
//
|
||||
//
|
||||
inline RegisterAllocator::RegisterAllocator(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter)
|
||||
: pool(pool), controlGraph(controlGraph), vrManager(vrManager), emitter(emitter), iGraph(*this), lGraph(*this), nameCount(vrManager.getSize()) {}
|
||||
|
||||
#endif // _REGISTER_ALLOCATOR_H_
|
||||
|
||||
355
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocatorTools.cpp
Normal file
355
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocatorTools.cpp
Normal file
@@ -0,0 +1,355 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "LogModule.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
#include "Pool.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Primitives.h"
|
||||
#include "InstructionEmitter.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "Spilling.h"
|
||||
#include "Splits.h"
|
||||
#include "BitSet.h"
|
||||
|
||||
UT_EXTERN_LOG_MODULE(RegAlloc);
|
||||
|
||||
#ifdef DEBUG
|
||||
void RegisterAllocatorTools::testTheInstructionGraph(ControlGraph& controlGraph, VirtualRegisterManager& vrManager)
|
||||
{
|
||||
// Test the declared VirtualRegisters. The register allocator tries to condense the register universe.
|
||||
// Any gap in the VirtualRegister names will be a loss of efficiency !!!!
|
||||
|
||||
Uint32 nameCount = vrManager.getSize();
|
||||
BitSet registerSeen(controlGraph.pool, nameCount);
|
||||
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
registerSeen.set(usePtr->getRegisterName());
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
registerSeen.set(definePtr->getRegisterName());
|
||||
}
|
||||
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& instruction = phiNodes.get(p);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
registerSeen.set(usePtr->getRegisterName());
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
registerSeen.set(definePtr->getRegisterName());
|
||||
}
|
||||
}
|
||||
|
||||
bool renameRegisters = false;
|
||||
for (BitSet::iterator i = registerSeen.nextZero(0); !registerSeen.done(i); i = registerSeen.nextZero(i)) {
|
||||
renameRegisters = true;
|
||||
fprintf(stderr,
|
||||
"WARNING: The VirtualRegister vr%d has been allocated during CodeGeneration but\n"
|
||||
" is never used nor defined by any instruction in the instruction graph\n"
|
||||
" PLEASE FIX \n",
|
||||
i);
|
||||
}
|
||||
if (renameRegisters) {
|
||||
Instruction** definingInstruction = new Instruction*[nameCount];
|
||||
memset(definingInstruction, '\0', nameCount * sizeof(Instruction*));
|
||||
RegisterName* newName = new RegisterName[nameCount];
|
||||
memset(newName, '\0', nameCount * sizeof(RegisterName));
|
||||
RegisterName nextName = RegisterName(1);
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName name = usePtr->getRegisterName();
|
||||
if (newName[name] == rnInvalid) {
|
||||
newName[name] = nextName;
|
||||
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
|
||||
nextName = RegisterName(nextName + 1);
|
||||
}
|
||||
usePtr->setRegisterName(newName[name]);
|
||||
}
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName name = definePtr->getRegisterName();
|
||||
if (newName[name] == rnInvalid) {
|
||||
newName[name] = nextName;
|
||||
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
|
||||
nextName = RegisterName(nextName + 1);
|
||||
}
|
||||
definePtr->setRegisterName(newName[name]);
|
||||
}
|
||||
}
|
||||
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& instruction = phiNodes.get(p);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName name = usePtr->getRegisterName();
|
||||
if (newName[name] == rnInvalid) {
|
||||
newName[name] = nextName;
|
||||
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
|
||||
nextName = RegisterName(nextName + 1);
|
||||
}
|
||||
usePtr->setRegisterName(newName[name]);
|
||||
}
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName name = definePtr->getRegisterName();
|
||||
if (newName[name] == rnInvalid) {
|
||||
newName[name] = nextName;
|
||||
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
|
||||
nextName = RegisterName(nextName + 1);
|
||||
}
|
||||
definePtr->setRegisterName(newName[name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vrManager.setSize(nextName);
|
||||
|
||||
for (RegisterName r = RegisterName(1); r < nextName; r = RegisterName(r + 1))
|
||||
vrManager.getVirtualRegister(r).definingInstruction = definingInstruction[r];
|
||||
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("RegisterMap:\n"));
|
||||
for (Uint32 i = 1; i < nameCount; i++)
|
||||
if (newName[i] != 0)
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tvr%d becomes vr%d.\n", i, newName[i]));
|
||||
else
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tvr%d is dead.\n", i));
|
||||
|
||||
|
||||
delete newName;
|
||||
delete definingInstruction;
|
||||
}
|
||||
|
||||
}
|
||||
#endif // DEBUG
|
||||
|
||||
void RegisterAllocatorTools::removeUnnecessaryCopies(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i);) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
i = instructions.advance(i);
|
||||
|
||||
if (instruction.getFlags() & ifCopy) {
|
||||
assert(instruction.getInstructionUseBegin() != instruction.getInstructionUseEnd() && instruction.getInstructionUseBegin()[0].isRegister());
|
||||
assert(instruction.getInstructionDefineBegin() != instruction.getInstructionDefineEnd() && instruction.getInstructionDefineBegin()[0].isRegister());
|
||||
|
||||
RegisterName source = name2range[instruction.getInstructionUseBegin()[0].getRegisterName()];
|
||||
RegisterName destination = name2range[instruction.getInstructionDefineBegin()[0].getRegisterName()];
|
||||
|
||||
if (source == destination)
|
||||
instruction.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RegisterAllocatorTools::updateInstructionGraph(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
usePtr->setRegisterName(name2range[usePtr->getRegisterName()]);
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
definePtr->setRegisterName(name2range[definePtr->getRegisterName()]);
|
||||
}
|
||||
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& instruction = phiNodes.get(p);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
usePtr->setRegisterName(name2range[usePtr->getRegisterName()]);
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
definePtr->setRegisterName(name2range[definePtr->getRegisterName()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RegisterAllocatorTools::insertPhiNodeInstructions(ControlGraph& controlGraph, InstructionEmitter& emitter)
|
||||
{
|
||||
Pool& pool = controlGraph.pool;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
DoublyLinkedList<PhiNode>& phiNodes = node.getPhiNodes();
|
||||
|
||||
if (!phiNodes.empty()) {
|
||||
|
||||
// Set the index of the incoming edges.
|
||||
Uint32 index = 0;
|
||||
const DoublyLinkedList<ControlEdge>& predecessors = node.getPredecessors();
|
||||
for (DoublyLinkedList<ControlEdge>::iterator p = predecessors.begin(); !predecessors.done(p); p = predecessors.advance(p))
|
||||
predecessors.get(p).setIndex(index++);
|
||||
|
||||
// Insert the phi node instruction in the instruction list.
|
||||
for (DoublyLinkedList<PhiNode>::iterator i = phiNodes.begin(); !phiNodes.done(i); i = phiNodes.advance(i)) {
|
||||
PhiNode& phiNode = phiNodes.get(i);
|
||||
ValueKind kind = phiNode.getKind();
|
||||
|
||||
if (!isStorableKind(kind))
|
||||
continue;
|
||||
|
||||
RegisterClassKind classKind = rckGeneral; // FIX: get class kind from phi node kind.
|
||||
Uint32 nInputs = phiNode.nInputs();
|
||||
|
||||
PhiNodeInstruction& phiNodeInstruction = *new(pool) PhiNodeInstruction(&phiNode, pool, nInputs);
|
||||
|
||||
emitter.defineProducer(phiNode, phiNodeInstruction, 0, classKind, drLow);
|
||||
for (Uint32 whichInput = 0; whichInput < nInputs; whichInput++)
|
||||
emitter.useProducer(phiNode.nthInputVariable(whichInput), phiNodeInstruction, whichInput, classKind, drLow);
|
||||
|
||||
node.addPhiNodeInstruction(phiNodeInstruction);
|
||||
|
||||
if (isDoublewordKind(kind)) {
|
||||
PhiNodeInstruction& phiNodeInstruction = *new(pool) PhiNodeInstruction(&phiNode, pool, nInputs);
|
||||
|
||||
emitter.defineProducer(phiNode, phiNodeInstruction, 0, classKind, drHigh);
|
||||
for (Uint32 whichInput = 0; whichInput < nInputs; whichInput++)
|
||||
emitter.useProducer(phiNode.nthInputVariable(whichInput), phiNodeInstruction, whichInput, classKind, drHigh);
|
||||
|
||||
node.addPhiNodeInstruction(phiNodeInstruction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
|
||||
void RegisterAllocatorTools::printSpillCosts(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
LogModuleObject log = UT_LOG_MODULE(RegAlloc);
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
SpillCost* cost = registerAllocator.spillCost;
|
||||
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Spill costs:\n"));
|
||||
for (Uint32 i = 1; i < rangeCount; i++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\trange %d : ", i));
|
||||
if (cost[i].infinite)
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("infinite\n"));
|
||||
else
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%f\n", cost[i].cost));
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterAllocatorTools::printSplitCosts(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
LogModuleObject log = UT_LOG_MODULE(RegAlloc);
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
SplitCost* cost = registerAllocator.splitCost;
|
||||
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Split costs:\n"));
|
||||
for (Uint32 i = 1; i < rangeCount; i++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\trange %d : loads = %f stores = %f\n", i, cost[i].loads, cost[i].stores));
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterAllocatorTools::printInstructions(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
LogModuleObject log = UT_LOG_MODULE(RegAlloc);
|
||||
ControlNode** nodes = registerAllocator.controlGraph.dfsList;
|
||||
Uint32 nNodes = registerAllocator.controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("N%d:\n", n));
|
||||
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
|
||||
if (!phiNodes.empty()) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" PhiNodes:\n", n));
|
||||
for(InstructionList::iterator i = phiNodes.begin(); !phiNodes.done(i); i = phiNodes.advance(i)) {
|
||||
phiNodes.get(i).printPretty(log);
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
if (!instructions.empty())
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" Instructions:\n", n));
|
||||
}
|
||||
|
||||
for(InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
instructions.get(i).printPretty(log);
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
117
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocatorTools.h
Normal file
117
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocatorTools.h
Normal file
@@ -0,0 +1,117 @@
|
||||
// -*- mode:C++; tab-width:4; truncate-lines:t -*-
|
||||
//
|
||||
// CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
// NETSCAPE COMMUNICATIONS CORPORATION
|
||||
// Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
// Reserved. Use of this Source Code is subject to the terms of the
|
||||
// applicable license agreement from Netscape Communications Corporation.
|
||||
// The copyright notice(s) in this Source Code does not indicate actual or
|
||||
// intended publication of this Source Code.
|
||||
//
|
||||
// $Id: RegisterAllocatorTools.h,v 1.1.2.1 1999-03-02 16:12:05 fur%netscape.com Exp $
|
||||
//
|
||||
|
||||
#ifndef _REGISTER_ALLOCATOR_TOOLS_H_
|
||||
#define _REGISTER_ALLOCATOR_TOOLS_H_
|
||||
|
||||
#include "LogModule.h"
|
||||
#include "RegisterTypes.h"
|
||||
#include <string.h>
|
||||
|
||||
class RegisterAllocator;
|
||||
class ControlGraph;
|
||||
class InstructionEmitter;
|
||||
class VirtualRegisterManager;
|
||||
|
||||
struct RegisterAllocatorTools
|
||||
{
|
||||
//
|
||||
//
|
||||
static void insertPhiNodeInstructions(ControlGraph& controlGraph, InstructionEmitter& emitter);
|
||||
|
||||
//
|
||||
//
|
||||
static void updateInstructionGraph(RegisterAllocator& registerAllocator);
|
||||
|
||||
//
|
||||
//
|
||||
static void removeUnnecessaryCopies(RegisterAllocator& registerAllocator);
|
||||
|
||||
#ifdef DEBUG
|
||||
//
|
||||
//
|
||||
static void testTheInstructionGraph(ControlGraph& controlGraph, VirtualRegisterManager& vrManager);
|
||||
#endif // DEBUG
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
//
|
||||
//
|
||||
static void printInstructions(RegisterAllocator& registerAllocator);
|
||||
|
||||
//
|
||||
//
|
||||
static void printSpillCosts(RegisterAllocator& registerAllocator);
|
||||
|
||||
//
|
||||
//
|
||||
static void printSplitCosts(RegisterAllocator& registerAllocator);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
//
|
||||
// FIX: this should go in a class (LookupTable ?)
|
||||
//
|
||||
|
||||
inline RegisterName findRoot(RegisterName name, RegisterName* table)
|
||||
{
|
||||
RegisterName* stack = table;
|
||||
RegisterName* stackPtr = stack;
|
||||
|
||||
RegisterName newName;
|
||||
while((newName = table[name]) != name) {
|
||||
*--stackPtr = name;
|
||||
name = newName;
|
||||
}
|
||||
|
||||
while (stackPtr != stack)
|
||||
table[*stackPtr++] = name;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
inline void init(RegisterName* table, Uint32 nameCount)
|
||||
{
|
||||
for (RegisterName r = RegisterName(0); r < nameCount; r = RegisterName(r + 1))
|
||||
table[r] = r;
|
||||
}
|
||||
|
||||
inline Uint32 compress(RegisterName* name2range, RegisterName* table, Uint32 nameCount, Uint32 tableSize)
|
||||
{
|
||||
RegisterName* liveRange = new RegisterName[tableSize];
|
||||
memset(liveRange, '\0', tableSize * sizeof(RegisterName));
|
||||
|
||||
// Update the lookup table.
|
||||
for (RegisterName r = RegisterName(1); r < tableSize; r = RegisterName(r + 1))
|
||||
findRoot(r, table);
|
||||
|
||||
// Count the liveranges.
|
||||
Uint32 liveRangeCount = 1;
|
||||
for (RegisterName s = RegisterName(1); s < tableSize; s = RegisterName(s + 1))
|
||||
if (table[s] == s)
|
||||
liveRange[s] = RegisterName(liveRangeCount++);
|
||||
|
||||
for (RegisterName t = RegisterName(1); t < nameCount; t = RegisterName(t + 1))
|
||||
name2range[t] = liveRange[table[name2range[t]]];
|
||||
|
||||
return liveRangeCount;
|
||||
}
|
||||
|
||||
inline double doLog10(Uint32 power)
|
||||
{
|
||||
double log = 1.0;
|
||||
while (power--)
|
||||
log *= 10.0;
|
||||
return log;
|
||||
}
|
||||
|
||||
#endif // _REGISTER_ALLOCATOR_TOOLS_H_
|
||||
38
mozilla/ef/Compiler/RegisterAllocator/RegisterAssigner.h
Normal file
38
mozilla/ef/Compiler/RegisterAllocator/RegisterAssigner.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_ASSIGNER_H_
|
||||
#define _REGISTER_ASSIGNER_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "VirtualRegister.h"
|
||||
|
||||
class FastBitMatrix;
|
||||
|
||||
class RegisterAssigner
|
||||
{
|
||||
protected:
|
||||
VirtualRegisterManager& vRegManager;
|
||||
|
||||
public:
|
||||
RegisterAssigner(VirtualRegisterManager& vrMan) : vRegManager(vrMan) {}
|
||||
|
||||
virtual bool assignRegisters(FastBitMatrix& interferenceMatrix) = 0;
|
||||
};
|
||||
|
||||
#endif /* _REGISTER_ASSIGNER_H_ */
|
||||
25
mozilla/ef/Compiler/RegisterAllocator/RegisterClass.h
Normal file
25
mozilla/ef/Compiler/RegisterAllocator/RegisterClass.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_CLASS_H_
|
||||
#define _REGISTER_CLASS_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "RegisterTypes.h"
|
||||
|
||||
#endif // _REGISTER_CLASS_H_
|
||||
37
mozilla/ef/Compiler/RegisterAllocator/RegisterPressure.h
Normal file
37
mozilla/ef/Compiler/RegisterAllocator/RegisterPressure.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_PRESSURE_H_
|
||||
#define _REGISTER_PRESSURE_H_
|
||||
|
||||
#include "BitSet.h"
|
||||
#include "HashSet.h"
|
||||
|
||||
struct LowRegisterPressure
|
||||
{
|
||||
typedef BitSet Set;
|
||||
static const bool setIsOrdered = true;
|
||||
};
|
||||
|
||||
struct HighRegisterPressure
|
||||
{
|
||||
typedef HashSet Set;
|
||||
static const bool setIsOrdered = false;
|
||||
};
|
||||
|
||||
#endif // _REGISTER_PRESSURE_H_
|
||||
104
mozilla/ef/Compiler/RegisterAllocator/RegisterTypes.h
Normal file
104
mozilla/ef/Compiler/RegisterAllocator/RegisterTypes.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_TYPES_H_
|
||||
#define _REGISTER_TYPES_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterName -
|
||||
//
|
||||
|
||||
enum RegisterName {
|
||||
rnInvalid = 0,
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterClassKind -
|
||||
//
|
||||
|
||||
enum RegisterClassKind {
|
||||
rckInvalid = 0,
|
||||
rckGeneral,
|
||||
rckStackSlot,
|
||||
|
||||
nRegisterClassKind
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterID -
|
||||
//
|
||||
|
||||
enum RegisterID {
|
||||
invalidID = 0
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterKind -
|
||||
//
|
||||
|
||||
enum RegisterKind {
|
||||
rkCallerSave = 0,
|
||||
rkCalleeSave,
|
||||
};
|
||||
|
||||
struct NameLinkedList {
|
||||
RegisterName name;
|
||||
NameLinkedList* next;
|
||||
};
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
const registerNameMask = 0x03ffffff;
|
||||
const coloredRegisterMask = 0x04000000;
|
||||
const machineRegisterMask = 0x08000000;
|
||||
const registerClassMask = 0xf0000000;
|
||||
|
||||
const registerNameShift = 0;
|
||||
const coloredRegisterShift = 26;
|
||||
const machineRegisterShift = 27;
|
||||
const registerClassShift = 28;
|
||||
|
||||
#else // DEBUG
|
||||
|
||||
const registerNameMask = 0x0fffffff;
|
||||
const registerClassMask = 0xf0000000;
|
||||
|
||||
const registerNameShift = 0;
|
||||
const registerClassShift = 28;
|
||||
|
||||
#endif // DEBUG
|
||||
|
||||
|
||||
inline RegisterClassKind getClass(RegisterID registerID) {return RegisterClassKind((registerID & registerClassMask) >> registerClassShift);}
|
||||
inline RegisterName getName(RegisterID registerID) {return RegisterName((registerID & registerNameMask) >> registerNameShift);}
|
||||
inline void setClass(RegisterID& registerID, RegisterClassKind classKind) {registerID = RegisterID((registerID & ~registerClassMask) | ((classKind << registerClassShift) & registerClassMask));}
|
||||
inline void setName(RegisterID& registerID, RegisterName name) {assert((name & ~registerNameMask) == 0); registerID = RegisterID((registerID & ~registerNameMask) | ((name << registerNameShift) & registerNameMask));}
|
||||
inline RegisterID buildRegisterID(RegisterName name, RegisterClassKind classKind) {return RegisterID(((classKind << registerClassShift) & registerClassMask) | ((name << registerNameShift) & registerNameMask));}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
inline bool isMachineRegister(RegisterID rid) {return (rid & machineRegisterMask) != 0;}
|
||||
inline void setMachineRegister(RegisterID& rid) {rid = RegisterID(rid | machineRegisterMask);}
|
||||
inline bool isColoredRegister(RegisterID rid) {return (rid & coloredRegisterMask) != 0;}
|
||||
inline void setColoredRegister(RegisterID& rid) {rid = RegisterID(rid | coloredRegisterMask);}
|
||||
|
||||
#endif // DEBUG
|
||||
|
||||
#endif // _REGISTER_TYPES_H_
|
||||
32
mozilla/ef/Compiler/RegisterAllocator/SSATools.cpp
Normal file
32
mozilla/ef/Compiler/RegisterAllocator/SSATools.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "SSATools.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "Liveness.h"
|
||||
|
||||
void replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager)
|
||||
{
|
||||
if (!controlGraph.hasBackEdges)
|
||||
return;
|
||||
|
||||
Liveness liveness(controlGraph.pool);
|
||||
liveness.buildLivenessAnalysis(controlGraph, vrManager);
|
||||
}
|
||||
29
mozilla/ef/Compiler/RegisterAllocator/SSATools.h
Normal file
29
mozilla/ef/Compiler/RegisterAllocator/SSATools.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _SSA_TOOLS_H_
|
||||
#define _SSA_TOOLS_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
|
||||
class ControlGraph;
|
||||
class VirtualRegisterManager;
|
||||
|
||||
extern void replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager);
|
||||
|
||||
#endif // _SSA_TOOLS_H_
|
||||
37
mozilla/ef/Compiler/RegisterAllocator/SparseSet.cpp
Normal file
37
mozilla/ef/Compiler/RegisterAllocator/SparseSet.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "SparseSet.h"
|
||||
#include "BitSet.h"
|
||||
#include "Pool.h"
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
// Print the set.
|
||||
//
|
||||
void SparseSet::printPretty(LogModuleObject log)
|
||||
{
|
||||
Pool pool;
|
||||
BitSet set(pool, universeSize);
|
||||
|
||||
for (Uint32 i = 0; i < count; i++)
|
||||
set.set(node[i].element);
|
||||
|
||||
set.printPretty(log);
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
168
mozilla/ef/Compiler/RegisterAllocator/SparseSet.h
Normal file
168
mozilla/ef/Compiler/RegisterAllocator/SparseSet.h
Normal file
@@ -0,0 +1,168 @@
|
||||
// -*- mode:C++; tab-width:4; truncate-lines:t -*-
|
||||
//
|
||||
// CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
// NETSCAPE COMMUNICATIONS CORPORATION
|
||||
// Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
// Reserved. Use of this Source Code is subject to the terms of the
|
||||
// applicable license agreement from Netscape Communications Corporation.
|
||||
// The copyright notice(s) in this Source Code does not indicate actual or
|
||||
// intended publication of this Source Code.
|
||||
//
|
||||
// $Id: SparseSet.h,v 1.1.2.1 1999-03-02 16:12:07 fur%netscape.com Exp $
|
||||
//
|
||||
|
||||
#ifndef _SPARSE_SET_H_
|
||||
#define _SPARSE_SET_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include "LogModule.h"
|
||||
#include "BitSet.h"
|
||||
|
||||
class SparseSet
|
||||
{
|
||||
private:
|
||||
|
||||
struct Node {
|
||||
Uint32 element;
|
||||
Uint32 stackIndex;
|
||||
};
|
||||
|
||||
Node* node;
|
||||
Uint32 count;
|
||||
Uint32 universeSize;
|
||||
|
||||
private:
|
||||
|
||||
// No copy constructor.
|
||||
SparseSet(const SparseSet&);
|
||||
|
||||
// Check if the given set's universe is of the same size than this universe.
|
||||
void checkUniverseCompatibility(const SparseSet& set) const {assert(set.universeSize == universeSize);}
|
||||
// Check if pos is valid for this set's universe.
|
||||
void checkMember(Int32 pos) const {assert(pos >=0 && Uint32(pos) < universeSize);}
|
||||
|
||||
public:
|
||||
|
||||
SparseSet(Pool& pool, Uint32 universeSize) : universeSize(universeSize) {node = new(pool) Node[universeSize]; clear();}
|
||||
|
||||
// Clear the sparse set.
|
||||
void clear() {count = 0;}
|
||||
// Clear the element at index.
|
||||
inline void clear(Uint32 index);
|
||||
// Set the element at index.
|
||||
inline void set(Uint32 index);
|
||||
// Return true if the element at index is set.
|
||||
inline bool test(Uint32 index) const;
|
||||
// Union with the given sparse set.
|
||||
inline void or(const SparseSet& set);
|
||||
// Intersection with the given sparse set.
|
||||
inline void and(const SparseSet& set);
|
||||
// Difference with the given sparse set.
|
||||
inline void difference(const SparseSet& set);
|
||||
// Copy set.
|
||||
inline SparseSet& operator = (const SparseSet& set);
|
||||
inline SparseSet& operator = (const BitSet& set);
|
||||
// Return true if the sparse sets are identical.
|
||||
friend bool operator == (const SparseSet& set1, const SparseSet& set2);
|
||||
// Return true if the sparse sets are different.
|
||||
friend bool operator != (const SparseSet& set1, const SparseSet& set2);
|
||||
|
||||
// Logical operators.
|
||||
SparseSet& operator |= (const SparseSet& set) {or(set); return *this;}
|
||||
SparseSet& operator &= (const SparseSet& set) {and(set); return *this;}
|
||||
SparseSet& operator -= (const SparseSet& set) {difference(set); return *this;}
|
||||
|
||||
// Iterator to conform with the set API.
|
||||
typedef Int32 iterator;
|
||||
// Return the iterator for the first element of this set.
|
||||
iterator begin() const {return count - 1;}
|
||||
// Return the next iterator.
|
||||
iterator advance(iterator pos) const {return --pos;}
|
||||
// Return true if the iterator is at the end of the set.
|
||||
bool done(iterator pos) const {return pos < 0;}
|
||||
// Return the element for the given iterator;
|
||||
Uint32 get(iterator pos) const {return node[pos].element;}
|
||||
// Return one element of this set.
|
||||
Uint32 getOne() const {assert(count > 0); return node[0].element;}
|
||||
// Return the size of this set.
|
||||
Uint32 getSize() const {return count;}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
// Print the set.
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
inline void SparseSet::clear(Uint32 element)
|
||||
{
|
||||
checkMember(element);
|
||||
Uint32 count = this->count;
|
||||
Node* node = this->node;
|
||||
|
||||
Uint32 stackIndex = node[element].stackIndex;
|
||||
|
||||
if ((stackIndex < count) && (node[stackIndex].element == element)) {
|
||||
Uint32 stackTop = node[count - 1].element;
|
||||
|
||||
node[stackIndex].element = stackTop;
|
||||
node[stackTop].stackIndex = stackIndex;
|
||||
this->count = count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline void SparseSet::set(Uint32 element)
|
||||
{
|
||||
checkMember(element);
|
||||
Uint32 count = this->count;
|
||||
Node* node = this->node;
|
||||
|
||||
Uint32 stackIndex = node[element].stackIndex;
|
||||
|
||||
if ((stackIndex >= count) || (node[stackIndex].element != element)) {
|
||||
node[count].element = element;
|
||||
node[element].stackIndex = count;
|
||||
this->count = count + 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool SparseSet::test(Uint32 element) const
|
||||
{
|
||||
checkMember(element);
|
||||
Node* node = this->node;
|
||||
|
||||
Uint32 stackIndex = node[element].stackIndex;
|
||||
return ((stackIndex < count) && (node[stackIndex].element == element));
|
||||
}
|
||||
|
||||
inline SparseSet& SparseSet::operator = (const SparseSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
Uint32 sourceCount = set.getSize();
|
||||
Node* node = this->node;
|
||||
|
||||
memcpy(node, set.node, sourceCount * sizeof(Node));
|
||||
|
||||
for (Uint32 i = 0; i < sourceCount; i++) {
|
||||
Uint32 element = node[i].element;
|
||||
node[element].stackIndex = i;
|
||||
}
|
||||
|
||||
count = sourceCount;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline SparseSet& SparseSet::operator = (const BitSet& set)
|
||||
{
|
||||
// FIX: there's room for optimization here.
|
||||
assert(universeSize == set.getSize());
|
||||
|
||||
clear();
|
||||
for (Int32 i = set.firstOne(); i != -1; i = set.nextOne(i))
|
||||
this->set(i);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif // _SPARSE_SET_H_
|
||||
270
mozilla/ef/Compiler/RegisterAllocator/Spilling.cpp
Normal file
270
mozilla/ef/Compiler/RegisterAllocator/Spilling.cpp
Normal file
@@ -0,0 +1,270 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef NEW_LAURENTM_CODE
|
||||
#define INCLUDE_EMITTER
|
||||
#include "CpuInfo.h"
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "InstructionEmitter.h"
|
||||
#include "Spilling.h"
|
||||
|
||||
|
||||
void Spilling::
|
||||
insertSpillCode(ControlNode** dfsList, Uint32 nNodes)
|
||||
{
|
||||
PRUint32 nVirtualRegisters = vRegManager.count();
|
||||
FastBitSet currentLive(vRegManager.pool, nVirtualRegisters);
|
||||
FastBitSet usedInThisInstruction(vRegManager.pool, nVirtualRegisters);
|
||||
RegisterFifo grNeedLoad(nVirtualRegisters);
|
||||
RegisterFifo fpNeedLoad(nVirtualRegisters);
|
||||
|
||||
for (PRInt32 n = nNodes - 1; n >= 0; n--)
|
||||
{
|
||||
PR_ASSERT(grNeedLoad.empty() & fpNeedLoad.empty());
|
||||
ControlNode& node = *dfsList[n];
|
||||
|
||||
currentLive = node.liveAtEnd;
|
||||
|
||||
PRUint32 nGeneralAlive = 0;
|
||||
PRUint32 nFloatingPointAlive = 0;
|
||||
|
||||
// Get the number of registers alive at the end of this node.
|
||||
for (PRInt32 j = currentLive.firstOne(); j != -1; j = currentLive.nextOne(j))
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(j);
|
||||
if (vReg.spillInfo.willSpill)
|
||||
{
|
||||
currentLive.clear(j);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
nGeneralAlive++;
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
nFloatingPointAlive++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if(node.dfsNum == 8) printf("\n________Begin Node %d________\n", node.dfsNum);
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i))
|
||||
{
|
||||
Instruction& instruction = instructions.get(i);
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* defPtr;
|
||||
|
||||
// if(node.dfsNum == 8) { printf("\n");
|
||||
// instruction.printPretty(stdout);
|
||||
// printf("\n"); }
|
||||
|
||||
// Handle definitions
|
||||
for (defPtr = defBegin; defPtr < defEnd; defPtr++)
|
||||
if (defPtr->isVirtualRegister())
|
||||
{
|
||||
VirtualRegister& vReg = defPtr->getVirtualRegister();
|
||||
currentLive.clear(vReg.getRegisterIndex());
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
nGeneralAlive--;
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
nFloatingPointAlive--;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for deaths
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isVirtualRegister())
|
||||
{
|
||||
VirtualRegister& vReg = usePtr->getVirtualRegister();
|
||||
if (!currentLive.test(vReg.getRegisterIndex()))
|
||||
// This is the last use of this register.
|
||||
{
|
||||
currentLive.set(vReg.getRegisterIndex());
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
nGeneralAlive++;
|
||||
while (/*(nGeneralAlive > NUMBER_OF_GREGISTERS) &&*/ !grNeedLoad.empty())
|
||||
{
|
||||
PRUint32 toLoad = grNeedLoad.get();
|
||||
currentLive.clear(toLoad);
|
||||
nGeneralAlive--;
|
||||
|
||||
VirtualRegister& nReg = vRegManager.getVirtualRegister(toLoad);
|
||||
Instruction& lastUsingInstruction = *nReg.spillInfo.lastUsingInstruction;
|
||||
emitter.emitLoadAfter(*lastUsingInstruction.getPrimitive(), lastUsingInstruction.getLinks().prev,
|
||||
nReg.getAlias(), *nReg.equivalentRegister[vrcStackSlot]);
|
||||
nReg.releaseSelf();
|
||||
}
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
nFloatingPointAlive++;
|
||||
while (/*(nFloatingPointAlive > NUMBER_OF_FPREGISTERS) &&*/ !fpNeedLoad.empty())
|
||||
{
|
||||
PRUint32 toLoad = fpNeedLoad.get();
|
||||
currentLive.clear(toLoad);
|
||||
nFloatingPointAlive--;
|
||||
|
||||
VirtualRegister& nReg = vRegManager.getVirtualRegister(toLoad);
|
||||
Instruction& lastUsingInstruction = *nReg.spillInfo.lastUsingInstruction;
|
||||
emitter.emitLoadAfter(*lastUsingInstruction.getPrimitive(), lastUsingInstruction.getLinks().prev,
|
||||
nReg.getAlias(), *nReg.equivalentRegister[vrcStackSlot]);
|
||||
nReg.releaseSelf();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle uses
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isVirtualRegister())
|
||||
{
|
||||
VirtualRegister& vReg = usePtr->getVirtualRegister();
|
||||
PRUint32 registerIndex = vReg.getRegisterIndex();
|
||||
|
||||
if (vReg.spillInfo.willSpill) {
|
||||
#if defined(GENERATE_FOR_X86)
|
||||
if (!instruction.switchUseToSpill((usePtr - useBegin), *vReg.equivalentRegister[vrcStackSlot]))
|
||||
#endif
|
||||
{
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
if (!grNeedLoad.test(registerIndex))
|
||||
{
|
||||
grNeedLoad.put(registerIndex);
|
||||
VirtualRegister& alias = vRegManager.newVirtualRegister(vrcInteger);
|
||||
if (vReg.isPreColored())
|
||||
alias.preColorRegister(vReg.getPreColor());
|
||||
/* if (vReg.hasSpecialInterference) {
|
||||
alias.specialInterference.sizeTo(NUMBER_OF_REGISTERS);
|
||||
alias.specialInterference = vReg.specialInterference;
|
||||
alias.hasSpecialInterference = true;
|
||||
} */
|
||||
vReg.setAlias(alias);
|
||||
vReg.retainSelf();
|
||||
}
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
if (!fpNeedLoad.test(registerIndex))
|
||||
{
|
||||
fpNeedLoad.put(registerIndex);
|
||||
VirtualRegister& alias = vRegManager.newVirtualRegister(vReg.getClass());
|
||||
if (vReg.isPreColored())
|
||||
alias.preColorRegister(vReg.getPreColor());
|
||||
/*if (vReg.hasSpecialInterference) {
|
||||
alias.specialInterference.sizeTo(NUMBER_OF_REGISTERS);
|
||||
alias.specialInterference = vReg.specialInterference;
|
||||
alias.hasSpecialInterference = true;
|
||||
} */
|
||||
vReg.setAlias(alias);
|
||||
vReg.retainSelf();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
usePtr->getVirtualRegisterPtr().initialize(vReg.getAlias());
|
||||
usedInThisInstruction.set(registerIndex);
|
||||
vReg.spillInfo.lastUsingInstruction = &instruction;
|
||||
}
|
||||
currentLive.clear(registerIndex);
|
||||
} else { // will not spill
|
||||
currentLive.set(registerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle definitions
|
||||
for (defPtr = defBegin; defPtr < defEnd; defPtr++)
|
||||
if (defPtr->isVirtualRegister())
|
||||
{
|
||||
VirtualRegister& vReg = defPtr->getVirtualRegister();
|
||||
|
||||
if (vReg.spillInfo.willSpill)
|
||||
#if defined(GENERATE_FOR_X86)
|
||||
if (!instruction.switchDefineToSpill((defPtr - defBegin), *vReg.equivalentRegister[vrcStackSlot]))
|
||||
#endif
|
||||
{
|
||||
if (usedInThisInstruction.test(vReg.getRegisterIndex()))
|
||||
// this virtualRegister was used in this instruction and is also defined. We need to move
|
||||
// this virtual register to its alias first and then save it to memory.
|
||||
{
|
||||
emitter.emitStoreAfter(*instruction.getPrimitive(), &instruction.getLinks(),
|
||||
vReg.getAlias(), *vReg.equivalentRegister[vrcStackSlot]);
|
||||
defPtr->getVirtualRegisterPtr().initialize(vReg.getAlias());
|
||||
}
|
||||
else
|
||||
{
|
||||
emitter.emitStoreAfter(*instruction.getPrimitive(), &instruction.getLinks(),
|
||||
vReg, *vReg.equivalentRegister[vrcStackSlot]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!grNeedLoad.empty())
|
||||
{
|
||||
PRUint32 nl = grNeedLoad.get();
|
||||
VirtualRegister& nlReg = vRegManager.getVirtualRegister(nl);
|
||||
Instruction& lastUse = *nlReg.spillInfo.lastUsingInstruction;
|
||||
|
||||
emitter.emitLoadAfter(*lastUse.getPrimitive(), lastUse.getLinks().prev,
|
||||
nlReg.getAlias(), *nlReg.equivalentRegister[vrcStackSlot]);
|
||||
nlReg.releaseSelf();
|
||||
}
|
||||
while (!fpNeedLoad.empty())
|
||||
{
|
||||
PRUint32 nl = fpNeedLoad.get();
|
||||
VirtualRegister& nlReg = vRegManager.getVirtualRegister(nl);
|
||||
Instruction& lastUse = *nlReg.spillInfo.lastUsingInstruction;
|
||||
|
||||
emitter.emitLoadAfter(*lastUse.getPrimitive(), lastUse.getLinks().prev,
|
||||
nlReg.getAlias(), *nlReg.equivalentRegister[vrcStackSlot]);
|
||||
nlReg.releaseSelf();
|
||||
}
|
||||
|
||||
// if(node.dfsNum == 8) printf("\n________End Node %d________\n", node.dfsNum);
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
269
mozilla/ef/Compiler/RegisterAllocator/Spilling.h
Normal file
269
mozilla/ef/Compiler/RegisterAllocator/Spilling.h
Normal file
@@ -0,0 +1,269 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _SPILLING_H_
|
||||
#define _SPILLING_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include <string.h>
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "SparseSet.h"
|
||||
|
||||
template <class RegisterPressure>
|
||||
class Spilling
|
||||
{
|
||||
private:
|
||||
static void insertStoreAfter(Instruction& instruction, RegisterName name);
|
||||
static void insertLoadBefore(Instruction& instruction, RegisterName name);
|
||||
|
||||
public:
|
||||
static void calculateSpillCosts(RegisterAllocator& registerAllocator);
|
||||
static void insertSpillCode(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
struct SpillCost
|
||||
{
|
||||
double loads;
|
||||
double stores;
|
||||
double copies;
|
||||
double cost;
|
||||
bool infinite;
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Spilling<RegisterPressure>::insertSpillCode(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
Pool& pool = registerAllocator.pool;
|
||||
SparseSet currentLive(pool, rangeCount);
|
||||
SparseSet needLoad(pool, rangeCount);
|
||||
SparseSet mustSpill(pool, rangeCount);
|
||||
SparseSet& willSpill = *registerAllocator.willSpill;
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
RegisterPressure::Set* liveOut = registerAllocator.liveness.liveOut;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
|
||||
needLoad.clear();
|
||||
currentLive = liveOut[n];
|
||||
mustSpill = currentLive;
|
||||
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i);) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
i = instructions.retreat(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
bool foundLiveDefine = false;
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
if (currentLive.test(name2range[definePtr->getRegisterName()])) {
|
||||
foundLiveDefine = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
foundLiveDefine = true;
|
||||
break;
|
||||
}
|
||||
if (defineBegin != defineEnd && !foundLiveDefine) {
|
||||
fprintf(stderr, "!!! Removed instruction because it was only defining unused registers !!!\n");
|
||||
instruction.remove();
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName range = name2range[definePtr->getRegisterName()];
|
||||
#ifdef DEBUG
|
||||
if (needLoad.test(range))
|
||||
if (!mustSpill.test(range) && registerAllocator.spillCost[range].infinite && willSpill.test(range)) {
|
||||
fprintf(stderr, "Tried to spill a register with infinite spill cost\n");
|
||||
abort();
|
||||
}
|
||||
#endif // DEBUG
|
||||
if (willSpill.test(range))
|
||||
insertStoreAfter(instruction, range);
|
||||
|
||||
needLoad.clear(range);
|
||||
}
|
||||
|
||||
if (instruction.getFlags() & ifCopy)
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName range = name2range[usePtr->getRegisterName()];
|
||||
if (!currentLive.test(range))
|
||||
for (SparseSet::iterator r = needLoad.begin(); !needLoad.done(r); r = needLoad.advance(r)) {
|
||||
RegisterName load = RegisterName(needLoad.get(r));
|
||||
if (willSpill.test(load))
|
||||
insertLoadBefore(instruction, load);
|
||||
mustSpill.set(load);
|
||||
}
|
||||
needLoad.clear();
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentLive.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName range = name2range[usePtr->getRegisterName()];
|
||||
currentLive.set(range);
|
||||
needLoad.set(range);
|
||||
}
|
||||
}
|
||||
|
||||
for (SparseSet::iterator l = needLoad.begin(); !needLoad.done(l); l = needLoad.advance(l)) {
|
||||
RegisterName load = RegisterName(needLoad.get(l));
|
||||
if (willSpill.test(load))
|
||||
insertLoadBefore(instructions.first(), load);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Spilling<RegisterPressure>::insertLoadBefore(Instruction& /*instruction*/, RegisterName name)
|
||||
{
|
||||
fprintf(stdout, "will insert load for range %d\n", name);
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Spilling<RegisterPressure>::insertStoreAfter(Instruction& /*instruction*/, RegisterName name)
|
||||
{
|
||||
fprintf(stdout, "will insert store for range %d\n", name);
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Spilling<RegisterPressure>::calculateSpillCosts(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
Pool& pool = registerAllocator.pool;
|
||||
SparseSet live(pool, rangeCount);
|
||||
SparseSet needLoad(pool, rangeCount);
|
||||
SparseSet mustSpill(pool, rangeCount);
|
||||
|
||||
SparseSet alreadyStored(pool, rangeCount); // FIX: should get this from previous spilling.
|
||||
|
||||
SpillCost* cost = new SpillCost[rangeCount];
|
||||
memset(cost, '\0', rangeCount * sizeof(SpillCost));
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
RegisterPressure::Set* liveOut = registerAllocator.liveness.liveOut;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
double weight = doLog10(node.loopDepth);
|
||||
|
||||
needLoad.clear();
|
||||
live = liveOut[n];
|
||||
mustSpill = live;
|
||||
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName range = name2range[definePtr->getRegisterName()];
|
||||
|
||||
if (needLoad.test(range))
|
||||
if (!mustSpill.test(range))
|
||||
cost[range].infinite = true;
|
||||
|
||||
if ((false /* !rematerializable(range) */ || !needLoad.test(range)) && !alreadyStored.test(range))
|
||||
cost[range].stores += weight;
|
||||
|
||||
needLoad.clear(range);
|
||||
}
|
||||
|
||||
if (instruction.getFlags() & ifCopy)
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
if (!live.test(name2range[usePtr->getRegisterName()])) {
|
||||
for (SparseSet::iterator l = needLoad.begin(); !needLoad.done(l); l = needLoad.advance(l)) {
|
||||
Uint32 range = needLoad.get(l);
|
||||
cost[range].loads += weight;
|
||||
mustSpill.set(range);
|
||||
}
|
||||
needLoad.clear();
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
live.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName range = name2range[usePtr->getRegisterName()];
|
||||
|
||||
live.set(range);
|
||||
needLoad.set(range);
|
||||
}
|
||||
|
||||
if (instruction.getFlags() & ifCopy) {
|
||||
assert(useBegin != useEnd && useBegin[0].isRegister());
|
||||
assert(defineBegin != defineEnd && defineBegin[0].isRegister());
|
||||
|
||||
RegisterName source = name2range[useBegin[0].getRegisterName()];
|
||||
RegisterName destination = name2range[defineBegin[0].getRegisterName()];
|
||||
|
||||
cost[source].copies += weight;
|
||||
cost[destination].copies += weight;
|
||||
}
|
||||
}
|
||||
|
||||
for (SparseSet::iterator s = needLoad.begin(); !needLoad.done(s); s = needLoad.advance(s))
|
||||
cost[needLoad.get(s)].loads += weight;
|
||||
}
|
||||
|
||||
for (Uint32 r = 0; r < rangeCount; r++) {
|
||||
SpillCost& c = cost[r];
|
||||
c.cost = 2 * (c.loads + c.stores) - c.copies;
|
||||
}
|
||||
|
||||
registerAllocator.spillCost = cost;
|
||||
}
|
||||
|
||||
#endif // _SPILLING_H_
|
||||
239
mozilla/ef/Compiler/RegisterAllocator/Splits.h
Normal file
239
mozilla/ef/Compiler/RegisterAllocator/Splits.h
Normal file
@@ -0,0 +1,239 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _SPLITS_H_
|
||||
#define _SPLITS_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include <string.h>
|
||||
#include "Pool.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
|
||||
UT_EXTERN_LOG_MODULE(RegAlloc);
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct Splits
|
||||
{
|
||||
static void calculateSplitCosts(RegisterAllocator& registerAllocator);
|
||||
static bool findSplit(RegisterAllocator& registerAllocator, RegisterName* color, RegisterName range);
|
||||
static void insertSplitCode(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
struct SplitCost
|
||||
{
|
||||
double loads;
|
||||
double stores;
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Splits<RegisterPressure>::insertSplitCode(RegisterAllocator& /*registerAllocator*/)
|
||||
{
|
||||
// FIX
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool Splits<RegisterPressure>::findSplit(RegisterAllocator& registerAllocator, RegisterName* color, RegisterName range)
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
NameLinkedList** neighborsWithColor = new(pool) NameLinkedList*[6]; // FIX
|
||||
memset(neighborsWithColor, '\0', 6 * sizeof(NameLinkedList*));
|
||||
|
||||
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
|
||||
|
||||
for (InterferenceVector* vector = iGraph.getInterferenceVector(range); vector != NULL; vector = vector->next)
|
||||
for (Int32 i = vector->count - 1; i >=0; --i) {
|
||||
RegisterName neighbor = vector->neighbors[i];
|
||||
RegisterName c = color[neighbor];
|
||||
|
||||
if (c < 6) { // FIX
|
||||
NameLinkedList* node = new(pool) NameLinkedList();
|
||||
node->name = neighbor;
|
||||
node->next = neighborsWithColor[c];
|
||||
neighborsWithColor[c] = node;
|
||||
}
|
||||
}
|
||||
|
||||
bool splitAroundName = true;
|
||||
|
||||
LiveRangeGraph<RegisterPressure>& lGraph = registerAllocator.lGraph;
|
||||
RegisterName bestColor = RegisterName(6); // FIX
|
||||
double bestCost = registerAllocator.spillCost[range].cost;
|
||||
SplitCost* splitCost = registerAllocator.splitCost;
|
||||
|
||||
for (RegisterName i = RegisterName(0); i < 6; i = RegisterName(i + 1)) { // FIX
|
||||
|
||||
double splitAroundNameCost = 0.0;
|
||||
bool canSplitAroundName = true;
|
||||
|
||||
SplitCost& sCost = splitCost[range];
|
||||
double addedCost = 2.0 * (sCost.stores + sCost.loads);
|
||||
|
||||
for (NameLinkedList* node = neighborsWithColor[i]; node != NULL; node = node->next) {
|
||||
RegisterName neighbor = node->name;
|
||||
if (lGraph.haveEdge(neighbor, range)) {
|
||||
canSplitAroundName = false;
|
||||
break;
|
||||
} else
|
||||
splitAroundNameCost += addedCost;
|
||||
}
|
||||
if (canSplitAroundName && splitAroundNameCost < bestCost) {
|
||||
bestCost = splitAroundNameCost;
|
||||
bestColor = i;
|
||||
splitAroundName = true;
|
||||
}
|
||||
|
||||
double splitAroundColorCost = 0.0;
|
||||
bool canSplitAroundColor = true;
|
||||
|
||||
for (NameLinkedList* node = neighborsWithColor[i]; node != NULL; node = node->next) {
|
||||
RegisterName neighbor = node->name;
|
||||
if (lGraph.haveEdge(range, neighbor)) {
|
||||
canSplitAroundColor = false;
|
||||
break;
|
||||
} else {
|
||||
SplitCost& sCost = splitCost[neighbor];
|
||||
double addedCost = 2.0 * (sCost.stores + sCost.loads);
|
||||
splitAroundColorCost += addedCost;
|
||||
}
|
||||
}
|
||||
if (canSplitAroundColor && splitAroundColorCost < bestCost) {
|
||||
bestCost = splitAroundColorCost;
|
||||
bestColor = i;
|
||||
splitAroundName = false;
|
||||
}
|
||||
}
|
||||
if (bestColor < RegisterName(6)) {
|
||||
color[range] = bestColor;
|
||||
registerAllocator.splitFound = true;
|
||||
|
||||
NameLinkedList** splitAround = registerAllocator.splitAround;
|
||||
|
||||
if (splitAroundName)
|
||||
for (NameLinkedList* node = neighborsWithColor[bestColor]; node != NULL; node = node->next) {
|
||||
NameLinkedList* newNode = new(pool) NameLinkedList();
|
||||
newNode->name = node->name;
|
||||
newNode->next = splitAround[range];
|
||||
splitAround[range] = newNode;
|
||||
}
|
||||
else
|
||||
for (NameLinkedList* node = neighborsWithColor[bestColor]; node != NULL; node = node->next) {
|
||||
NameLinkedList* newNode = new(pool) NameLinkedList();
|
||||
RegisterName neighbor = node->name;
|
||||
newNode->name = range;
|
||||
newNode->next = splitAround[neighbor];
|
||||
splitAround[neighbor] = newNode;
|
||||
}
|
||||
|
||||
trespass("Found a split");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Splits<RegisterPressure>::calculateSplitCosts(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
SplitCost* splitCost = new(pool) SplitCost[rangeCount];
|
||||
memset(splitCost, '\0', rangeCount * sizeof(SplitCost));
|
||||
|
||||
SparseSet live(pool, rangeCount);
|
||||
RegisterPressure::Set* liveIn = registerAllocator.liveness.liveIn;
|
||||
RegisterPressure::Set* liveOut = registerAllocator.liveness.liveOut;
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
double weight = doLog10(node.loopDepth);
|
||||
|
||||
live = liveOut[n];
|
||||
|
||||
ControlEdge* successorsEnd = node.getSuccessorsEnd();
|
||||
for (ControlEdge* successorsPtr = node.getSuccessorsBegin(); successorsPtr < successorsEnd; successorsPtr++) {
|
||||
ControlNode& successor = successorsPtr->getTarget();
|
||||
|
||||
if (successor.getControlKind() != ckEnd) {
|
||||
RegisterPressure::Set& successorLiveIn = liveIn[successor.dfsNum];
|
||||
|
||||
for (SparseSet::iterator i = live.begin(); !live.done(i); i = live.advance(i)) {
|
||||
RegisterName name = RegisterName(live.get(i));
|
||||
if (!successorLiveIn.test(name))
|
||||
splitCost[name].loads += doLog10(successor.loopDepth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
splitCost[name2range[definePtr->getRegisterName()]].stores += weight;
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName range = name2range[usePtr->getRegisterName()];
|
||||
if (!live.test(range)) {
|
||||
if (&instruction != &instructions.last())
|
||||
splitCost[range].loads += weight;
|
||||
else {
|
||||
ControlEdge* successorsEnd = node.getSuccessorsEnd();
|
||||
for (ControlEdge* successorsPtr = node.getSuccessorsBegin(); successorsPtr < successorsEnd; successorsPtr++)
|
||||
splitCost[range].loads += doLog10(successorsPtr->getTarget().loopDepth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
live.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
live.set(name2range[usePtr->getRegisterName()]);
|
||||
}
|
||||
}
|
||||
|
||||
NameLinkedList** splitAround = new(pool) NameLinkedList*[rangeCount];
|
||||
memset(splitAround, '\0', rangeCount * sizeof(NameLinkedList*));
|
||||
registerAllocator.splitAround = splitAround;
|
||||
|
||||
registerAllocator.splitCost = splitCost;
|
||||
registerAllocator.splitFound = false;
|
||||
}
|
||||
|
||||
#endif // _SPLITS_H_
|
||||
186
mozilla/ef/Compiler/RegisterAllocator/Timer.cpp
Normal file
186
mozilla/ef/Compiler/RegisterAllocator/Timer.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "HashTable.h"
|
||||
#include "Timer.h"
|
||||
#include "Pool.h"
|
||||
|
||||
static Pool pool; // Pool for the Timer class.
|
||||
static HashTable<TimerEntry*> timerEntries(pool); // Timers hashtable.
|
||||
|
||||
const nTimersInABlock = 128; // Number of timers in a block.
|
||||
static PRTime *timers = new(pool) PRTime[nTimersInABlock]; // A block of timers.
|
||||
static Uint8 nextTimer = 0; // nextAvailableTimer.
|
||||
|
||||
//
|
||||
// Calibrate the call to PR_Now().
|
||||
//
|
||||
static PRTime calibrate()
|
||||
{
|
||||
PRTime t = PR_Now();
|
||||
PRTime& a = *new(pool) PRTime();
|
||||
|
||||
// Call 10 times the PR_Now() function.
|
||||
a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now();
|
||||
a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now();
|
||||
t = (PR_Now() - t + 9) / 10;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
static PRTime adjust = calibrate();
|
||||
|
||||
//
|
||||
// Return the named timer..
|
||||
//
|
||||
TimerEntry& Timer::getTimerEntry(const char* name)
|
||||
{
|
||||
if (!timerEntries.exists(name)) {
|
||||
TimerEntry* newEntry = new(pool) TimerEntry();
|
||||
newEntry->accumulator = 0;
|
||||
newEntry->running = false;
|
||||
timerEntries.add(name, newEntry);
|
||||
}
|
||||
|
||||
return *timerEntries[name];
|
||||
}
|
||||
|
||||
//
|
||||
// Return a reference to a new timer.
|
||||
//
|
||||
PRTime& Timer::getNewTimer()
|
||||
{
|
||||
if (nextTimer >= nTimersInABlock) {
|
||||
timers = new(pool) PRTime[nTimersInABlock];
|
||||
nextTimer = 0;
|
||||
}
|
||||
return timers[nextTimer++];
|
||||
}
|
||||
|
||||
static Uint32 timersAreFrozen = 0;
|
||||
|
||||
//
|
||||
// Start the named timer.
|
||||
//
|
||||
void Timer::start(const char* name)
|
||||
{
|
||||
if (timersAreFrozen)
|
||||
return;
|
||||
|
||||
freezeTimers();
|
||||
|
||||
TimerEntry& timer = getTimerEntry(name);
|
||||
PR_ASSERT(!timer.running);
|
||||
|
||||
timer.accumulator = 0;
|
||||
timer.running = true;
|
||||
timer.done = false;
|
||||
|
||||
unfreezeTimers();
|
||||
}
|
||||
|
||||
//
|
||||
// Stop the named timer.
|
||||
//
|
||||
void Timer::stop(const char* name)
|
||||
{
|
||||
if (timersAreFrozen)
|
||||
return;
|
||||
|
||||
freezeTimers();
|
||||
|
||||
TimerEntry& timer = getTimerEntry(name);
|
||||
PR_ASSERT(timer.running);
|
||||
timer.running = false;
|
||||
timer.done = true;
|
||||
|
||||
unfreezeTimers();
|
||||
}
|
||||
|
||||
//
|
||||
// Freeze all the running timers.
|
||||
//
|
||||
void Timer::freezeTimers()
|
||||
{
|
||||
PRTime when = PR_Now() - adjust;
|
||||
|
||||
if (timersAreFrozen == 0) {
|
||||
Vector<TimerEntry*> entries = timerEntries;
|
||||
Uint32 count = entries.size();
|
||||
|
||||
for (Uint32 i = 0; i < count; i++) {
|
||||
TimerEntry& entry = *entries[i];
|
||||
if (entry.running) {
|
||||
entry.accumulator += (when - *entry.startTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
timersAreFrozen++;
|
||||
}
|
||||
|
||||
//
|
||||
// Unfreeze all the running timers.
|
||||
//
|
||||
void Timer::unfreezeTimers()
|
||||
{
|
||||
PR_ASSERT(timersAreFrozen != 0);
|
||||
timersAreFrozen--;
|
||||
|
||||
if (timersAreFrozen == 0) {
|
||||
Vector<TimerEntry *> entries = timerEntries;
|
||||
Uint32 count = entries.size();
|
||||
|
||||
PRTime& newStart = getNewTimer();
|
||||
|
||||
for (Uint32 i = 0; i < count; i++) {
|
||||
TimerEntry& entry = *entries[i];
|
||||
if (entry.running) {
|
||||
entry.startTime = &newStart;
|
||||
}
|
||||
}
|
||||
|
||||
newStart = PR_Now();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Print the named timer in the file f.
|
||||
//
|
||||
void Timer::print(FILE* f, const char *name)
|
||||
{
|
||||
if (timersAreFrozen)
|
||||
return;
|
||||
|
||||
freezeTimers();
|
||||
|
||||
TimerEntry& timer = getTimerEntry(name);
|
||||
|
||||
PR_ASSERT(timer.done);
|
||||
PRTime elapsed = timer.accumulator;
|
||||
|
||||
if (elapsed >> 32) {
|
||||
fprintf(f, "[timer %s out of range]\n", name);
|
||||
} else {
|
||||
fprintf(f, "[%dus in %s]\n", Uint32(elapsed), name);
|
||||
}
|
||||
fflush(f);
|
||||
|
||||
unfreezeTimers();
|
||||
}
|
||||
|
||||
80
mozilla/ef/Compiler/RegisterAllocator/Timer.h
Normal file
80
mozilla/ef/Compiler/RegisterAllocator/Timer.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _TIMER_H_
|
||||
#define _TIMER_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "HashTable.h"
|
||||
#include "prtime.h"
|
||||
|
||||
//
|
||||
// Naming convention:
|
||||
// As the class Timer contains only static methods, the timer's name should start with the
|
||||
// module name. Otherwise starting 2 timers with the same name will assert.
|
||||
//
|
||||
|
||||
#ifndef NO_TIMER
|
||||
|
||||
struct TimerEntry
|
||||
{
|
||||
PRTime *startTime; // Current time when we start the timer.
|
||||
PRTime accumulator; // Time spent in this timer.
|
||||
bool running; // True if the timer is running.
|
||||
bool done; // True if the timer was running and was stopped.
|
||||
};
|
||||
|
||||
class Timer
|
||||
{
|
||||
private:
|
||||
|
||||
// Return the named timer.
|
||||
static TimerEntry& getTimerEntry(const char* name);
|
||||
// Return a reference to a new Timer.
|
||||
static PRTime& getNewTimer();
|
||||
|
||||
public:
|
||||
|
||||
// Start the timer.
|
||||
static void start(const char* name);
|
||||
// Stop the timer.
|
||||
static void stop(const char* name);
|
||||
// Freeze all the running timers.
|
||||
static void freezeTimers();
|
||||
// Unfreeze all the running timers.
|
||||
static void unfreezeTimers();
|
||||
// Print the timer.
|
||||
static void print(FILE* f, const char *name);
|
||||
};
|
||||
|
||||
inline void startTimer(const char* name) {Timer::start(name);}
|
||||
inline void stopTimer(const char* name) {Timer::stop(name); Timer::print(stdout, name);}
|
||||
#define START_TIMER_SAFE Timer::freezeTimers();
|
||||
#define END_TIMER_SAFE Timer::unfreezeTimers();
|
||||
#define TIMER_SAFE(x) START_TIMER_SAFE x; END_TIMER_SAFE
|
||||
|
||||
#else /* NO_TIMER */
|
||||
|
||||
inline void startTimer(const char* /*name*/) {}
|
||||
inline void stopTimer(const char* /*name*/) {}
|
||||
#define START_TIMER_SAFE
|
||||
#define END_TIMER_SAFE
|
||||
#define TIMER_SAFE(x) x;
|
||||
|
||||
#endif /* NO_TIMER */
|
||||
#endif /* _TIMER_H_ */
|
||||
40
mozilla/ef/Compiler/RegisterAllocator/VirtualRegister.cpp
Normal file
40
mozilla/ef/Compiler/RegisterAllocator/VirtualRegister.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "Instruction.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VirtualRegister -
|
||||
|
||||
#ifdef MANUAL_TEMPLATES
|
||||
template class IndexedPool<VirtualRegister>;
|
||||
#endif
|
||||
|
||||
// Set the defining instruction.
|
||||
//
|
||||
void VirtualRegister::setDefiningInstruction(Instruction& instruction)
|
||||
{
|
||||
if (definingInstruction != NULL) {
|
||||
if ((instruction.getFlags() & ifCopy) && (definingInstruction->getFlags() & ifPhiNode))
|
||||
return;
|
||||
}
|
||||
definingInstruction = &instruction;
|
||||
}
|
||||
|
||||
116
mozilla/ef/Compiler/RegisterAllocator/VirtualRegister.h
Normal file
116
mozilla/ef/Compiler/RegisterAllocator/VirtualRegister.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _VIRTUAL_REGISTER_H_
|
||||
#define _VIRTUAL_REGISTER_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "IndexedPool.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "RegisterTypes.h"
|
||||
#include "RegisterClass.h"
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VirtualRegister - 24b
|
||||
|
||||
class Instruction;
|
||||
|
||||
class VirtualRegister : public IndexedObject<VirtualRegister>
|
||||
{
|
||||
public:
|
||||
|
||||
Instruction* definingInstruction; // Instruction defining this VR.
|
||||
|
||||
// Initialize a VR of the given classKind.
|
||||
VirtualRegister(RegisterClassKind /*classKind*/) : definingInstruction(NULL) {}
|
||||
|
||||
// Return the defining instruction for this VR.
|
||||
Instruction* getDefiningInstruction() const {return definingInstruction;}
|
||||
// Set the defining instruction.
|
||||
void setDefiningInstruction(Instruction& insn);
|
||||
};
|
||||
|
||||
// Return true if the VirtualRegisters are equals. The only way 2 VRs can be equal is if
|
||||
// they have the same index. If they have the same index then they are at the same
|
||||
// address in the indexed pool.
|
||||
//
|
||||
inline bool operator == (const VirtualRegister& regA, const VirtualRegister& regB) {return ®A == ®B;}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VirtualRegisterManager -
|
||||
|
||||
struct PreColoredRegister
|
||||
{
|
||||
RegisterID id;
|
||||
RegisterName color;
|
||||
};
|
||||
|
||||
class VirtualRegisterManager
|
||||
{
|
||||
private:
|
||||
|
||||
IndexedPool<VirtualRegister> registerPool;
|
||||
PreColoredRegister machineRegister[6];
|
||||
|
||||
public:
|
||||
VirtualRegisterManager()
|
||||
{
|
||||
for (Uint32 i = 0; i < 6; i++)
|
||||
machineRegister[i].id = invalidID;
|
||||
}
|
||||
|
||||
// Return the VirtualRegister at the given index.
|
||||
VirtualRegister& getVirtualRegister(RegisterName name) const {return registerPool.get(name);}
|
||||
|
||||
// Return a new VirtualRegister.
|
||||
RegisterID newVirtualRegister(RegisterClassKind classKind)
|
||||
{
|
||||
VirtualRegister& vReg = *new(registerPool) VirtualRegister(classKind);
|
||||
RegisterID rid;
|
||||
|
||||
setName(rid, RegisterName(vReg.getIndex()));
|
||||
setClass(rid, classKind);
|
||||
return rid;
|
||||
}
|
||||
|
||||
RegisterID newMachineRegister(RegisterName name, RegisterClassKind classKind)
|
||||
{
|
||||
RegisterID rid = machineRegister[name].id;
|
||||
|
||||
if (rid == invalidID) {
|
||||
rid = newVirtualRegister(classKind);
|
||||
DEBUG_ONLY(setMachineRegister(rid));
|
||||
machineRegister[name].id = rid;
|
||||
machineRegister[name].color = name;
|
||||
}
|
||||
|
||||
return rid;
|
||||
}
|
||||
|
||||
PreColoredRegister* getMachineRegistersBegin() const {return (PreColoredRegister*) machineRegister;} // FIX
|
||||
PreColoredRegister* getMachineRegistersEnd() const {return (PreColoredRegister*) &machineRegister[6];} // FIX
|
||||
|
||||
// Return the VirtualRegister universe size.
|
||||
Uint32 getSize() {return registerPool.getSize();}
|
||||
|
||||
void setSize(Uint32 size) {registerPool.setSize(size);}
|
||||
};
|
||||
|
||||
#endif // _VIRTUAL_REGISTER_H_
|
||||
6
mozilla/netwerk/cache/public/MANIFEST
vendored
6
mozilla/netwerk/cache/public/MANIFEST
vendored
@@ -1,6 +0,0 @@
|
||||
nsICachedNetData.idl
|
||||
nsINetDataCache.idl
|
||||
nsINetDataCacheManager.idl
|
||||
nsINetDataCacheRecord.idl
|
||||
nsINetDataDiskCache.idl
|
||||
nsIStreamAsFile.idl
|
||||
60
mozilla/netwerk/cache/public/Makefile.in
vendored
60
mozilla/netwerk/cache/public/Makefile.in
vendored
@@ -1,60 +0,0 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
MODULE = nkcache
|
||||
XPIDL_MODULE = necko_cache
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
XPIDLSRCS = $(NULL)
|
||||
|
||||
ifdef OLD_CACHE
|
||||
XPIDLSRCS += \
|
||||
nsICachedNetData.idl \
|
||||
nsINetDataCacheManager.idl \
|
||||
nsINetDataCache.idl \
|
||||
nsINetDataCacheRecord.idl \
|
||||
nsINetDataDiskCache.idl \
|
||||
nsIStreamAsFile.idl \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
|
||||
ifdef MOZ_NEW_CACHE
|
||||
XPIDLSRCS += \
|
||||
nsICache.idl \
|
||||
nsICacheEntryDescriptor.idl \
|
||||
nsICacheListener.idl \
|
||||
nsICacheService.idl \
|
||||
nsICacheSession.idl \
|
||||
nsICacheVisitor.idl \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
53
mozilla/netwerk/cache/public/Makefile.win
vendored
53
mozilla/netwerk/cache/public/Makefile.win
vendored
@@ -1,53 +0,0 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
MODULE = necko
|
||||
XPIDL_MODULE = necko_cache
|
||||
|
||||
DEPTH = ..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
!ifdef MOZ_OLD_CACHE
|
||||
.\nsICachedNetData.idl \
|
||||
.\nsINetDataCacheManager.idl \
|
||||
.\nsINetDataCache.idl \
|
||||
.\nsINetDataCacheRecord.idl \
|
||||
.\nsINetDataDiskCache.idl \
|
||||
.\nsIStreamAsFile.idl \
|
||||
!endif
|
||||
!ifdef MOZ_NEW_CACHE
|
||||
.\nsICache.idl \
|
||||
.\nsICacheEntryDescriptor.idl \
|
||||
.\nsICacheListener.idl \
|
||||
.\nsICacheService.idl \
|
||||
.\nsICacheSession.idl \
|
||||
.\nsICacheVisitor.idl \
|
||||
!endif
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
|
||||
170
mozilla/netwerk/cache/public/nsICache.idl
vendored
170
mozilla/netwerk/cache/public/nsICache.idl
vendored
@@ -1,170 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsICache.idl, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
typedef long nsCacheStoragePolicy;
|
||||
typedef long nsCacheAccessMode;
|
||||
|
||||
/**
|
||||
* nsICache is a namespace for various cache constants. It does not represent
|
||||
* an actual object.
|
||||
*/
|
||||
[scriptable, uuid(ec1c0063-197d-44bb-84ba-7525d50fc937)]
|
||||
interface nsICache
|
||||
{
|
||||
/**
|
||||
* Access Modes
|
||||
*
|
||||
*
|
||||
* Mode Requested | Not Cached | Cached
|
||||
* ------------------------------------------------------------------------
|
||||
* READ | KEY_NOT_FOUND | NS_OK
|
||||
* | Mode = NONE | Mode = READ
|
||||
* | No Descriptor | Descriptor
|
||||
* ------------------------------------------------------------------------
|
||||
* WRITE | NS_OK | NS_OK (Cache service
|
||||
* | Mode = WRITE | Mode = WRITE dooms existing
|
||||
* | Descriptor | Descriptor cache entry)
|
||||
* ------------------------------------------------------------------------
|
||||
* READ_WRITE | NS_OK | NS_OK
|
||||
* (1st req.) | Mode = WRITE | Mode = READ_WRITE
|
||||
* | Descriptor | Descriptor
|
||||
* ------------------------------------------------------------------------
|
||||
* READ_WRITE | N/A | NS_OK
|
||||
* (Nth req.) | | Mode = READ
|
||||
* | | Descriptor
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
*
|
||||
* Access Requested:
|
||||
*
|
||||
* READ - I only want to READ, if there isn't an entry just fail
|
||||
* WRITE - I have something new I want to write into the cache, make
|
||||
* me a new entry and doom the old one, if any.
|
||||
* READ_WRITE - I want to READ, but I'm willing to update an existing
|
||||
* entry if necessary, or create a new one if none exists.
|
||||
*
|
||||
*
|
||||
* Access Granted:
|
||||
*
|
||||
* NONE - No descriptor is provided. You get zilch. Nada. Nothing.
|
||||
* READ - You can READ from this descriptor.
|
||||
* WRITE - You must WRITE to this descriptor because the cache entry
|
||||
* was just created for you.
|
||||
* READ_WRITE - You can READ the descriptor to determine if it's valid,
|
||||
* you may WRITE if it needs updating.
|
||||
*
|
||||
*
|
||||
* Comments:
|
||||
*
|
||||
* If you think that you might need to modify cached data or meta data,
|
||||
* then you must open a cache entry requesting WRITE access. Only one
|
||||
* cache entry descriptor, per cache entry, will be granted WRITE access.
|
||||
*
|
||||
* Usually, you will request READ_WRITE access in order to first test the
|
||||
* meta data and informational fields to determine if a write (ie. going
|
||||
* to the net) may actually be necessary. If you determine that it is
|
||||
* not, then you would mark the cache entry as valid (using MarkValid) and
|
||||
* then simply read the data from the cache.
|
||||
*
|
||||
* A descriptor granted WRITE access has exclusive access to the cache
|
||||
* entry up to the point at which it marks it as valid. Once the cache
|
||||
* entry has been "validated", other descriptors with READ access may be
|
||||
* opened to the cache entry.
|
||||
*
|
||||
* If you make a request for READ_WRITE access to a cache entry, the cache
|
||||
* service will downgrade your access to READ if there is already a
|
||||
* cache entry descriptor open with WRITE access.
|
||||
*
|
||||
* If you make a request for only WRITE access to a cache entry and another
|
||||
* descriptor with WRITE access is currently open, then the existing cache
|
||||
* entry will be 'doomed', and you will be given a descriptor (with WRITE
|
||||
* access only) to a new cache entry.
|
||||
*
|
||||
*/
|
||||
const nsCacheAccessMode ACCESS_NONE = 0;
|
||||
const nsCacheAccessMode ACCESS_READ = 1;
|
||||
const nsCacheAccessMode ACCESS_WRITE = 2;
|
||||
const nsCacheAccessMode ACCESS_READ_WRITE = 3;
|
||||
|
||||
/**
|
||||
* Storage Policy
|
||||
*
|
||||
* The storage policy of a cache entry determines the device(s) to which
|
||||
* it belongs. See nsICacheSession and nsICacheEntryDescriptor for more
|
||||
* details.
|
||||
*
|
||||
* STORE_ANYWHERE - Allows the cache entry to be stored in any device.
|
||||
* The cache service decides which cache device to use
|
||||
* based on "some resource management calculation."
|
||||
* STORE_IN_MEMORY - Requires the cache entry to reside in non-persistent
|
||||
* storage (ie. typically in system RAM).
|
||||
* STORE_ON_DISK - Requires the cache entry to reside in persistent
|
||||
* storage (ie. typically on a system's hard disk).
|
||||
* STORE_ON_DISK_AS_DISK - Requires the cache entry to reside in persistent
|
||||
* storage, and in a specific file.
|
||||
*/
|
||||
const nsCacheStoragePolicy STORE_ANYWHERE = 0;
|
||||
const nsCacheStoragePolicy STORE_IN_MEMORY = 1;
|
||||
const nsCacheStoragePolicy STORE_ON_DISK = 2;
|
||||
const nsCacheStoragePolicy STORE_ON_DISK_AS_FILE = 3;
|
||||
|
||||
/**
|
||||
* All entries for a cache session are stored as streams of data or
|
||||
* as objects. These constant my be used to specify the type of entries
|
||||
* when calling nsICacheService::CreateSession().
|
||||
*/
|
||||
const long NOT_STREAM_BASED = 0;
|
||||
const long STREAM_BASED = 1;
|
||||
|
||||
/**
|
||||
* The synchronous OpenCacheEntry() may be blocking or non-blocking. If a cache entry is
|
||||
* waiting to be validated by another cache descriptor (so no new cache descriptors for that
|
||||
* key can be created, OpenCacheEntry() will return NS_ERROR_CACHE_WAIT_FOR_VALIDATION in
|
||||
* non-blocking mode. In blocking mode, it will wait until the cache entry for the key has
|
||||
* been validated or doomed. If the cache entry is validated, then a descriptor for that
|
||||
* entry will be created and returned. If the cache entry was doomed, then a descriptor
|
||||
* will be created for a new cache entry for the key.
|
||||
*/
|
||||
const long NON_BLOCKING = 0;
|
||||
const long BLOCKING = 1;
|
||||
};
|
||||
|
||||
|
||||
%{C++
|
||||
|
||||
/**
|
||||
* Cache specific nsresult error codes
|
||||
*/
|
||||
#define NS_ERROR_CACHE_KEY_NOT_FOUND NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 61)
|
||||
#define NS_ERROR_CACHE_DATA_IS_STREAM NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 62)
|
||||
#define NS_ERROR_CACHE_DATA_IS_NOT_STREAM NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 63)
|
||||
#define NS_ERROR_CACHE_WAIT_FOR_VALIDATION NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 64)
|
||||
#define NS_ERROR_CACHE_ENTRY_DOOMED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 65)
|
||||
#define NS_ERROR_CACHE_READ_ACCESS_DENIED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 66)
|
||||
#define NS_ERROR_CACHE_WRITE_ACCESS_DENIED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 67)
|
||||
|
||||
%}
|
||||
@@ -1,137 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsICacheEntryDescriptor.idl, released
|
||||
* February 10, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsICacheVisitor.idl"
|
||||
#include "nsICache.idl"
|
||||
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsICacheListener;
|
||||
interface nsITransport;
|
||||
interface nsIFile;
|
||||
interface nsICacheMetaDataVisitor;
|
||||
|
||||
|
||||
[scriptable, uuid(49c1a11d-f5d2-4f09-8262-551e64908ada)]
|
||||
interface nsICacheEntryDescriptor : nsICacheEntryInfo
|
||||
{
|
||||
/**
|
||||
* Set the time at which the cache entry should be considered invalid (in
|
||||
* seconds since the Epoch).
|
||||
*/
|
||||
void setExpirationTime(in PRUint32 expirationTime);
|
||||
|
||||
/**
|
||||
* Set the cache entry data size. This will fail if the cache entry
|
||||
* IS stream based.
|
||||
*/
|
||||
void setDataSize(in unsigned long size);
|
||||
|
||||
/**
|
||||
* Get a transport to the cache data. This will fail if the cache entry
|
||||
* IS NOT stream based.
|
||||
*/
|
||||
readonly attribute nsITransport transport;
|
||||
|
||||
/**
|
||||
* Get/set the cache data element. This will fail if the cache entry
|
||||
* IS stream based. The cache entry holds a strong reference to this
|
||||
* object. The object will be released when the cache entry is destroyed.
|
||||
*/
|
||||
attribute nsISupports cacheElement;
|
||||
|
||||
/**
|
||||
* Get the access granted to this descriptor. See nsICache.idl for the
|
||||
* definitions of the access modes and a thorough description of their
|
||||
* corresponding meanings.
|
||||
*/
|
||||
readonly attribute nsCacheAccessMode accessGranted;
|
||||
|
||||
/**
|
||||
* Get/set the storage policy of the cache entry. See nsICache.idl for
|
||||
* the definitions of the storage policies.
|
||||
*/
|
||||
attribute nsCacheStoragePolicy storagePolicy;
|
||||
|
||||
/**
|
||||
* Get the disk file associated with the cache entry.
|
||||
*/
|
||||
readonly attribute nsIFile file;
|
||||
|
||||
/**
|
||||
* Get/set security info on the cache entry for this descriptor. This fails
|
||||
* if the storage policy is not STORE_IN_MEMORY.
|
||||
*/
|
||||
attribute nsISupports securityInfo;
|
||||
|
||||
/**
|
||||
* Doom the cache entry this descriptor references in order to slate it for
|
||||
* removal. Once doomed a cache entry cannot be undoomed.
|
||||
*
|
||||
* A descriptor with WRITE access can doom the cache entry and choose to
|
||||
* fail pending requests. This means that pending requests will not get
|
||||
* a cache descriptor. This is meant as a tool for clients that wish to
|
||||
* instruct pending requests to skip the cache.
|
||||
*/
|
||||
void doom();
|
||||
void doomAndFailPendingRequests(in nsresult status);
|
||||
|
||||
/**
|
||||
* A writer must validate this cache object before any readers are given
|
||||
* a descriptor to the object.
|
||||
*/
|
||||
void markValid();
|
||||
|
||||
/**
|
||||
* Explicitly close the descriptor (optional).
|
||||
*/
|
||||
|
||||
void close();
|
||||
|
||||
/**
|
||||
* Methods for accessing meta data. Meta data is a table of key/value
|
||||
* string pairs. The strings do not have to conform to any particular
|
||||
* charset, but they must be null terminated.
|
||||
*/
|
||||
string getMetaDataElement(in string key);
|
||||
void setMetaDataElement(in string key, in string value);
|
||||
|
||||
/**
|
||||
* Visitor will be called with key/value pair for each meta data element.
|
||||
*/
|
||||
void visitMetaData(in nsICacheMetaDataVisitor visitor);
|
||||
};
|
||||
|
||||
|
||||
|
||||
[scriptable, uuid(22f9a49c-3cf8-4c23-8006-54efb11ac562)]
|
||||
interface nsICacheMetaDataVisitor : nsISupports
|
||||
{
|
||||
/**
|
||||
* Called for each key/value pair in the meta data for a cache entry
|
||||
*/
|
||||
boolean visitMetaDataElement(in string key,
|
||||
in string value);
|
||||
};
|
||||
@@ -1,44 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsICacheListener.idl, released January 19, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsICache.idl"
|
||||
|
||||
|
||||
interface nsICacheEntryDescriptor;
|
||||
|
||||
[scriptable, uuid(638c3848-778b-4851-8ff3-9400f65b8773)]
|
||||
interface nsICacheListener : nsISupports
|
||||
{
|
||||
/**
|
||||
* Called when the requested access (or appropriate subset) is
|
||||
* acquired. The status parameter equals NS_OK on success.
|
||||
* See nsICacheService.idl for accessGranted values.
|
||||
*/
|
||||
void onCacheEntryAvailable(in nsICacheEntryDescriptor descriptor,
|
||||
in nsCacheAccessMode accessGranted,
|
||||
in nsresult status);
|
||||
};
|
||||
80
mozilla/netwerk/cache/public/nsICacheService.idl
vendored
80
mozilla/netwerk/cache/public/nsICacheService.idl
vendored
@@ -1,80 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsICacheService.idl, released February 10, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsICache.idl"
|
||||
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsICacheListener;
|
||||
interface nsICacheSession;
|
||||
interface nsICacheVisitor;
|
||||
|
||||
[scriptable, uuid(0ebec4c7-742f-4f27-8e7b-7c8a0cc76348)]
|
||||
interface nsICacheService : nsISupports
|
||||
{
|
||||
/**
|
||||
* Initialize the cache service.
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Shutdown the cache service.
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* Create a cache session
|
||||
*
|
||||
* A cache session represents a client's access into the cache. The cache
|
||||
* session is not "owned" by the cache service. Hence, it is possible to
|
||||
* create duplicate cache sessions. Entries created by a cache session
|
||||
* are invisible to other cache sessions, unless the cache sessions are
|
||||
* equivalent.
|
||||
*
|
||||
* @param clientID - Specifies the name of the client using the cache.
|
||||
* @param storagePolicy - Limits the storage policy for all entries
|
||||
* accessed via the returned session. As a result, devices excluded
|
||||
* by the storage policy will not be searched when opening entries
|
||||
* from the returned session.
|
||||
* @param streamBased - Indicates whether or not the data being cached
|
||||
* can be represented as a stream. The storagePolicy must be
|
||||
* consistent with the value of this field. For example, a non-stream-
|
||||
* based cache entry can only have a storage policy of STORE_IN_MEMORY.
|
||||
* @return new cache session.
|
||||
*/
|
||||
nsICacheSession createSession(in string clientID,
|
||||
in nsCacheStoragePolicy storagePolicy,
|
||||
in boolean streamBased);
|
||||
|
||||
/**
|
||||
* Visit entries stored in the cache. Used to implement about:cache.
|
||||
*/
|
||||
void visitEntries(in nsICacheVisitor visitor);
|
||||
|
||||
/**
|
||||
* Evicts all entries in all devices implied by the storage policy.
|
||||
*/
|
||||
void evictEntries(in nsCacheStoragePolicy storagePolicy);
|
||||
};
|
||||
72
mozilla/netwerk/cache/public/nsICacheSession.idl
vendored
72
mozilla/netwerk/cache/public/nsICacheSession.idl
vendored
@@ -1,72 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsICacheSession.idl, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsICache.idl"
|
||||
|
||||
interface nsICacheEntryDescriptor;
|
||||
interface nsICacheListener;
|
||||
|
||||
[scriptable, uuid(b4b419ad-28b7-4d25-9988-20fa98505a19)]
|
||||
interface nsICacheSession : nsISupports
|
||||
{
|
||||
/**
|
||||
* Expired entries will be doomed or evicted if this attribute is set to
|
||||
* true. If false, expired entries will be returned (useful for offline-
|
||||
* mode and clients, such as HTTP, that can update the valid lifetime of
|
||||
* cached content). This attribute defaults to true.
|
||||
*/
|
||||
attribute PRBool doomEntriesIfExpired;
|
||||
|
||||
/**
|
||||
* A cache session can only give out one descriptor with WRITE access
|
||||
* to a given cache entry at a time. Until the client calls MarkValid on
|
||||
* its descriptor, other attempts to open the same cache entry will block.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Synchronous cache access. This returns a unique descriptor each
|
||||
* time it is called, even if the same key is specified. When
|
||||
* called by multiple threads for write access, only one writable
|
||||
* descriptor will be granted. If 'blocking' is set to false,
|
||||
*/
|
||||
nsICacheEntryDescriptor openCacheEntry(in string key,
|
||||
in nsCacheAccessMode accessRequested,
|
||||
in boolean blockingMode);
|
||||
|
||||
/**
|
||||
* Asynchronous cache access. Does not block the calling thread.
|
||||
* Instead, the listener will be notified when the descriptor is
|
||||
* available.
|
||||
*/
|
||||
void asyncOpenCacheEntry(in string key,
|
||||
in nsCacheAccessMode accessRequested,
|
||||
in nsICacheListener listener);
|
||||
|
||||
/**
|
||||
* Evict all entries for this session's clientID according to its storagePolicy.
|
||||
*/
|
||||
void evictEntries();
|
||||
};
|
||||
142
mozilla/netwerk/cache/public/nsICacheVisitor.idl
vendored
142
mozilla/netwerk/cache/public/nsICacheVisitor.idl
vendored
@@ -1,142 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsICacheVisitor.idl, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/* XXX we should define device and entry info as well (stats, etc) */
|
||||
|
||||
interface nsICacheDeviceInfo;
|
||||
interface nsICacheEntryInfo;
|
||||
|
||||
|
||||
[scriptable, uuid(f8c08c4b-d778-49d1-a59b-866fdc500d95)]
|
||||
interface nsICacheVisitor : nsISupports
|
||||
{
|
||||
/**
|
||||
* Called to provide information about a cache device.
|
||||
*
|
||||
* @param deviceID - specifies the device being visited.
|
||||
* @param deviceInfo - specifies information about this device.
|
||||
*
|
||||
* @return true to start visiting all entries for this device.
|
||||
* @return false to advance to the next device.
|
||||
*/
|
||||
boolean visitDevice(in string deviceID,
|
||||
in nsICacheDeviceInfo deviceInfo);
|
||||
|
||||
/**
|
||||
* Called to provide information about a cache entry.
|
||||
*
|
||||
* @param deviceID - specifies the device being visited.
|
||||
* @param entryInfo - specifies information about this entry.
|
||||
*
|
||||
* @return true to visit the next entry on the current device, or if the
|
||||
* end of the device has been reached, advance to the next device.
|
||||
* @return false to advance to the next device.
|
||||
*/
|
||||
boolean visitEntry(in string deviceID,
|
||||
in nsICacheEntryInfo entryInfo);
|
||||
};
|
||||
|
||||
|
||||
[scriptable, uuid(31d1c294-1dd2-11b2-be3a-c79230dca297)]
|
||||
interface nsICacheDeviceInfo : nsISupports
|
||||
{
|
||||
/**
|
||||
* Get a human readable description of the cache device.
|
||||
*/
|
||||
readonly attribute string description;
|
||||
|
||||
/**
|
||||
* Get a usage report, statistics, miscellaneous data about
|
||||
* the cache device.
|
||||
*/
|
||||
readonly attribute string usageReport;
|
||||
|
||||
/**
|
||||
* Get the number of stored cache entries.
|
||||
*/
|
||||
readonly attribute unsigned long entryCount;
|
||||
|
||||
/**
|
||||
* Get the total size of the stored cache entries.
|
||||
*/
|
||||
readonly attribute unsigned long totalSize;
|
||||
|
||||
/**
|
||||
* Get the upper limit of the size of the data the cache can store.
|
||||
*/
|
||||
readonly attribute unsigned long maximumSize;
|
||||
};
|
||||
|
||||
|
||||
[scriptable, uuid(72c64022-1dd2-11b2-b3a5-b8b859e0a1b2)]
|
||||
interface nsICacheEntryInfo : nsISupports
|
||||
{
|
||||
/**
|
||||
* Get the client id associated with this cache entry.
|
||||
*/
|
||||
readonly attribute string clientID;
|
||||
|
||||
/**
|
||||
* Get the id for the device that stores this cache entry.
|
||||
*/
|
||||
readonly attribute string deviceID;
|
||||
|
||||
/**
|
||||
* Get the key identifying the cache entry.
|
||||
*/
|
||||
readonly attribute string key;
|
||||
|
||||
/**
|
||||
* Get the number of times the cache entry has been opened.
|
||||
*/
|
||||
readonly attribute long fetchCount;
|
||||
|
||||
/**
|
||||
* Get the last time the cache entry was opened (in seconds since the Epoch).
|
||||
*/
|
||||
readonly attribute PRUint32 lastFetched;
|
||||
|
||||
/**
|
||||
* Get the last time the cache entry was modified (in seconds since the Epoch).
|
||||
*/
|
||||
readonly attribute PRUint32 lastModified;
|
||||
|
||||
/**
|
||||
* Get the expiration time of the cache entry (in seconds since the Epoch).
|
||||
*/
|
||||
readonly attribute PRUint32 expirationTime;
|
||||
|
||||
/**
|
||||
* Get the cache entry data size.
|
||||
*/
|
||||
readonly attribute unsigned long dataSize;
|
||||
|
||||
/**
|
||||
* Find out whether or not the cache entry is stream based.
|
||||
*/
|
||||
boolean isStreamBased();
|
||||
};
|
||||
240
mozilla/netwerk/cache/public/nsICachedNetData.idl
vendored
240
mozilla/netwerk/cache/public/nsICachedNetData.idl
vendored
@@ -1,240 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsrootidl.idl"
|
||||
#include "nsISupports.idl"
|
||||
|
||||
|
||||
interface nsIURI;
|
||||
interface nsIObserver;
|
||||
interface nsIChannel;
|
||||
interface nsINetDataCache;
|
||||
interface nsINetDataCacheRecord;
|
||||
interface nsILoadGroup;
|
||||
interface nsIStreamListener;
|
||||
|
||||
/**
|
||||
* The nsICachedNetData interface represents a single entry in a database that
|
||||
* caches data retrieved from the network. This interface is implemented by the
|
||||
* cache manager on top of the low-level nsINetDataCacheRecord and
|
||||
* nsINetDataCache interfaces that are implemented by the database.
|
||||
*
|
||||
* Each cache record may contain both content and metadata. The content may
|
||||
* be, for example, GIF image data or HTML, and it is accessed through
|
||||
* nsIChannel's streaming API. The opaque metadata, which may contain HTTP
|
||||
* headers among other things, is stored as a byte array. Each entry in the
|
||||
* cache is indexed by two different keys: a record id number and a key created
|
||||
* by combining the URI with a "secondary key", e.g. HTTP post data.
|
||||
*
|
||||
* @See nsINetDataCacheRecord
|
||||
* @See nsINetDataCache
|
||||
* @See nsINetDataDiskCache
|
||||
* @See nsINetDataCacheManager
|
||||
*/
|
||||
[scriptable, uuid(6aeb2a40-6d43-11d3-90c8-000064657374)]
|
||||
interface nsICachedNetData : nsISupports
|
||||
{
|
||||
/**
|
||||
* String form of the URI provided as an argument to the call to
|
||||
* nsINetDataCacheManager::GetCachedNetData() that created this record.
|
||||
*/
|
||||
readonly attribute string uriSpec;
|
||||
|
||||
/**
|
||||
* Getter for the opaque secondary database key provided as an argument to
|
||||
* the call to nsINetDataCacheManager::GetCachedNetData() that created this
|
||||
* record.
|
||||
*/
|
||||
void getSecondaryKey(out unsigned long length,
|
||||
[retval, size_is(length)] out string secondaryKey);
|
||||
|
||||
/**
|
||||
* This flag may be set by a protocol handler to indicate that it supports
|
||||
* partial fetching of data. In that case, the cache manager is permitted
|
||||
* to truncate the entry's content to accommodate incoming data for other
|
||||
* cache entries rather than deleting it wholesale.
|
||||
*/
|
||||
attribute boolean allowPartial;
|
||||
|
||||
/**
|
||||
* This flag indicates that the write stream supplying content data for the
|
||||
* cache did not complete normally and, therefore, the content may be
|
||||
* truncated.
|
||||
*/
|
||||
readonly attribute boolean partialFlag;
|
||||
|
||||
/**
|
||||
* This flag can be set and cleared by a protocol handler as a form of
|
||||
* self-notification, so as to avoid race conditions in which a protocol
|
||||
* handler issues two identical network requests to fill the same cache
|
||||
* entry. The cache manager itself largely ignores this flag.
|
||||
*/
|
||||
attribute boolean updateInProgress;
|
||||
|
||||
/**
|
||||
* inUse is set if any existing channels are associated with this cache
|
||||
* entry or if the updateInProgess flag is set. This can be used to
|
||||
* prevent writing to a cache entry by a protocol handler if it's being
|
||||
* read or written elsewhere.
|
||||
*/
|
||||
readonly attribute boolean inUse;
|
||||
|
||||
/**
|
||||
* Date/time that the document was last stored on the origin server, as
|
||||
* supplied by the protocol handler. This value is used as input to the
|
||||
* cache replacement policy, i.e. it is not used for validation. If the
|
||||
* protocol can't supply a last-modified time, this attribute should remain
|
||||
* unset. When unset, the value of this attribute is zero.
|
||||
*
|
||||
* FIXME: Should use nsIDateTime interface, once it's created
|
||||
* instead of PRTime, for improved scriptability ?
|
||||
*/
|
||||
attribute PRTime lastModifiedTime;
|
||||
|
||||
/**
|
||||
* Supplied by the protocol handler, the expirationTime attribute specifies
|
||||
* the time until which the document is guaranteed fresh, i.e. the document
|
||||
* does not have to be validated with the server and, therefore, any data
|
||||
* in cache is definitely usable. The value of this attribute serves as a
|
||||
* hint to the cache replacement policy. Only one of either staleTime or
|
||||
* expirationTime may be set for a single cache record. When unset, the
|
||||
* value of this attribute is zero.
|
||||
*/
|
||||
attribute PRTime expirationTime;
|
||||
|
||||
/**
|
||||
* Date/time supplied by the protocol handler, at which point the content
|
||||
* is *likely* to be stale, i.e. the data in the cache may be out-of-date
|
||||
* with respect to the data on the server. This heuristic date does not
|
||||
* necessarily correspond to the HTTP Expires header, as it does not
|
||||
* determine when cached network data must be validated with the origin
|
||||
* server, but only serves as a hint to the cache replacement policy. Only
|
||||
* one of either staleTime or expirationTime may be set for a single cache
|
||||
* record. When unset, the value of this attribute is zero.
|
||||
*/
|
||||
attribute PRTime staleTime;
|
||||
|
||||
/**
|
||||
* Date/time of last access of the data in this cache record, as determined
|
||||
* by the cache manager.
|
||||
*/
|
||||
readonly attribute PRTime lastAccessTime;
|
||||
|
||||
readonly attribute PRTime lastUpdateTime;
|
||||
|
||||
/**
|
||||
* Number of times this record has been accessed since it was first stored.
|
||||
*/
|
||||
readonly attribute PRUint16 numberAccesses;
|
||||
|
||||
/**
|
||||
* Accessor methods for opaque meta-data which can be read and updated
|
||||
* independently of the content data.
|
||||
*
|
||||
* The aTag argument can be used to accommodate multiple clients of the
|
||||
* cache API, each of which wants to store its own private meta-data into
|
||||
* the cache. For example, there could be a "headers" tag that the HTTP
|
||||
* protocol handler uses to store http response headers and a "image size"
|
||||
* tag used to store the image dimensions of a GIF file. The aData
|
||||
* argument refers to an opaque blob of arbitrary bytes.
|
||||
*
|
||||
* IMPORTANT: If aData does not contain byte-oriented data, i.e. it's not a
|
||||
* string, the contents of aData must be byte-swapped by the,
|
||||
* caller, so as to make the cache files endian-independent.
|
||||
*/
|
||||
void getAnnotation(in string aTag,
|
||||
out PRUint32 aLength, [size_is(aLength), retval] out string aData);
|
||||
void setAnnotation(in string aTag,
|
||||
in PRUint32 aLength, [size_is(aLength)] in string aData);
|
||||
|
||||
/**
|
||||
* As a getter, return the number of content bytes stored in the cache,
|
||||
* i.e. via the nsIChannel streaming APIs. This may be less than the
|
||||
* complete content length if a partial cache fill occurred. The cached
|
||||
* content can be truncated by setting the value of this attribute. The
|
||||
* value of the attribute represents a logical, not a physical, length. If
|
||||
* compression has been used, the content may consume less storage than
|
||||
* indicated by this attribute.
|
||||
*
|
||||
* When this attribute is set to zero the associated cache disk file, if
|
||||
* any, should be deleted.
|
||||
*/
|
||||
attribute PRUint32 storedContentLength;
|
||||
|
||||
/**
|
||||
* Length of stored content, which may be less than storage consumed if
|
||||
* compression is used
|
||||
*/
|
||||
readonly attribute PRUint32 logicalLength;
|
||||
|
||||
/**
|
||||
* Opaque security info associated with the cache entry; it can't be serialized
|
||||
* to disk, so it'll only make sense with memory cache
|
||||
*/
|
||||
attribute nsISupports securityInfo;
|
||||
|
||||
/**
|
||||
* Notify any observers associated with this cache entry of the deletion
|
||||
* request. If all observers drop their reference to the cache entry,
|
||||
* proceed to delete the underlying cache database record and associated
|
||||
* content storage.
|
||||
*/
|
||||
void delete();
|
||||
|
||||
/**
|
||||
* Flush any changes in this entry's data to the cache database. This
|
||||
* method will automatically be called when the last reference to the cache
|
||||
* is dropped, but it can also be called explicitly for a synchronous
|
||||
* effect.
|
||||
*/
|
||||
void commit();
|
||||
|
||||
/**
|
||||
* Parent container cache for this entry.
|
||||
*/
|
||||
readonly attribute nsINetDataCache cache;
|
||||
|
||||
/**
|
||||
* Create a channel for reading or writing a stream of content into the
|
||||
* entry. It is expected that many of the nsIChannel methods return
|
||||
* NS_NOT_IMPLEMENTED, including:
|
||||
*
|
||||
* + GetURI()
|
||||
* + GetContentType()
|
||||
* + GetContentLength()
|
||||
*
|
||||
* Though nsIChannel provides for both async and synchronous I/O APIs, both
|
||||
* may not be implemented. Only AsyncRead() and OpenOutputStream() is
|
||||
* required.
|
||||
*/
|
||||
nsIChannel newChannel(in nsILoadGroup aLoadGroup);
|
||||
|
||||
/**
|
||||
* This method can be used by a caching protocol handler to store data in
|
||||
* the cache by forking an asynchronous read stream so that it is
|
||||
* simultaneously sent to a requester and written into the cache. This
|
||||
* method implicitly sets the updateInProgress flag, if it has not already
|
||||
* been set.
|
||||
*/
|
||||
nsIStreamListener interceptAsyncRead(in nsIStreamListener aOriginalListener,
|
||||
in PRUint32 aStartOffset);
|
||||
};
|
||||
142
mozilla/netwerk/cache/public/nsINetDataCache.idl
vendored
142
mozilla/netwerk/cache/public/nsINetDataCache.idl
vendored
@@ -1,142 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIURI;
|
||||
interface nsINetDataCacheRecord;
|
||||
interface nsISimpleEnumerator;
|
||||
|
||||
/**
|
||||
* The nsINetDataCache defines the low-level API for a network-data
|
||||
* cache, used to cache the responses to network retrieval commands.
|
||||
* This interface, along with nsINetDataCacheRecord, is implemented by
|
||||
* the memory cache, the file cache and, optionally, by some extension
|
||||
* caches. This interface is essentially a pseudo-private API for the
|
||||
* cache manager. Other clients should never use this interface.
|
||||
*
|
||||
* Each cache entry may contain both content, e.g. GIF image data, and
|
||||
* associated metadata, e.g. HTTP headers. Each entry is indexed by two
|
||||
* different keys: a record id number and a key created by combining the URI
|
||||
* with a "secondary key", e.g. HTTP post data.
|
||||
*
|
||||
* The nsINetDataCache interface is agnostic as to where the data is
|
||||
* stored and whether the storage is volatile or persistent. The
|
||||
* memory cache, any disk caches and any extension caches must all
|
||||
* implement this interface.
|
||||
*
|
||||
*/
|
||||
[scriptable, uuid(ccfc58c0-6dde-11d3-90c8-000064657374)]
|
||||
interface nsINetDataCache : nsISupports
|
||||
{
|
||||
/**
|
||||
* Human-readable description of the cache module, e.g. "Disk Cache"
|
||||
*/
|
||||
readonly attribute wstring description;
|
||||
|
||||
/**
|
||||
* Returns true if cached data is available for the given opaque key,
|
||||
* even if only partial data is stored.
|
||||
*/
|
||||
boolean contains([size_is(length)] in string key, in PRUint32 length);
|
||||
|
||||
/**
|
||||
* Fetch the cache entry record for the given opaque key. If one does not
|
||||
* exist, create a new, empty record.
|
||||
*/
|
||||
nsINetDataCacheRecord getCachedNetData([size_is(length)] in string key,
|
||||
in PRUint32 length);
|
||||
|
||||
/**
|
||||
* Fetch the cache entry record for the given URI using the record ID as a key.
|
||||
*/
|
||||
nsINetDataCacheRecord getCachedNetDataByID(in PRInt32 RecordID);
|
||||
|
||||
/**
|
||||
* False indicates that this cache is entirely bypassed.
|
||||
*/
|
||||
attribute boolean enabled;
|
||||
|
||||
/**
|
||||
* Constants for flags attribute, below
|
||||
*/
|
||||
|
||||
// Used for extension caches, e.g. a CD-ROM cache
|
||||
const long READ_ONLY = 1 << 0;
|
||||
|
||||
// One of these bits must be set
|
||||
const long MEMORY_CACHE = 1 << 1;
|
||||
const long FLAT_FILE_CACHE = 1 << 2;
|
||||
const long FILE_PER_URL_CACHE = 1 << 3;
|
||||
|
||||
/**
|
||||
* See constants defined above.
|
||||
*/
|
||||
readonly attribute PRUint32 flags;
|
||||
|
||||
/**
|
||||
* Total number of URI entries stored in the cache.
|
||||
*/
|
||||
readonly attribute PRUint32 numEntries;
|
||||
|
||||
/**
|
||||
* Maximum number of URI entries that may be stored in the cache.
|
||||
*/
|
||||
readonly attribute PRUint32 maxEntries;
|
||||
|
||||
/**
|
||||
* Enumerate the URI entries stored in the cache.
|
||||
*/
|
||||
nsISimpleEnumerator newCacheEntryIterator();
|
||||
|
||||
/**
|
||||
* Contains a reference to the next cache in search order. For the memory
|
||||
* cache, this attribute always references the disk cache. For the disk
|
||||
* cache, it contains a reference to the first extension cache.
|
||||
*/
|
||||
attribute nsINetDataCache nextCache;
|
||||
|
||||
/**
|
||||
* An estimate of the amount of storage occupied by the cache, in kB.
|
||||
* Actual use may be slightly higher than reported due to cache overhead
|
||||
* and heap fragmentation (in the memory cache) or block quantization (in
|
||||
* the disk cache).
|
||||
*/
|
||||
readonly attribute PRUint32 storageInUse;
|
||||
|
||||
/**
|
||||
* Remove all entries from a writable cache. This could be used, for
|
||||
* example, after a guest ends a browser session. This is equivalent to
|
||||
* setting the cache's Capacity to zero, except that all cache entries,
|
||||
* even those in active use, will be deleted. Also, any global cache
|
||||
* database files will be deleted.
|
||||
*/
|
||||
void removeAll();
|
||||
};
|
||||
|
||||
%{ C++
|
||||
// ContractID prefix for Components that implement this interface
|
||||
#define NS_NETWORK_CACHE_CONTRACTID "@mozilla.org/network/cache;1"
|
||||
#define NS_NETWORK_MEMORY_CACHE_CONTRACTID NS_NETWORK_CACHE_CONTRACTID "?name=memory-cache"
|
||||
#define NS_NETWORK_FLAT_CACHE_CONTRACTID NS_NETWORK_CACHE_CONTRACTID "?name=flat-cache"
|
||||
#define NS_NETWORK_FILE_CACHE_CONTRACTID NS_NETWORK_CACHE_CONTRACTID "?name=file-cache"
|
||||
%}
|
||||
@@ -1,169 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsINetDataCache.idl"
|
||||
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsICachedNetData;
|
||||
interface nsINetDataDiskCache;
|
||||
interface nsIURI;
|
||||
|
||||
/**
|
||||
* The network-response cache manager is partly responsible for the caching of
|
||||
* content and associated metadata that has been retrieved via the network.
|
||||
* (The remaining responsibility for caching lies with individual network
|
||||
* protocol handlers.)
|
||||
*
|
||||
* The cache manager supervises the actions of individual cache components,
|
||||
* such as the memory cache, the disk cache and any extension caches, e.g. a
|
||||
* read-only CD-ROM cache.
|
||||
*
|
||||
* @See nsINetDataCache
|
||||
* @See nsICachedNetData
|
||||
*/
|
||||
[scriptable, uuid(71c8ab00-6d5c-11d3-90c8-000064657374)]
|
||||
interface nsINetDataCacheManager : nsISupports
|
||||
{
|
||||
/**
|
||||
* Flag for the GetCachedNetData() method: If set, the memory cache is
|
||||
* neither searched nor will any data be stored into it. This might be
|
||||
* appropriate, for example, with images, because they have their own
|
||||
* cache for storing *decoded* images.
|
||||
*/
|
||||
const unsigned long BYPASS_MEMORY_CACHE = 1 << 0;
|
||||
|
||||
/**
|
||||
* Flag for the GetCachedNetData() method: If set, the disk cache
|
||||
* is neither searched nor will any be data stored into it.
|
||||
* However, read-only extension caches may be searched. This
|
||||
* might be used to avoid leaving persistent records of secure
|
||||
* data.
|
||||
*/
|
||||
const unsigned long BYPASS_PERSISTENT_CACHE = 1 << 1;
|
||||
|
||||
/**
|
||||
* Flag for the GetCachedNetData() method: If set, any stream
|
||||
* content is stored in the cache as a single disk file. Content
|
||||
* will not be cached in the memory cache nor is it cached in a
|
||||
* flat-file cache database. This is used to implement the jar
|
||||
* protocol handler and to provide the stream-as-file semantics
|
||||
* required by the classic bowser plugin API.
|
||||
*/
|
||||
const unsigned long CACHE_AS_FILE = 1 << 2;
|
||||
|
||||
/**
|
||||
These enum's are used for the ClearCache calls.
|
||||
*/
|
||||
const unsigned long ALL_CACHES = 1;
|
||||
const unsigned long MEM_CACHE = 1<<1;
|
||||
const unsigned long FILE_CACHE = 1<<2;
|
||||
const unsigned long FLAT_CACHE = 1<<3;
|
||||
/**
|
||||
* Fetch the cache entry record for the given URI. If one does not exist,
|
||||
* create a new, empty record. The normal search order for caches is:
|
||||
* + Memory cache
|
||||
* + Disk cache
|
||||
* + File cache (stream-as-file cache)
|
||||
* + All extension caches
|
||||
*
|
||||
* When writing, data is typically stored in both the memory cache and the
|
||||
* disk cache. Both the search order and this write policy can be modified by
|
||||
* setting one or more of the flag argument bits, as defined above.
|
||||
*
|
||||
* The optionally-NULL secondaryKey argument can be used, e.g. for form
|
||||
* post data or for HTTP headers in the case of HTTP.
|
||||
*/
|
||||
nsICachedNetData getCachedNetData(in string uri,
|
||||
[size_is(secondaryKeyLength)] in string secondaryKey,
|
||||
in PRUint32 secondaryKeyLength,
|
||||
in PRUint32 flags);
|
||||
|
||||
/**
|
||||
* Returns true if cached content is available for the given URI, even if
|
||||
* only partial data is stored. The flags argument behaves the same as for
|
||||
* the GetCachedNetData() method, above.
|
||||
*/
|
||||
boolean contains(in string uri,
|
||||
[size_is(secondaryKeyLength)] in string secondaryKey,
|
||||
in PRUint32 secondaryKeyLength,
|
||||
in PRUint32 flags);
|
||||
|
||||
/**
|
||||
* Total number of unexpired URI entries stored in all caches. This number
|
||||
* does not take into account duplicate URIs, e.g. because the memory cache
|
||||
* and the disk cache might each contain an entry for the same URI.
|
||||
*/
|
||||
readonly attribute PRUint32 numEntries;
|
||||
|
||||
/**
|
||||
* Enumerate the unexpired URI entries stored in all caches. Some URIs may
|
||||
* be enumerated more than once, e.g. because the the memory cache and the
|
||||
* disk cache might each contain an entry for the same URI.
|
||||
*/
|
||||
nsISimpleEnumerator newCacheEntryIterator();
|
||||
|
||||
/*
|
||||
* Enumerate all the loaded nsINetDataCache-implementing cache modules.
|
||||
* The first module enumerated will be the memory cache, the second will be
|
||||
* the disk cache, then the file cache, followed by all the extension
|
||||
* caches, in search order.
|
||||
*/
|
||||
nsISimpleEnumerator newCacheModuleIterator();
|
||||
|
||||
/**
|
||||
* Remove all entries from all writable caches. This could be used, for
|
||||
* example, after a guest ends a browser session. This is equivalent to
|
||||
* setting the DiskCacheCapacity to zero, except that all cache entries,
|
||||
* even those in active use, will be deleted. Also, any global cache
|
||||
* database files will be deleted.
|
||||
*/
|
||||
void removeAll();
|
||||
|
||||
/**
|
||||
* Clears the specified cache
|
||||
*/
|
||||
void clear( in PRUint32 aCacheToClear );
|
||||
|
||||
/**
|
||||
* The disk cache is made up of the file cache (for stream-as-file
|
||||
* requests) and a (possibly independent) persistent cache that handles all
|
||||
* other cache requests. This attribute sets/gets the combined capacity of
|
||||
* these caches, measured in KBytes. Setting the capacity lower than the
|
||||
* current amount of space currently in use may cause cache entries to be
|
||||
* evicted from the cache to accomodate the requested capacity.
|
||||
*/
|
||||
attribute PRUint32 diskCacheCapacity;
|
||||
|
||||
/**
|
||||
* This attribute sets/gets the capacity of the memory cache, measured in
|
||||
* KBytes. Setting the capacity lower than the current amount of space
|
||||
* currently in use may cause cache entries to be evicted from the cache to
|
||||
* accomodate the requested capacity.
|
||||
*/
|
||||
attribute PRUint32 memCacheCapacity;
|
||||
};
|
||||
|
||||
%{ C++
|
||||
// ContractID prefix for Components that implement this interface
|
||||
#define NS_NETWORK_CACHE_MANAGER_CONTRACTID NS_NETWORK_CACHE_CONTRACTID "?name=manager"
|
||||
%}
|
||||
@@ -1,131 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsrootidl.idl"
|
||||
|
||||
interface nsIFile;
|
||||
interface nsIChannel;
|
||||
interface nsINetDataCache;
|
||||
|
||||
/**
|
||||
* The nsINetDataCacheRecord represents a single entry in a database that
|
||||
* caches data retrieved from the network. On top of this low-level interface
|
||||
* to the raw record data, the cache manager implements a higher-level record
|
||||
* interface, nsICachedNetData. Each instance of nsINetDataCacheRecord is
|
||||
* (internally) associated with a parent database, an instance of the
|
||||
* nsINetDataCache interface. This interface is essentially a pseudo-private
|
||||
* API for the cache manager. Other clients should never use this interface.
|
||||
*
|
||||
* Each cache record may contain both content and metadata. The content may
|
||||
* be, for example, GIF image data or HTML, and it is accessed through
|
||||
* nsIChannel's streaming API. The opaque metadata, which may contain HTTP
|
||||
* headers among other things, is accessed as a contiguous byte array. Each
|
||||
* entry in the cache is indexed by two different keys: a unique record id
|
||||
* number, generated by the cache, and an opaque string. The latter contains
|
||||
* the URI and other secondary key information, e.g. HTTP form post key/value
|
||||
* pairs.
|
||||
*
|
||||
* The nsINetDataCacheRecord interface is agnostic as to where the data is
|
||||
* stored and whether the storage is volatile or persistent. The memory cache,
|
||||
* the disk cache, a flat-file cache and any read-only extension caches must
|
||||
* all implement this interface.
|
||||
*
|
||||
* @See nsICachedNetData
|
||||
* @See nsINetDataCache
|
||||
* @See nsINetDataDiskCache
|
||||
* @See nsINetDataCacheManager
|
||||
*/
|
||||
|
||||
interface nsILoadGroup;
|
||||
|
||||
[scriptable, uuid(fdcdd6a0-7461-11d3-90ca-0040056a906e)]
|
||||
interface nsINetDataCacheRecord : nsISupports
|
||||
{
|
||||
/**
|
||||
* As far as the nsINetDataCacheRecord implementation is concerned, the
|
||||
* cache entry database key is an opaque blob, but it's intended to contain
|
||||
* both the URI and any secondary keys, such as HTTP post data.
|
||||
*/
|
||||
void getKey(out unsigned long length, [size_is(length), retval] out string key);
|
||||
|
||||
/**
|
||||
* A persistent record number assigned by the cache which must be unique
|
||||
* among all entries stored within the same cache. The record ID serves as
|
||||
* an alternate key to the cache record. Providing that they satisfy the
|
||||
* afforementioned uniqueness requirement, record IDs can be assigned any
|
||||
* value by the database except that they may never be zero.
|
||||
*/
|
||||
readonly attribute PRInt32 recordID;
|
||||
|
||||
/**
|
||||
* Opaque data which can be updated for each cache entry independently of
|
||||
* the content data. This data is a combination of protocol-independent
|
||||
* data provided by the cache manager and protocol-specific meta-data,
|
||||
* e.g. HTTP headers.
|
||||
*/
|
||||
void getMetaData(out PRUint32 length, [size_is(length), retval] out string metaData);
|
||||
void setMetaData(in PRUint32 length, [size_is(length)] in string data);
|
||||
|
||||
/**
|
||||
* Number of content bytes stored in the cache, i.e. via the nsIChannel
|
||||
* streaming APIs. This may be less than the complete content length if a
|
||||
* partial cache fill occurred. Additionally, the cached content can be
|
||||
* truncated by reducing the value of this attribute. When this attribute
|
||||
* is set to zero the associated cache disk file, if any, should be
|
||||
* deleted.
|
||||
*/
|
||||
attribute PRUint32 storedContentLength;
|
||||
|
||||
/**
|
||||
* Opaque security info associated with the cache entry; it can't be serialized
|
||||
* to disk, so it'll only make sense with memory cache
|
||||
*/
|
||||
attribute nsISupports securityInfo;
|
||||
|
||||
/**
|
||||
* Delete this cache entry and its associated content.
|
||||
*/
|
||||
void delete();
|
||||
|
||||
/**
|
||||
* Create a channel for reading or writing a stream of content into the
|
||||
* entry. However, many of the nsIChannel methods may return
|
||||
* NS_NOT_IMPLEMENTED, including:
|
||||
*
|
||||
* + GetURI()
|
||||
* + GetContentType()
|
||||
* + GetContentLength()
|
||||
*/
|
||||
nsIChannel newChannel(in nsILoadGroup loadGroup);
|
||||
|
||||
/**
|
||||
* If a cache is implemented such that it stores each URI's content in an
|
||||
* individual disk file, this method will identify the file corresponding
|
||||
* to this record. This may be used to implement the "stream-as-file"
|
||||
* semantics required by some plugins and by the 'jar:' protocol handler.
|
||||
* However, not all cache implementations are *required* to store the data
|
||||
* from each URI in an individual file, so it is acceptable for an
|
||||
* implementation of this method to signal NS_NOT_IMPLEMENTED.
|
||||
*/
|
||||
readonly attribute nsIFile file;
|
||||
};
|
||||
@@ -1,41 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsINetDataCache.idl"
|
||||
|
||||
interface nsIFile;
|
||||
|
||||
/**
|
||||
* A network-data disk cache is used to persistently cache the responses to
|
||||
* network retrieval commands. Each cache entry may contain both content,
|
||||
* e.g. GIF image data, and associated metadata, e.g. HTTP headers.
|
||||
*/
|
||||
[scriptable, uuid(6408e390-6f13-11d3-90c8-000064657374)]
|
||||
interface nsINetDataDiskCache : nsINetDataCache
|
||||
{
|
||||
/**
|
||||
* This attribute must be set before calling any other methods of this
|
||||
* interface.
|
||||
*/
|
||||
attribute nsIFile diskCacheFolder;
|
||||
};
|
||||
|
||||
106
mozilla/netwerk/cache/public/nsIStreamAsFile.idl
vendored
106
mozilla/netwerk/cache/public/nsIStreamAsFile.idl
vendored
@@ -1,106 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code, released
|
||||
* March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Scott Furman, fur@netscape.com
|
||||
*/
|
||||
#include "nsrootidl.idl"
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIFile;
|
||||
interface nsIStreamAsFileObserver;
|
||||
|
||||
/**
|
||||
* In addition to enhancing effective network response time via caching, the
|
||||
* cache manager serves a second purpose by providing the stream-as-file
|
||||
* service required by traditional browser plugins and the jar: protocol
|
||||
* handler. The interface below provides a means for a client to determine the
|
||||
* filename associated with a stream and to detect modification/deletion of
|
||||
* that file.
|
||||
*/
|
||||
[scriptable, uuid(0eedbbf0-92d9-11d3-90d3-0040056a906e)]
|
||||
interface nsIStreamAsFile : nsISupports
|
||||
{
|
||||
/**
|
||||
* Filename containing stream-as-file
|
||||
*/
|
||||
readonly attribute nsIFile file;
|
||||
|
||||
/**
|
||||
* Add an observer for this cache record. When the cache wants to delete
|
||||
* or truncate a record, so as to make space for another cache entry's
|
||||
* content data, it will call <code>aObserver</code>'s Observe() method,
|
||||
* passing the nsIStreamAsFile instance as the <code>aSubject</code>
|
||||
* argument and an appropriate message. If the observer does not wish to
|
||||
* inhibit deletion/truncation, it should Release() any references it has to the
|
||||
* cache record.
|
||||
*
|
||||
* @See nsIStreamAsFileObserver
|
||||
*/
|
||||
void addObserver(in nsIStreamAsFileObserver aObserver);
|
||||
|
||||
/**
|
||||
* Delete an observer that was added by the AddObserver() method.
|
||||
*/
|
||||
void removeObserver(in nsIStreamAsFileObserver aObserver);
|
||||
};
|
||||
|
||||
/**
|
||||
* This interface can be implemented by a client to receive notifications of
|
||||
* either modification or deletion of a file created by the cache manager using
|
||||
* the stream-as-file semantics.
|
||||
*/
|
||||
[scriptable, uuid(a26e27c0-92da-11d3-90d3-0040056a906e)]
|
||||
interface nsIStreamAsFileObserver : nsISupports
|
||||
{
|
||||
/**
|
||||
* Flag bits for argument to observeStreamAsFile() method.
|
||||
*/
|
||||
const long NOTIFY_AVAILABLE = 1 << 0; // Stream-as-file now available for reading
|
||||
const long NOTIFY_ERROR = 1 << 1; // Error while loading stream / creating file
|
||||
const long REQUEST_DELETION = 1 << 2; // Cache manager wishes to delete/truncate file
|
||||
const long INVALIDATE = 1 << 3; // File is out-of-date
|
||||
|
||||
// Convenience value
|
||||
const long MAKE_UNAVAILABLE = REQUEST_DELETION | INVALIDATE;
|
||||
|
||||
/**
|
||||
* Receive either a notification or a request concerning a file that has
|
||||
* been opened using stream-as-file. The aMessage and aError arguments
|
||||
* have varying values depending on the nature of the notification.
|
||||
* aMessage is set to NOTIFY_AVAILABLE when a complete stream has been read
|
||||
* and stored on disk in a file. At that point, and no sooner, may the
|
||||
* filename attribute of the associated nsIStreamAsFile be accessed via the
|
||||
* associated nsIStreamAsFile interface. If the aMessage argument is
|
||||
* NOTIFY_ERROR, the aError argument contains the relevant error code. If
|
||||
* the aMessage argument is either REQUEST_DELETION or REQUEST_TRUNCATION,
|
||||
* the callee should immediately Release() all references to the
|
||||
* nsIStreamAsFile (and any references to its associated nsICachedNetData
|
||||
* instances), unless it wishes to inhibit the requested file modification.
|
||||
* If the aMessage argument is INVALIDATE, the cache manager is replacing
|
||||
* the file with a more recent version. If a client wants to continue
|
||||
* using the (now out-of-date) file, it must delete it when it has finished,
|
||||
* as the cache manager will effectively relinquished ownership of the
|
||||
* file.
|
||||
*/
|
||||
void observeStreamAsFile(in nsIStreamAsFile aStreamAsFile,
|
||||
in PRUint32 aMessage,
|
||||
in nsresult aError);
|
||||
};
|
||||
68
mozilla/netwerk/cache/src/Makefile.in
vendored
68
mozilla/netwerk/cache/src/Makefile.in
vendored
@@ -1,68 +0,0 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = nkcache
|
||||
LIBRARY_NAME = nkcache
|
||||
EXPORT_LIBRARY = 1
|
||||
IS_COMPONENT = 1
|
||||
REQUIRES = xpcom string necko pref
|
||||
|
||||
EXPORTS = \
|
||||
nsCacheService.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsCache.cpp \
|
||||
nsCacheEntry.cpp \
|
||||
nsCacheEntryDescriptor.cpp \
|
||||
nsCacheMetaData.cpp \
|
||||
nsCacheModule.cpp \
|
||||
nsCacheService.cpp \
|
||||
nsCacheSession.cpp \
|
||||
nsDiskCacheBinding.cpp \
|
||||
nsDiskCacheBlockFile.cpp \
|
||||
nsDiskCacheDevice.cpp \
|
||||
nsDiskCacheEntry.cpp \
|
||||
nsDiskCacheMap.cpp \
|
||||
nsMemoryCacheDevice.cpp \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
EXTRA_DSO_LDOPTS = $(MOZ_COMPONENT_LIBS)
|
||||
|
||||
#EXTRA_LIBS = $(NSPR_LIBS)
|
||||
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a
|
||||
# static lib.
|
||||
#override NO_SHARED_LIB=1
|
||||
#override NO_STATIC_LIB=
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
69
mozilla/netwerk/cache/src/makefile.win
vendored
69
mozilla/netwerk/cache/src/makefile.win
vendored
@@ -1,69 +0,0 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
MODULE = nkcache
|
||||
DLLNAME=nkcache
|
||||
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
MAKE_OBJ_TYPE=DLL
|
||||
|
||||
LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET
|
||||
|
||||
EXPORTS = \
|
||||
nsCacheService.h \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsCache.obj \
|
||||
.\$(OBJDIR)\nsCacheEntry.obj \
|
||||
.\$(OBJDIR)\nsCacheEntryDescriptor.obj \
|
||||
.\$(OBJDIR)\nsCacheMetaData.obj \
|
||||
.\$(OBJDIR)\nsCacheModule.obj \
|
||||
.\$(OBJDIR)\nsCacheService.obj \
|
||||
.\$(OBJDIR)\nsCacheSession.obj \
|
||||
.\$(OBJDIR)\nsDiskCacheBinding.obj \
|
||||
.\$(OBJDIR)\nsDiskCacheBlockFile.obj \
|
||||
.\$(OBJDIR)\nsDiskCacheDevice.obj \
|
||||
.\$(OBJDIR)\nsDiskCacheEntry.obj \
|
||||
.\$(OBJDIR)\nsDiskCacheMap.obj \
|
||||
.\$(OBJDIR)\nsMemoryCacheDevice.obj \
|
||||
$(NULL)
|
||||
|
||||
|
||||
LLIBS = \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
|
||||
clobber::
|
||||
$(RM) $(DIST)\bin\components\$(DLLNAME).dll
|
||||
$(RM) $(DIST)\lib\$(DLLNAME).lib
|
||||
388
mozilla/netwerk/cache/src/nsANSIFileStreams.cpp
vendored
388
mozilla/netwerk/cache/src/nsANSIFileStreams.cpp
vendored
@@ -1,388 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsANSIFileStreams.cpp, released March 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsANSIFileStreams.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsANSIInputStream, nsIInputStream, nsISeekableStream);
|
||||
|
||||
nsANSIInputStream::nsANSIInputStream() : mFile(nsnull), mSize(0)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsANSIInputStream::~nsANSIInputStream()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
nsresult nsANSIInputStream::Open(nsILocalFile* file)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = file->OpenANSIFileDesc("rb", &mFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (::fseek(mFile, 0, SEEK_END) != 0) return NS_ERROR_FAILURE;
|
||||
mSize = ::ftell(mFile);
|
||||
::fseek(mFile, 0, SEEK_SET);
|
||||
rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Close()
|
||||
{
|
||||
if (mFile) {
|
||||
::fclose(mFile);
|
||||
mFile = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Available(PRUint32 * result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = (mSize - ::ftell(mFile));
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Read(char * buf, PRUint32 count, PRUint32 *result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::fread(buf, 1, count, mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::GetNonBlocking(PRBool *aNonBlocking)
|
||||
{
|
||||
*aNonBlocking = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::GetObserver(nsIInputStreamObserver * *aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::SetObserver(nsIInputStreamObserver * aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Seek(PRInt32 whence, PRInt32 offset)
|
||||
{
|
||||
if (mFile) {
|
||||
::fseek(mFile, offset, whence);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Tell(PRUint32 * result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::ftell(mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsANSIOutputStream, nsIOutputStream, nsISeekableStream);
|
||||
|
||||
nsANSIOutputStream::nsANSIOutputStream() : mFile(nsnull)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsANSIOutputStream::~nsANSIOutputStream()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
nsresult nsANSIOutputStream::Open(nsILocalFile* file)
|
||||
{
|
||||
nsresult rv = file->OpenANSIFileDesc("wb", &mFile);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Close()
|
||||
{
|
||||
if (mFile) {
|
||||
::fclose(mFile);
|
||||
mFile = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Flush()
|
||||
{
|
||||
if (mFile) {
|
||||
::fflush(mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Write(const char *buffer, PRUint32 count, PRUint32 *result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::fwrite(buffer, 1, count, mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::WriteFrom(nsIInputStream *input, PRUint32 count, PRUint32 *actualCount)
|
||||
{
|
||||
nsresult rv;
|
||||
char buffer[BUFSIZ];
|
||||
PRUint32 totalCount = count;
|
||||
*actualCount = 0;
|
||||
while (totalCount > 0) {
|
||||
count = (totalCount < BUFSIZ ? totalCount : BUFSIZ);
|
||||
rv = input->Read(buffer, count, &count);
|
||||
if (NS_FAILED(rv)) break;
|
||||
rv = Write(buffer, count, &count);
|
||||
if (NS_FAILED(rv)) break;
|
||||
totalCount -= count;
|
||||
*actualCount += count;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::GetNonBlocking(PRBool *aNonBlocking)
|
||||
{
|
||||
*aNonBlocking = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsANSIOutputStream::SetNonBlocking(PRBool aNonBlocking)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::GetObserver(nsIOutputStreamObserver * *aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHODIMP nsANSIOutputStream::SetObserver(nsIOutputStreamObserver * aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Seek(PRInt32 whence, PRInt32 offset)
|
||||
{
|
||||
if (mFile) {
|
||||
::fseek(mFile, offset, whence);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Tell(PRUint32 * result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::ftell(mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
///////
|
||||
|
||||
NS_IMPL_ISUPPORTS3(nsANSIFileStream, nsIInputStream, nsIOutputStream, nsISeekableStream);
|
||||
|
||||
nsANSIFileStream::nsANSIFileStream() : mFile(nsnull), mSize(0)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsANSIFileStream::~nsANSIFileStream()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Open(nsILocalFile* file)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = file->OpenANSIFileDesc("rb+", &mFile);
|
||||
if (NS_FAILED(rv)) {
|
||||
rv = rv = file->OpenANSIFileDesc("wb+", &mFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
// compute size of file.
|
||||
if (::fseek(mFile, 0, SEEK_END) != 0) return NS_ERROR_FAILURE;
|
||||
mSize = ::ftell(mFile);
|
||||
::fseek(mFile, 0, SEEK_SET);
|
||||
rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Close()
|
||||
{
|
||||
if (mFile) {
|
||||
::fclose(mFile);
|
||||
mFile = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Available(PRUint32 * result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = (mSize - ::ftell(mFile));
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Read(char * buf, PRUint32 count, PRUint32 *result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::fread(buf, 1, count, mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::GetNonBlocking(PRBool *aNonBlocking)
|
||||
{
|
||||
*aNonBlocking = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::GetObserver(nsIInputStreamObserver * *aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::SetObserver(nsIInputStreamObserver * aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Flush()
|
||||
{
|
||||
if (mFile) {
|
||||
::fflush(mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Write(const char *buffer, PRUint32 count, PRUint32 *result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::fwrite(buffer, 1, count, mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::WriteFrom(nsIInputStream *input, PRUint32 count, PRUint32 *actualCount)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
PRUint32 totalCount = count;
|
||||
*actualCount = 0;
|
||||
while (totalCount > 0) {
|
||||
count = (totalCount < BUFSIZ ? totalCount : BUFSIZ);
|
||||
nsresult rv = input->Read(buffer, count, &count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = Write(buffer, count, &count);
|
||||
totalCount -= count;
|
||||
*actualCount += count;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::SetNonBlocking(PRBool aNonBlocking)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::GetObserver(nsIOutputStreamObserver * *aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::SetObserver(nsIOutputStreamObserver * aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Seek(PRInt32 whence, PRInt32 offset)
|
||||
{
|
||||
if (mFile) {
|
||||
::fseek(mFile, offset, whence);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Tell(PRUint32 * result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::ftell(mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
80
mozilla/netwerk/cache/src/nsANSIFileStreams.h
vendored
80
mozilla/netwerk/cache/src/nsANSIFileStreams.h
vendored
@@ -1,80 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsANSIFileStreams.h, released March 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsANSIFileStreams_h_
|
||||
#define _nsANSIFileStreams_h_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "nsIFileStreams.h"
|
||||
|
||||
class nsANSIInputStream : public nsIInputStream, public nsISeekableStream {
|
||||
FILE* mFile;
|
||||
PRUint32 mSize;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIINPUTSTREAM
|
||||
NS_DECL_NSISEEKABLESTREAM
|
||||
|
||||
nsANSIInputStream();
|
||||
virtual ~nsANSIInputStream();
|
||||
nsresult Open(nsILocalFile* file);
|
||||
};
|
||||
|
||||
class nsANSIOutputStream : public nsIOutputStream, public nsISeekableStream {
|
||||
FILE* mFile;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOUTPUTSTREAM
|
||||
NS_DECL_NSISEEKABLESTREAM
|
||||
|
||||
nsANSIOutputStream();
|
||||
virtual ~nsANSIOutputStream();
|
||||
nsresult Open(nsILocalFile* file);
|
||||
};
|
||||
|
||||
class nsANSIFileStream : public nsIInputStream, public nsIOutputStream, public nsISeekableStream {
|
||||
FILE* mFile;
|
||||
PRUint32 mSize;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIINPUTSTREAM
|
||||
|
||||
// NS_DECL_NSIOUTPUTSTREAM
|
||||
// XXX must only declare additional methods introduced by nsIOutputStream.
|
||||
NS_IMETHOD Flush(void);
|
||||
NS_IMETHOD Write(const char *buf, PRUint32 count, PRUint32 *_retval);
|
||||
NS_IMETHOD WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval);
|
||||
NS_IMETHOD WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval);
|
||||
NS_IMETHOD SetNonBlocking(PRBool aNonBlocking);
|
||||
NS_IMETHOD GetObserver(nsIOutputStreamObserver * *aObserver);
|
||||
NS_IMETHOD SetObserver(nsIOutputStreamObserver * aObserver);
|
||||
|
||||
NS_DECL_NSISEEKABLESTREAM
|
||||
|
||||
NS_EXPORT nsANSIFileStream();
|
||||
virtual ~nsANSIFileStream();
|
||||
NS_IMETHOD Open(nsILocalFile* file);
|
||||
};
|
||||
|
||||
#endif // _nsANSIFileStreams_h_
|
||||
119
mozilla/netwerk/cache/src/nsCache.cpp
vendored
119
mozilla/netwerk/cache/src/nsCache.cpp
vendored
@@ -1,119 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCache.cpp, released March 18, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsCache.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
|
||||
/**
|
||||
* Cache Service Utility Functions
|
||||
*/
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
PRLogModuleInfo * gCacheLog = nsnull;
|
||||
|
||||
void
|
||||
CacheLogInit()
|
||||
{
|
||||
if (gCacheLog) return;
|
||||
gCacheLog = PR_NewLogModule("cache");
|
||||
NS_ASSERTION(gCacheLog, "\n### failed to allocate cache log.\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
PRUint32
|
||||
SecondsFromPRTime(PRTime prTime)
|
||||
{
|
||||
PRInt64 microSecondsPerSecond, intermediateResult;
|
||||
PRUint32 seconds;
|
||||
|
||||
LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC);
|
||||
LL_DIV(intermediateResult, prTime, microSecondsPerSecond);
|
||||
LL_L2UI(seconds, intermediateResult);
|
||||
return seconds;
|
||||
}
|
||||
|
||||
|
||||
PRTime
|
||||
PRTimeFromSeconds(PRUint32 seconds)
|
||||
{
|
||||
PRInt64 microSecondsPerSecond, intermediateResult;
|
||||
PRTime prTime;
|
||||
|
||||
LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC);
|
||||
LL_UI2L(intermediateResult, seconds);
|
||||
LL_MUL(prTime, intermediateResult, microSecondsPerSecond);
|
||||
return prTime;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
ClientIDFromCacheKey(const nsAReadableCString& key, char ** result)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
*result = nsnull;
|
||||
|
||||
nsReadingIterator<char> colon;
|
||||
key.BeginReading(colon);
|
||||
|
||||
nsReadingIterator<char> start;
|
||||
key.BeginReading(start);
|
||||
|
||||
nsReadingIterator<char> end;
|
||||
key.EndReading(end);
|
||||
|
||||
if (FindCharInReadable(':', colon, end)) {
|
||||
*result = ToNewCString( Substring(start, colon));
|
||||
if (!*result) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "FindCharInRead failed to find ':'");
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
ClientKeyFromCacheKey(const nsAReadableCString& key, char ** result)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
*result = nsnull;
|
||||
|
||||
nsReadingIterator<char> start;
|
||||
key.BeginReading(start);
|
||||
|
||||
nsReadingIterator<char> end;
|
||||
key.EndReading(end);
|
||||
|
||||
if (FindCharInReadable(':', start, end)) {
|
||||
++start; // advance past clientID ':' delimiter
|
||||
*result = ToNewCString( Substring(start, end));
|
||||
if (!*result) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "FindCharInRead failed to find ':'");
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
63
mozilla/netwerk/cache/src/nsCache.h
vendored
63
mozilla/netwerk/cache/src/nsCache.h
vendored
@@ -1,63 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCache.h, released March 18, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Cache Service Utility Functions
|
||||
*/
|
||||
|
||||
#ifndef _nsCache_h_
|
||||
#define _nsCache_h_
|
||||
|
||||
#include "nsAReadableString.h"
|
||||
#include "prtime.h"
|
||||
#include "nsError.h"
|
||||
#include "prlog.h"
|
||||
|
||||
// PR_LOG args = "format string", arg, arg, ...
|
||||
#if defined(PR_LOGGING)
|
||||
extern PRLogModuleInfo * gCacheLog;
|
||||
void CacheLogInit();
|
||||
#define CACHE_LOG_INIT() CacheLogInit()
|
||||
#define CACHE_LOG_ALWAYS(args) PR_LOG(gCacheLog, PR_LOG_ALWAYS, args)
|
||||
#define CACHE_LOG_ERROR(args) PR_LOG(gCacheLog, PR_LOG_ERROR, args)
|
||||
#define CACHE_LOG_WARNING(args) PR_LOG(gCacheLog, PR_LOG_WARNING, args)
|
||||
#define CACHE_LOG_DEBUG(args) PR_LOG(gCacheLog, PR_LOG_DEBUG, args)
|
||||
#else
|
||||
#define CACHE_LOG_INIT() {}
|
||||
#define CACHE_LOG_ALWAYS(args) {}
|
||||
#define CACHE_LOG_ERROR(args) {}
|
||||
#define CACHE_LOG_WARNING(args) {}
|
||||
#define CACHE_LOG_DEBUG(args) {}
|
||||
#endif
|
||||
|
||||
|
||||
extern PRUint32 SecondsFromPRTime(PRTime prTime);
|
||||
extern PRTime PRTimeFromSeconds(PRUint32 seconds);
|
||||
|
||||
|
||||
extern nsresult ClientIDFromCacheKey(const nsAReadableCString& key, char ** result);
|
||||
extern nsresult ClientKeyFromCacheKey(const nsAReadableCString& key, char ** result);
|
||||
|
||||
#endif // _nsCache_h
|
||||
72
mozilla/netwerk/cache/src/nsCacheDevice.h
vendored
72
mozilla/netwerk/cache/src/nsCacheDevice.h
vendored
@@ -1,72 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheDevice.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheDevice_h_
|
||||
#define _nsCacheDevice_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsError.h"
|
||||
#include "nsICache.h"
|
||||
|
||||
class nsIFile;
|
||||
class nsCString;
|
||||
class nsCacheEntry;
|
||||
class nsICacheVisitor;
|
||||
class nsITransport;
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheDevice
|
||||
*******************************************************************************/
|
||||
class nsCacheDevice {
|
||||
public:
|
||||
virtual ~nsCacheDevice() {}
|
||||
|
||||
virtual nsresult Init() = 0;
|
||||
virtual nsresult Shutdown() = 0;
|
||||
|
||||
virtual const char * GetDeviceID(void) = 0;
|
||||
virtual nsCacheEntry * FindEntry( nsCString * key ) = 0;
|
||||
|
||||
virtual nsresult DeactivateEntry( nsCacheEntry * entry ) = 0;
|
||||
virtual nsresult BindEntry( nsCacheEntry * entry ) = 0;
|
||||
virtual void DoomEntry( nsCacheEntry * entry ) = 0;
|
||||
|
||||
virtual nsresult GetTransportForEntry( nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport **result ) = 0;
|
||||
|
||||
virtual nsresult GetFileForEntry( nsCacheEntry * entry,
|
||||
nsIFile ** result ) = 0;
|
||||
|
||||
virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize ) = 0;
|
||||
|
||||
virtual nsresult Visit(nsICacheVisitor * visitor) = 0;
|
||||
|
||||
/**
|
||||
* Device must evict entries associated with clientID. If clientID == nsnull, all
|
||||
* entries must be evicted. Active entries must be doomed, rather than evicted.
|
||||
*/
|
||||
virtual nsresult EvictEntries(const char * clientID) = 0;
|
||||
};
|
||||
|
||||
#endif // _nsCacheDevice_h_
|
||||
663
mozilla/netwerk/cache/src/nsCacheEntry.cpp
vendored
663
mozilla/netwerk/cache/src/nsCacheEntry.cpp
vendored
@@ -1,663 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheEntry.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsCacheEntry.h"
|
||||
#include "nsCacheEntryDescriptor.h"
|
||||
#include "nsCacheMetaData.h"
|
||||
#include "nsCacheRequest.h"
|
||||
#include "nsError.h"
|
||||
#include "nsICacheService.h"
|
||||
#include "nsCache.h"
|
||||
#include "nsCacheDevice.h"
|
||||
|
||||
|
||||
nsCacheEntry::nsCacheEntry(nsCString * key,
|
||||
PRBool streamBased,
|
||||
nsCacheStoragePolicy storagePolicy)
|
||||
: mKey(key),
|
||||
mFetchCount(0),
|
||||
mLastFetched(0),
|
||||
mExpirationTime(0),
|
||||
mFlags(0),
|
||||
mDataSize(0),
|
||||
mMetaSize(0),
|
||||
mCacheDevice(nsnull),
|
||||
mData(nsnull),
|
||||
mMetaData(nsnull)
|
||||
{
|
||||
PR_INIT_CLIST(this);
|
||||
PR_INIT_CLIST(&mRequestQ);
|
||||
PR_INIT_CLIST(&mDescriptorQ);
|
||||
|
||||
if (streamBased) MarkStreamBased();
|
||||
SetStoragePolicy(storagePolicy);
|
||||
}
|
||||
|
||||
|
||||
static void* PR_CALLBACK
|
||||
CacheElementReleaseEventHandler(PLEvent *self)
|
||||
{
|
||||
nsISupports * element = (nsISupports *)PL_GetEventOwner(self);
|
||||
NS_RELEASE(element);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void PR_CALLBACK
|
||||
CacheElementReleaseDestroyHandler(PLEvent *self)
|
||||
{
|
||||
delete self;
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntry::~nsCacheEntry()
|
||||
{
|
||||
delete mKey;
|
||||
delete mMetaData;
|
||||
|
||||
if (IsStreamData()) return;
|
||||
|
||||
// proxy release of of memory cache nsISupports objects
|
||||
if (!mData) {
|
||||
NS_ASSERTION(!mEventQ, "### ~nsCacheEntry: mEventQ but no mData");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mEventQ) {
|
||||
NS_ASSERTION(!mData, "### ~nsCacheEntry: mData, but no eventQ");
|
||||
return;
|
||||
}
|
||||
|
||||
PLEvent * event = new PLEvent;
|
||||
if (!event) {
|
||||
// XXX warning
|
||||
return;
|
||||
}
|
||||
|
||||
nsISupports * data = mData;
|
||||
NS_ADDREF(data); // this reference will be owned by the event
|
||||
mData = nsnull; // release our reference before switching threads
|
||||
|
||||
PL_InitEvent(event,
|
||||
data,
|
||||
CacheElementReleaseEventHandler,
|
||||
CacheElementReleaseDestroyHandler);
|
||||
|
||||
mEventQ->PostEvent(event);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::Create( const char * key,
|
||||
PRBool streamBased,
|
||||
nsCacheStoragePolicy storagePolicy,
|
||||
nsCacheDevice * device,
|
||||
nsCacheEntry ** result)
|
||||
{
|
||||
nsCString* newKey = new nsCString(key);
|
||||
if (!newKey) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCacheEntry* entry = new nsCacheEntry(newKey, streamBased, storagePolicy);
|
||||
if (!entry) { delete newKey; return NS_ERROR_OUT_OF_MEMORY; }
|
||||
|
||||
entry->SetCacheDevice(device);
|
||||
|
||||
*result = entry;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsCacheEntry::Fetched()
|
||||
{
|
||||
mLastFetched = SecondsFromPRTime(PR_Now());
|
||||
++mFetchCount;
|
||||
MarkEntryDirty();
|
||||
}
|
||||
|
||||
|
||||
const char *
|
||||
nsCacheEntry::GetDeviceID()
|
||||
{
|
||||
if (mCacheDevice) return mCacheDevice->GetDeviceID();
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::GetData(nsISupports **result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
NS_IF_ADDREF(*result = mData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntry::TouchData()
|
||||
{
|
||||
mLastModified = SecondsFromPRTime(PR_Now());
|
||||
MarkDataDirty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::GetMetaDataElement( const nsAReadableCString& key,
|
||||
nsAReadableCString ** value)
|
||||
{
|
||||
*value = mMetaData ? mMetaData->GetElement(&key) : nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::SetMetaDataElement( const nsAReadableCString& key,
|
||||
const nsAReadableCString& value)
|
||||
{
|
||||
if (!mMetaData) {
|
||||
mMetaData = nsCacheMetaData::Create();
|
||||
if (!mMetaData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult rv = mMetaData->SetElement(key, value);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
mMetaSize = mMetaData->Size(); // calc new meta data size
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::VisitMetaDataElements( nsICacheMetaDataVisitor * visitor)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(visitor);
|
||||
|
||||
if (mMetaData)
|
||||
mMetaData->VisitElements(visitor);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::FlattenMetaData(char ** data, PRUint32 * size)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(size);
|
||||
|
||||
if (mMetaData)
|
||||
return mMetaData->FlattenMetaData(data, size);
|
||||
|
||||
if (data) *data = nsnull;
|
||||
*size = 0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::UnflattenMetaData(char * data, PRUint32 size)
|
||||
{
|
||||
delete mMetaData;
|
||||
mMetaData = nsCacheMetaData::Create();
|
||||
if (!mMetaData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsresult rv = mMetaData->UnflattenMetaData(data, size);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mMetaSize = mMetaData->Size();
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntry::TouchMetaData()
|
||||
{
|
||||
mLastModified = SecondsFromPRTime(PR_Now());
|
||||
MarkMetaDataDirty();
|
||||
}
|
||||
|
||||
#if 0
|
||||
nsresult
|
||||
nsCacheEntry::GetKeyValueArray(nsCacheMetaDataKeyValuePair ** array,
|
||||
PRUint32 * count)
|
||||
{
|
||||
if (!array || !count) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (!mMetaData) {
|
||||
*array = nsnull;
|
||||
*count = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
return mMetaData->GetKeyValueArray(array, count);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::GetSecurityInfo( nsISupports ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
NS_IF_ADDREF(*result = mSecurityInfo);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* cache entry states
|
||||
* 0 descriptors (new entry)
|
||||
* 0 descriptors (existing, bound entry)
|
||||
* n descriptors (existing, bound entry) valid
|
||||
* n descriptors (existing, bound entry) not valid (wait until valid or doomed)
|
||||
*/
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::RequestAccess(nsCacheRequest * request, nsCacheAccessMode *accessGranted)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!IsInitialized()) {
|
||||
// brand new, unbound entry
|
||||
request->mKey = nsnull; // steal ownership of the key string
|
||||
if (request->IsStreamBased()) MarkStreamBased();
|
||||
MarkInitialized();
|
||||
|
||||
*accessGranted = request->AccessRequested() & nsICache::ACCESS_WRITE;
|
||||
NS_ASSERTION(*accessGranted, "new cache entry for READ-ONLY request");
|
||||
PR_APPEND_LINK(request, &mRequestQ);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (IsDoomed()) return NS_ERROR_CACHE_ENTRY_DOOMED;
|
||||
|
||||
if (IsStreamData() != request->IsStreamBased()) {
|
||||
*accessGranted = nsICache::ACCESS_NONE;
|
||||
return request->IsStreamBased() ?
|
||||
NS_ERROR_CACHE_DATA_IS_NOT_STREAM : NS_ERROR_CACHE_DATA_IS_STREAM;
|
||||
}
|
||||
|
||||
if (PR_CLIST_IS_EMPTY(&mDescriptorQ)) {
|
||||
// 1st descriptor for existing bound entry
|
||||
*accessGranted = request->AccessRequested();
|
||||
if (*accessGranted & nsICache::ACCESS_WRITE) {
|
||||
MarkInvalid();
|
||||
} else {
|
||||
MarkValid();
|
||||
}
|
||||
} else {
|
||||
// nth request for existing, bound entry
|
||||
*accessGranted = request->AccessRequested() & ~nsICache::ACCESS_WRITE;
|
||||
if (!IsValid())
|
||||
rv = NS_ERROR_CACHE_WAIT_FOR_VALIDATION;
|
||||
}
|
||||
PR_APPEND_LINK(request,&mRequestQ);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::CreateDescriptor(nsCacheRequest * request,
|
||||
nsCacheAccessMode accessGranted,
|
||||
nsICacheEntryDescriptor ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(request && result);
|
||||
|
||||
nsCacheEntryDescriptor * descriptor =
|
||||
new nsCacheEntryDescriptor(this, accessGranted);
|
||||
|
||||
// XXX check request is on q
|
||||
PR_REMOVE_AND_INIT_LINK(request); // remove request regardless of success
|
||||
|
||||
if (descriptor == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PR_APPEND_LINK(descriptor, &mDescriptorQ);
|
||||
|
||||
NS_ADDREF(*result = descriptor);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsCacheEntry::RemoveRequest(nsCacheRequest * request)
|
||||
{
|
||||
// XXX if debug: verify this request belongs to this entry
|
||||
PR_REMOVE_AND_INIT_LINK(request);
|
||||
|
||||
// return true if this entry should stay active
|
||||
return !((PR_CLIST_IS_EMPTY(&mRequestQ)) &&
|
||||
(PR_CLIST_IS_EMPTY(&mDescriptorQ)));
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsCacheEntry::RemoveDescriptor(nsCacheEntryDescriptor * descriptor)
|
||||
{
|
||||
// XXX if debug: verify this descriptor belongs to this entry
|
||||
PR_REMOVE_AND_INIT_LINK(descriptor);
|
||||
|
||||
if (!PR_CLIST_IS_EMPTY(&mDescriptorQ))
|
||||
return PR_TRUE; // stay active if we still have open descriptors
|
||||
|
||||
if (PR_CLIST_IS_EMPTY(&mRequestQ))
|
||||
return PR_FALSE; // no descriptors or requests, we can deactivate
|
||||
|
||||
return PR_TRUE; // find next best request to give a descriptor to
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntry::DetachDescriptors(void)
|
||||
{
|
||||
nsCacheEntryDescriptor * descriptor =
|
||||
(nsCacheEntryDescriptor *)PR_LIST_HEAD(&mDescriptorQ);
|
||||
|
||||
while (descriptor != &mDescriptorQ) {
|
||||
nsCacheEntryDescriptor * nextDescriptor =
|
||||
(nsCacheEntryDescriptor *)PR_NEXT_LINK(descriptor);
|
||||
|
||||
descriptor->ClearCacheEntry();
|
||||
PR_REMOVE_AND_INIT_LINK(descriptor);
|
||||
descriptor = nextDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryInfo - for implementing about:cache
|
||||
*****************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsCacheEntryInfo, nsICacheEntryInfo);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetClientID(char ** clientID)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(clientID);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return ClientIDFromCacheKey(*mCacheEntry->Key(), clientID);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetDeviceID(char ** deviceID)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(deviceID);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*deviceID = nsCRT::strdup(mCacheEntry->GetDeviceID());
|
||||
return *deviceID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetKey(char ** key)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(key);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return ClientKeyFromCacheKey(*mCacheEntry->Key(), key);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetFetchCount(PRInt32 * fetchCount)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(fetchCount);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*fetchCount = mCacheEntry->FetchCount();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetLastFetched(PRUint32 * lastFetched)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(lastFetched);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*lastFetched = mCacheEntry->LastFetched();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetLastModified(PRUint32 * lastModified)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(lastModified);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*lastModified = mCacheEntry->LastModified();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetExpirationTime(PRUint32 * expirationTime)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(expirationTime);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*expirationTime = mCacheEntry->ExpirationTime();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetDataSize(PRUint32 * dataSize)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(dataSize);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*dataSize = mCacheEntry->DataSize();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::IsStreamBased(PRBool * result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->IsStreamData();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryHashTable
|
||||
*****************************************************************************/
|
||||
|
||||
PLDHashTableOps
|
||||
nsCacheEntryHashTable::ops =
|
||||
{
|
||||
PL_DHashAllocTable,
|
||||
PL_DHashFreeTable,
|
||||
GetKey,
|
||||
HashKey,
|
||||
MatchEntry,
|
||||
MoveEntry,
|
||||
ClearEntry,
|
||||
PL_DHashFinalizeStub
|
||||
};
|
||||
|
||||
|
||||
nsCacheEntryHashTable::nsCacheEntryHashTable()
|
||||
: initialized(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntryHashTable::~nsCacheEntryHashTable()
|
||||
{
|
||||
if (initialized)
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryHashTable::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
initialized = PL_DHashTableInit(&table, &ops, nsnull,
|
||||
sizeof(nsCacheEntryHashTableEntry), 512);
|
||||
|
||||
if (!initialized) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
nsCacheEntryHashTable::Shutdown()
|
||||
{
|
||||
if (initialized) {
|
||||
PL_DHashTableFinish(&table);
|
||||
initialized = PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntry *
|
||||
nsCacheEntryHashTable::GetEntry( const nsCString * key)
|
||||
{
|
||||
PLDHashEntryHdr *hashEntry;
|
||||
nsCacheEntry *result = nsnull;
|
||||
|
||||
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
||||
if (!initialized) return nsnull;
|
||||
|
||||
hashEntry = PL_DHashTableOperate(&table, key, PL_DHASH_LOOKUP);
|
||||
if (PL_DHASH_ENTRY_IS_BUSY(hashEntry)) {
|
||||
result = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryHashTable::AddEntry( nsCacheEntry *cacheEntry)
|
||||
{
|
||||
PLDHashEntryHdr *hashEntry;
|
||||
|
||||
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
||||
if (!initialized) return NS_ERROR_NOT_INITIALIZED;
|
||||
if (!cacheEntry) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
hashEntry = PL_DHashTableOperate(&table, cacheEntry->mKey, PL_DHASH_ADD);
|
||||
#ifndef DEBUG_dougt
|
||||
NS_ASSERTION(((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry == 0,
|
||||
"### nsCacheEntryHashTable::AddEntry - entry already used");
|
||||
#endif
|
||||
((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry = cacheEntry;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntryHashTable::RemoveEntry( nsCacheEntry *cacheEntry)
|
||||
{
|
||||
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
||||
NS_ASSERTION(cacheEntry, "### cacheEntry == nsnull");
|
||||
|
||||
if (!initialized) return; // NS_ERROR_NOT_INITIALIZED
|
||||
|
||||
#if DEBUG
|
||||
// XXX debug code to make sure we have the entry we're trying to remove
|
||||
nsCacheEntry *check = GetEntry(cacheEntry->mKey);
|
||||
NS_ASSERTION(check == cacheEntry, "### Attempting to remove unknown cache entry!!!");
|
||||
#endif
|
||||
(void) PL_DHashTableOperate(&table, cacheEntry->mKey, PL_DHASH_REMOVE);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntryHashTable::VisitEntries( nsCacheEntryHashTable::Visitor *visitor)
|
||||
{
|
||||
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
||||
if (!initialized) return; // NS_ERROR_NOT_INITIALIZED
|
||||
PL_DHashTableEnumerate(&table, VisitEntry, visitor);
|
||||
}
|
||||
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheEntryHashTable::VisitEntry(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hashEntry,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheEntry *cacheEntry = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
||||
nsCacheEntryHashTable::Visitor *visitor = (nsCacheEntryHashTable::Visitor*) arg;
|
||||
return (visitor->VisitEntry(cacheEntry) ? PL_DHASH_NEXT : PL_DHASH_STOP);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash table operation callback functions
|
||||
*/
|
||||
const void * PR_CALLBACK
|
||||
nsCacheEntryHashTable::GetKey( PLDHashTable * /*table*/, PLDHashEntryHdr *hashEntry)
|
||||
{
|
||||
nsCacheEntry *cacheEntry = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
||||
return cacheEntry->mKey;
|
||||
}
|
||||
|
||||
|
||||
PLDHashNumber PR_CALLBACK
|
||||
nsCacheEntryHashTable::HashKey( PLDHashTable *table, const void *key)
|
||||
{
|
||||
return PL_DHashStringKey(table,((nsCString *)key)->get());
|
||||
}
|
||||
|
||||
PRBool PR_CALLBACK
|
||||
nsCacheEntryHashTable::MatchEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr * hashEntry,
|
||||
const void * key)
|
||||
{
|
||||
NS_ASSERTION(key != nsnull, "### nsCacheEntryHashTable::MatchEntry : null key");
|
||||
nsCacheEntry *cacheEntry = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
||||
|
||||
return nsStr::StrCompare(*cacheEntry->mKey, *(nsCString *)key, -1, PR_FALSE) == 0;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheEntryHashTable::MoveEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr *from,
|
||||
PLDHashEntryHdr *to)
|
||||
{
|
||||
((nsCacheEntryHashTableEntry *)to)->cacheEntry =
|
||||
((nsCacheEntryHashTableEntry *)from)->cacheEntry;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheEntryHashTable::ClearEntry(PLDHashTable * /* table */,
|
||||
PLDHashEntryHdr * hashEntry)
|
||||
{
|
||||
((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry = 0;
|
||||
}
|
||||
|
||||
330
mozilla/netwerk/cache/src/nsCacheEntry.h
vendored
330
mozilla/netwerk/cache/src/nsCacheEntry.h
vendored
@@ -1,330 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheEntry.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheEntry_h_
|
||||
#define _nsCacheEntry_h_
|
||||
|
||||
#include "nsICache.h"
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "nsCacheMetaData.h"
|
||||
|
||||
#include "nspr.h"
|
||||
#include "pldhash.h"
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsAReadableString.h"
|
||||
#include "nsIEventQueue.h"
|
||||
|
||||
|
||||
class nsCacheDevice;
|
||||
class nsCacheMetaData;
|
||||
class nsCacheRequest;
|
||||
class nsCacheEntryDescriptor;
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntry
|
||||
*******************************************************************************/
|
||||
class nsCacheEntry : public PRCList
|
||||
{
|
||||
public:
|
||||
|
||||
nsCacheEntry(nsCString * key,
|
||||
PRBool streamBased,
|
||||
nsCacheStoragePolicy storagePolicy);
|
||||
~nsCacheEntry();
|
||||
|
||||
|
||||
static nsresult Create( const char * key,
|
||||
PRBool streamBased,
|
||||
nsCacheStoragePolicy storagePolicy,
|
||||
nsCacheDevice * device,
|
||||
nsCacheEntry ** result);
|
||||
|
||||
nsCString * Key() { return mKey; }
|
||||
|
||||
PRInt32 FetchCount() { return mFetchCount;}
|
||||
void SetFetchCount( PRInt32 count) { mFetchCount = count;}
|
||||
void Fetched();
|
||||
|
||||
PRUint32 LastFetched() { return mLastFetched;}
|
||||
void SetLastFetched( PRUint32 lastFetched) { mLastFetched = lastFetched;}
|
||||
|
||||
PRUint32 LastModified() { return mLastModified;}
|
||||
void SetLastModified( PRUint32 lastModified) { mLastModified = lastModified;}
|
||||
|
||||
PRUint32 ExpirationTime() { return mExpirationTime;}
|
||||
void SetExpirationTime( PRUint32 expires) { mExpirationTime = expires;}
|
||||
|
||||
PRUint32 Size() { return mDataSize + mMetaSize; }
|
||||
|
||||
nsCacheDevice * CacheDevice() { return mCacheDevice;}
|
||||
void SetCacheDevice( nsCacheDevice * device) { mCacheDevice = device;}
|
||||
const char * GetDeviceID();
|
||||
|
||||
/**
|
||||
* Data accessors
|
||||
*/
|
||||
nsresult GetData( nsISupports ** result);
|
||||
void SetData( nsISupports * data) { mData = data;}
|
||||
|
||||
PRUint32 DataSize() { return mDataSize;}
|
||||
void SetDataSize( PRUint32 size) { mDataSize = size;}
|
||||
|
||||
void TouchData();
|
||||
|
||||
nsIEventQueue * GetEventQ() { return mEventQ;}
|
||||
void SetEventQ(nsIEventQueue * eventQ) { mEventQ = dont_AddRef(eventQ);}
|
||||
|
||||
/**
|
||||
* Meta data accessors
|
||||
*/
|
||||
nsresult GetMetaDataElement( const nsAReadableCString& key,
|
||||
nsAReadableCString ** value);
|
||||
nsresult SetMetaDataElement( const nsAReadableCString& key,
|
||||
const nsAReadableCString& value);
|
||||
|
||||
nsresult VisitMetaDataElements( nsICacheMetaDataVisitor * visitor);
|
||||
|
||||
nsresult FlattenMetaData( char ** data, PRUint32 * size);
|
||||
nsresult UnflattenMetaData( char * data, PRUint32 size);
|
||||
|
||||
PRUint32 MetaDataSize() { return mMetaSize;}
|
||||
|
||||
void TouchMetaData();
|
||||
|
||||
|
||||
/**
|
||||
* Security Info accessors
|
||||
*/
|
||||
nsresult GetSecurityInfo( nsISupports ** result);
|
||||
void SetSecurityInfo( nsISupports * info) { mSecurityInfo = info; }
|
||||
|
||||
|
||||
// XXX enumerate MetaData method
|
||||
|
||||
|
||||
enum CacheEntryFlags {
|
||||
eStoragePolicyMask = 0x000000FF,
|
||||
eDoomedMask = 0x00000100,
|
||||
eEntryDirtyMask = 0x00000200,
|
||||
eDataDirtyMask = 0x00000400,
|
||||
eMetaDataDirtyMask = 0x00000800,
|
||||
eStreamDataMask = 0x00001000,
|
||||
eActiveMask = 0x00002000,
|
||||
eInitializedMask = 0x00004000,
|
||||
eValidMask = 0x00008000,
|
||||
eBindingMask = 0x00010000
|
||||
};
|
||||
|
||||
void MarkBinding() { mFlags |= eBindingMask; }
|
||||
void ClearBinding() { mFlags &= ~eBindingMask; }
|
||||
PRBool IsBinding() { return (mFlags & eBindingMask) != 0; }
|
||||
|
||||
void MarkEntryDirty() { mFlags |= eEntryDirtyMask; }
|
||||
void MarkEntryClean() { mFlags &= ~eEntryDirtyMask; }
|
||||
void MarkDataDirty() { mFlags |= eDataDirtyMask; }
|
||||
void MarkDataClean() { mFlags &= ~eDataDirtyMask; }
|
||||
void MarkMetaDataDirty() { mFlags |= eMetaDataDirtyMask; }
|
||||
void MarkMetaDataClean() { mFlags &= ~eMetaDataDirtyMask; }
|
||||
void MarkStreamData() { mFlags |= eStreamDataMask; }
|
||||
void MarkValid() { mFlags |= eValidMask; }
|
||||
void MarkInvalid() { mFlags &= ~eValidMask; }
|
||||
// void MarkAllowedInMemory() { mFlags |= eAllowedInMemoryMask; }
|
||||
// void MarkAllowedOnDisk() { mFlags |= eAllowedOnDiskMask; }
|
||||
|
||||
PRBool IsDoomed() { return (mFlags & eDoomedMask) != 0; }
|
||||
PRBool IsEntryDirty() { return (mFlags & eEntryDirtyMask) != 0; }
|
||||
PRBool IsDataDirty() { return (mFlags & eDataDirtyMask) != 0; }
|
||||
PRBool IsMetaDataDirty() { return (mFlags & eMetaDataDirtyMask) != 0; }
|
||||
PRBool IsStreamData() { return (mFlags & eStreamDataMask) != 0; }
|
||||
PRBool IsActive() { return (mFlags & eActiveMask) != 0; }
|
||||
PRBool IsInitialized() { return (mFlags & eInitializedMask) != 0; }
|
||||
PRBool IsValid() { return (mFlags & eValidMask) != 0; }
|
||||
PRBool IsInvalid() { return (mFlags & eValidMask) == 0; }
|
||||
PRBool IsInUse() { return !(PR_CLIST_IS_EMPTY(&mRequestQ) &&
|
||||
PR_CLIST_IS_EMPTY(&mDescriptorQ)); }
|
||||
PRBool IsNotInUse() { return (PR_CLIST_IS_EMPTY(&mRequestQ) &&
|
||||
PR_CLIST_IS_EMPTY(&mDescriptorQ)); }
|
||||
|
||||
|
||||
PRBool IsAllowedInMemory()
|
||||
{
|
||||
return (StoragePolicy() == nsICache::STORE_ANYWHERE) ||
|
||||
(StoragePolicy() == nsICache::STORE_IN_MEMORY);
|
||||
}
|
||||
|
||||
PRBool IsAllowedOnDisk()
|
||||
{
|
||||
return (StoragePolicy() == nsICache::STORE_ANYWHERE) ||
|
||||
(StoragePolicy() == nsICache::STORE_ON_DISK) ||
|
||||
(StoragePolicy() == nsICache::STORE_ON_DISK_AS_FILE);
|
||||
}
|
||||
|
||||
nsCacheStoragePolicy StoragePolicy()
|
||||
{
|
||||
return (nsCacheStoragePolicy)(mFlags & eStoragePolicyMask);
|
||||
}
|
||||
|
||||
void SetStoragePolicy(nsCacheStoragePolicy policy)
|
||||
{
|
||||
NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy");
|
||||
mFlags &= ~eStoragePolicyMask; // clear storage policy bits
|
||||
mFlags |= policy;
|
||||
}
|
||||
|
||||
|
||||
// methods for nsCacheService
|
||||
nsresult RequestAccess( nsCacheRequest * request, nsCacheAccessMode *accessGranted);
|
||||
nsresult CreateDescriptor( nsCacheRequest * request,
|
||||
nsCacheAccessMode accessGranted,
|
||||
nsICacheEntryDescriptor ** result);
|
||||
|
||||
// nsresult Open(nsCacheRequest *request, nsICacheEntryDescriptor ** result);
|
||||
// nsresult AsyncOpen(nsCacheRequest *request);
|
||||
PRBool RemoveRequest( nsCacheRequest * request);
|
||||
PRBool RemoveDescriptor( nsCacheEntryDescriptor * descriptor);
|
||||
|
||||
private:
|
||||
friend class nsCacheEntryHashTable;
|
||||
friend class nsCacheService;
|
||||
|
||||
void DetachDescriptors(void);
|
||||
|
||||
// internal methods
|
||||
void MarkDoomed() { mFlags |= eDoomedMask; }
|
||||
void MarkStreamBased() { mFlags |= eStreamDataMask; }
|
||||
void MarkInitialized() { mFlags |= eInitializedMask; }
|
||||
void MarkActive() { mFlags |= eActiveMask; }
|
||||
void MarkInactive() { mFlags &= ~eActiveMask; }
|
||||
|
||||
nsCString * mKey; // 4 // XXX ask scc about const'ness
|
||||
PRUint32 mFetchCount; // 4
|
||||
PRUint32 mLastFetched; // 4
|
||||
PRUint32 mLastModified; // 4
|
||||
PRUint32 mLastValidated; // 4
|
||||
PRUint32 mExpirationTime; // 4
|
||||
PRUint32 mFlags; // 4
|
||||
PRUint32 mDataSize; // 4
|
||||
PRUint32 mMetaSize; // 4
|
||||
nsCacheDevice * mCacheDevice; // 4
|
||||
nsCOMPtr<nsISupports> mSecurityInfo; //
|
||||
nsCOMPtr<nsISupports> mData; //
|
||||
nsCOMPtr<nsIEventQueue> mEventQ; // event queue for mData (for mem object cache)
|
||||
nsCacheMetaData * mMetaData; // 4
|
||||
PRCList mRequestQ; // 8
|
||||
PRCList mDescriptorQ; // 8
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryInfo
|
||||
*******************************************************************************/
|
||||
class nsCacheEntryInfo : public nsICacheEntryInfo {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHEENTRYINFO
|
||||
|
||||
nsCacheEntryInfo(nsCacheEntry* entry)
|
||||
: mCacheEntry(entry)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
virtual ~nsCacheEntryInfo() {}
|
||||
void DetachEntry() { mCacheEntry = nsnull; }
|
||||
|
||||
private:
|
||||
nsCacheEntry * mCacheEntry;
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryHashTable
|
||||
*******************************************************************************/
|
||||
typedef struct {
|
||||
PLDHashNumber keyHash;
|
||||
nsCacheEntry *cacheEntry;
|
||||
} nsCacheEntryHashTableEntry;
|
||||
|
||||
|
||||
class nsCacheEntryHashTable
|
||||
{
|
||||
public:
|
||||
nsCacheEntryHashTable();
|
||||
~nsCacheEntryHashTable();
|
||||
|
||||
nsresult Init();
|
||||
void Shutdown();
|
||||
|
||||
nsCacheEntry *GetEntry( const nsCString * key);
|
||||
nsresult AddEntry( nsCacheEntry *entry);
|
||||
void RemoveEntry( nsCacheEntry *entry);
|
||||
|
||||
// XXX enumerate entries?
|
||||
class Visitor {
|
||||
public:
|
||||
virtual PRBool VisitEntry( nsCacheEntry *entry) = 0;
|
||||
};
|
||||
|
||||
void VisitEntries( Visitor *visitor);
|
||||
|
||||
private:
|
||||
friend class nsCacheService; // XXX redefine interface so this isn't necessary
|
||||
|
||||
// PLDHashTable operation callbacks
|
||||
static const void * PR_CALLBACK GetKey( PLDHashTable *table, PLDHashEntryHdr *entry);
|
||||
|
||||
static PLDHashNumber PR_CALLBACK HashKey( PLDHashTable *table, const void *key);
|
||||
|
||||
static PRBool PR_CALLBACK MatchEntry( PLDHashTable * table,
|
||||
const PLDHashEntryHdr * entry,
|
||||
const void * key);
|
||||
|
||||
static void PR_CALLBACK MoveEntry( PLDHashTable *table,
|
||||
const PLDHashEntryHdr *from,
|
||||
PLDHashEntryHdr *to);
|
||||
|
||||
static void PR_CALLBACK ClearEntry( PLDHashTable *table, PLDHashEntryHdr *entry);
|
||||
|
||||
static void PR_CALLBACK Finalize( PLDHashTable *table);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK FreeCacheEntries(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
PRUint32 number,
|
||||
void * arg);
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK VisitEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
PRUint32 number,
|
||||
void * arg);
|
||||
|
||||
// member variables
|
||||
static PLDHashTableOps ops;
|
||||
PLDHashTable table;
|
||||
PRBool initialized;
|
||||
};
|
||||
|
||||
#endif // _nsCacheEntry_h_
|
||||
|
||||
647
mozilla/netwerk/cache/src/nsCacheEntryDescriptor.cpp
vendored
647
mozilla/netwerk/cache/src/nsCacheEntryDescriptor.cpp
vendored
@@ -1,647 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheEntryDescriptor.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#include "nsICache.h"
|
||||
#include "nsCache.h"
|
||||
#include "nsCacheService.h"
|
||||
#include "nsCacheEntryDescriptor.h"
|
||||
#include "nsCacheEntry.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIOutputStream.h"
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheEntryDescriptor, nsICacheEntryDescriptor)
|
||||
|
||||
|
||||
nsCacheEntryDescriptor::nsCacheEntryDescriptor(nsCacheEntry * entry,
|
||||
nsCacheAccessMode accessGranted)
|
||||
: mCacheEntry(entry),
|
||||
mAccessGranted(accessGranted)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
PR_INIT_CLIST(this);
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntryDescriptor::~nsCacheEntryDescriptor()
|
||||
{
|
||||
if (mCacheEntry)
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryDescriptor::Create(nsCacheEntry * entry, nsCacheAccessMode accessGranted,
|
||||
nsICacheEntryDescriptor ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
nsresult rv = nsnull;
|
||||
|
||||
nsCacheEntryDescriptor * descriptor =
|
||||
new nsCacheEntryDescriptor(entry, accessGranted);
|
||||
|
||||
if (descriptor == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(descriptor);
|
||||
rv = descriptor->QueryInterface(NS_GET_IID(nsICacheEntryDescriptor), (void**)result);
|
||||
NS_RELEASE(descriptor);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetClientID(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return ClientIDFromCacheKey(*(mCacheEntry->Key()), result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetDeviceID(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = nsCRT::strdup(mCacheEntry->GetDeviceID());
|
||||
return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetKey(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return ClientKeyFromCacheKey(*(mCacheEntry->Key()), result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetFetchCount(PRInt32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->FetchCount();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetLastFetched(PRUint32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->LastFetched();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetLastModified(PRUint32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->LastModified();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetExpirationTime(PRUint32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->ExpirationTime();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetExpirationTime(PRUint32 expirationTime)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
mCacheEntry->SetExpirationTime(expirationTime);
|
||||
mCacheEntry->MarkEntryDirty();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::IsStreamBased(PRBool *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->IsStreamData(); // XXX which name is better?
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::GetDataSize(PRUint32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->DataSize();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryDescriptor::RequestDataSizeChange(PRInt32 deltaSize)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsCacheService::GlobalInstance()->OnDataSizeChange(mCacheEntry, deltaSize);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// XXX review for signed/unsigned math errors
|
||||
PRUint32 newDataSize = mCacheEntry->DataSize() + deltaSize;
|
||||
mCacheEntry->SetDataSize(newDataSize);
|
||||
mCacheEntry->TouchData();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetDataSize(PRUint32 dataSize)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
// XXX review for signed/unsigned math errors
|
||||
PRInt32 deltaSize = dataSize - mCacheEntry->DataSize();
|
||||
|
||||
// this had better be NS_OK, this call instance is advisory
|
||||
nsresult rv = RequestDataSizeChange(deltaSize);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "failed SetDataSize() on memory cache object!");
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetTransport(nsITransport ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
if (!mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_NOT_STREAM;
|
||||
|
||||
NS_ADDREF(*result = &mTransportWrapper);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetCacheElement(nsISupports ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
if (mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_STREAM;
|
||||
|
||||
return mCacheEntry->GetData(result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetCacheElement(nsISupports * cacheElement)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
if (mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_STREAM;
|
||||
|
||||
mCacheEntry->SetData(cacheElement);
|
||||
mCacheEntry->TouchData();
|
||||
|
||||
return nsCacheService::GlobalInstance()->SetCacheElement(mCacheEntry, cacheElement);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetAccessGranted(nsCacheAccessMode *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = mAccessGranted;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetStoragePolicy(nsCacheStoragePolicy *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return mCacheEntry->StoragePolicy();
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetStoragePolicy(nsCacheStoragePolicy policy)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
// XXX validate policy against session?
|
||||
mCacheEntry->SetStoragePolicy(policy);
|
||||
mCacheEntry->MarkEntryDirty();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetFile(nsIFile ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return nsCacheService::GlobalInstance()->GetFileForEntry(mCacheEntry, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetSecurityInfo(nsISupports ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return mCacheEntry->GetSecurityInfo(result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetSecurityInfo(nsISupports * securityInfo)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
mCacheEntry->SetSecurityInfo(securityInfo);
|
||||
mCacheEntry->MarkEntryDirty();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::Doom()
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return nsCacheService::GlobalInstance()->DoomEntry(mCacheEntry);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::DoomAndFailPendingRequests(nsresult status)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::MarkValid()
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
nsresult rv;
|
||||
rv = nsCacheService::GlobalInstance()->ValidateEntry(mCacheEntry);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::Close()
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
// tell nsCacheService we're going away
|
||||
nsCacheService::GlobalInstance()->CloseDescriptor(this);
|
||||
mCacheEntry = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetMetaDataElement(const char *key, char ** result)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
if (!key | !result) return NS_ERROR_NULL_POINTER;
|
||||
nsAReadableCString *value;
|
||||
*result = nsnull;
|
||||
|
||||
// XXX not thread safe
|
||||
nsresult rv = mCacheEntry->GetMetaDataElement(nsLiteralCString(key), &value);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!value) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = ToNewCString(*value);
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetMetaDataElement(const char *key, const char *value)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
if (!key) return NS_ERROR_NULL_POINTER;
|
||||
// XXX not thread safe
|
||||
// XXX allow null value, for clearing key?
|
||||
nsresult rv = mCacheEntry->SetMetaDataElement(nsLiteralCString(key),
|
||||
nsLiteralCString(value));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mCacheEntry->TouchMetaData();
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::VisitMetaData(nsICacheMetaDataVisitor * visitor)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(visitor);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return mCacheEntry->VisitMetaDataElements(visitor);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheTransportWrapper
|
||||
******************************************************************************/
|
||||
|
||||
// XXX NS_IMPL_ISUPPORTS1(nsCacheEntryDescriptor::nsTransportWrapper, nsITransport);
|
||||
NS_IMPL_QUERY_INTERFACE1(nsCacheEntryDescriptor::nsTransportWrapper, nsITransport)
|
||||
|
||||
|
||||
// special AddRef and Release, because we are part of the descriptor
|
||||
#define GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(_this) \
|
||||
((nsCacheEntryDescriptor*)((char*)(_this) - \
|
||||
offsetof(nsCacheEntryDescriptor, mTransportWrapper)))
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt) nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::AddRef(void)
|
||||
{
|
||||
return GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(this)->AddRef();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt) nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::Release(void)
|
||||
{
|
||||
return GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(this)->Release();
|
||||
}
|
||||
|
||||
|
||||
nsresult nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::EnsureTransportWithAccess(nsCacheAccessMode mode)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCacheEntryDescriptor * descriptor = GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(this);
|
||||
if (!descriptor->mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
if (!descriptor->mAccessGranted & mode) {
|
||||
rv = (mode == nsICache::ACCESS_READ) ?
|
||||
NS_ERROR_CACHE_READ_ACCESS_DENIED : NS_ERROR_CACHE_WRITE_ACCESS_DENIED;
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!mTransport) {
|
||||
rv = nsCacheService::GlobalInstance()->
|
||||
GetTransportForEntry(descriptor->mCacheEntry,
|
||||
descriptor->mAccessGranted,
|
||||
getter_AddRefs(mTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryDescriptor::NewOutputStreamWrapper(nsIOutputStream ** result,
|
||||
nsCacheEntryDescriptor * descriptor,
|
||||
nsIOutputStream * output)
|
||||
{
|
||||
nsOutputStreamWrapper* cacheOutput =
|
||||
new nsOutputStreamWrapper(descriptor, output);
|
||||
if (!cacheOutput) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsISupports> ref(cacheOutput);
|
||||
nsresult rv = cacheOutput->Init();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ADDREF(*result = cacheOutput);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::GetSecurityInfo(nsISupports ** securityInfo)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::GetNotificationCallbacks(nsIInterfaceRequestor ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
// if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::SetNotificationCallbacks(nsIInterfaceRequestor * requestor,
|
||||
PRUint32 flags)
|
||||
{
|
||||
// if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::OpenInputStream(PRUint32 offset,
|
||||
PRUint32 count,
|
||||
PRUint32 flags,
|
||||
nsIInputStream ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
nsresult rv = EnsureTransportWithAccess(nsICache::ACCESS_READ);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return mTransport->OpenInputStream(offset, count, flags, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::OpenOutputStream(PRUint32 offset,
|
||||
PRUint32 count,
|
||||
PRUint32 flags,
|
||||
nsIOutputStream ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
nsresult rv = EnsureTransportWithAccess(nsICache::ACCESS_WRITE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// XXX allow more than one output stream at a time on a descriptor? Why?
|
||||
|
||||
// Create the underlying output stream using the wrapped transport.
|
||||
nsCOMPtr<nsIOutputStream> output;
|
||||
rv = mTransport->OpenOutputStream(offset, count, flags, getter_AddRefs(output));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Wrap this output stream with a stream that monitors how much data gets written,
|
||||
// maintains the cache entry's size, and informs the cache device.
|
||||
// This mechanism provides a way for the cache device to enforce space limits,
|
||||
// and to drive cache entry eviction.
|
||||
nsCacheEntryDescriptor * descriptor = GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(this);
|
||||
|
||||
// reset datasize of entry based on offset so OnWrite calculates delta changes correctly.
|
||||
rv = descriptor->SetDataSize(offset);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NewOutputStreamWrapper(result, descriptor, output);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::AsyncRead(nsIStreamListener * listener,
|
||||
nsISupports * ctxt,
|
||||
PRUint32 offset,
|
||||
PRUint32 count,
|
||||
PRUint32 flags,
|
||||
nsIRequest ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
nsresult rv = EnsureTransportWithAccess(nsICache::ACCESS_READ);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return mTransport->AsyncRead(listener, ctxt, offset, count, flags, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::AsyncWrite(nsIStreamProvider * provider,
|
||||
nsISupports * ctxt,
|
||||
PRUint32 offset,
|
||||
PRUint32 count,
|
||||
PRUint32 flags,
|
||||
nsIRequest ** result)
|
||||
{
|
||||
// we're not planning on implementing this
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
#if 0
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
nsresult rv = EnsureTransportWithAccess(nsICache::ACCESS_WRITE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return mTransport->AsyncWrite(provider, ctxt, offset, count, flags, result);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheOutputStream - a wrapper for nsIOutputstream to track the amount of
|
||||
* data written to a cache entry.
|
||||
******************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsCacheEntryDescriptor::nsOutputStreamWrapper, nsIOutputStream);
|
||||
|
||||
nsresult nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::Init()
|
||||
{
|
||||
nsCacheAccessMode mode;
|
||||
nsresult rv = mDescriptor->GetAccessGranted(&mode);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (mode == nsICache::ACCESS_WRITE) {
|
||||
nsCacheEntry* cacheEntry = mDescriptor->CacheEntry();
|
||||
if (!cacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
nsCacheDevice* device = cacheEntry->CacheDevice();
|
||||
if (!device) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
// the entry has been truncated to zero bytes, inform the device.
|
||||
PRInt32 delta = -cacheEntry->DataSize();
|
||||
rv = device->OnDataSizeChange(cacheEntry, delta);
|
||||
cacheEntry->SetDataSize(0);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::Write(const char * buf,
|
||||
PRUint32 count,
|
||||
PRUint32 * result)
|
||||
{
|
||||
nsresult rv = OnWrite(count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mOutput->Write(buf, count, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::WriteFrom(nsIInputStream * inStr,
|
||||
PRUint32 count,
|
||||
PRUint32 * result)
|
||||
{
|
||||
nsresult rv = OnWrite(count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mOutput->WriteFrom(inStr, count, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::WriteSegments(nsReadSegmentFun reader,
|
||||
void * closure,
|
||||
PRUint32 count,
|
||||
PRUint32 * result)
|
||||
{
|
||||
nsresult rv = OnWrite(count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mOutput->WriteSegments(reader, closure, count, result);
|
||||
}
|
||||
|
||||
|
||||
nsresult nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::OnWrite(PRUint32 count)
|
||||
{
|
||||
// XXX if count > 2^31 error_write_too_big
|
||||
return mDescriptor->RequestDataSizeChange((PRInt32)count);
|
||||
}
|
||||
|
||||
|
||||
167
mozilla/netwerk/cache/src/nsCacheEntryDescriptor.h
vendored
167
mozilla/netwerk/cache/src/nsCacheEntryDescriptor.h
vendored
@@ -1,167 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheEntryDescriptor.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _nsCacheEntryDescriptor_h_
|
||||
#define _nsCacheEntryDescriptor_h_
|
||||
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "nsCacheEntry.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsITransport.h"
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryDescriptor
|
||||
*******************************************************************************/
|
||||
class nsCacheEntryDescriptor :
|
||||
public PRCList,
|
||||
public nsICacheEntryDescriptor
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHEENTRYDESCRIPTOR
|
||||
NS_DECL_NSICACHEENTRYINFO
|
||||
|
||||
nsCacheEntryDescriptor(nsCacheEntry * entry, nsCacheAccessMode mode);
|
||||
virtual ~nsCacheEntryDescriptor();
|
||||
|
||||
static nsresult Create(nsCacheEntry * entry, nsCacheAccessMode accessGranted,
|
||||
nsICacheEntryDescriptor ** result);
|
||||
|
||||
|
||||
/**
|
||||
* utility method to attempt changing data size of associated entry
|
||||
*/
|
||||
nsresult RequestDataSizeChange(PRInt32 deltaSize);
|
||||
|
||||
/**
|
||||
* methods callbacks for nsCacheService
|
||||
*/
|
||||
nsCacheEntry * CacheEntry(void) { return mCacheEntry; }
|
||||
void ClearCacheEntry(void) { mCacheEntry = nsnull; }
|
||||
|
||||
private:
|
||||
|
||||
/*************************************************************************
|
||||
* transport wrapper class -
|
||||
*
|
||||
* we want the transport wrapper to have the same lifetime as the
|
||||
* descriptor, but since they each need to reference the other, we have the
|
||||
* descriptor include the transport wrapper as a member, rather than just
|
||||
* pointing to it, which avoids circular AddRefs.
|
||||
*************************************************************************/
|
||||
class nsTransportWrapper : public nsITransport
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSITRANSPORT
|
||||
|
||||
nsTransportWrapper() : mTransport(nsnull) {}
|
||||
virtual ~nsTransportWrapper() {}
|
||||
|
||||
nsresult EnsureTransportWithAccess(nsCacheAccessMode mode);
|
||||
|
||||
nsCOMPtr<nsITransport> mTransport;
|
||||
}; // end of class nsTransportWrapper
|
||||
friend class nsTransportWrapper;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* output stream wrapper class -
|
||||
*
|
||||
* The output stream wrapper references the descriptor, but the descriptor
|
||||
* doesn't need any references to the stream wrapper, so we don't need the
|
||||
* same kind of tricks that we're using for the transport wrapper.
|
||||
*************************************************************************/
|
||||
class nsOutputStreamWrapper : public nsIOutputStream {
|
||||
private:
|
||||
nsCacheEntryDescriptor * mDescriptor;
|
||||
nsCOMPtr<nsIOutputStream> mOutput;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
// NS_DECL_NSIOUTPUTSTREAM
|
||||
NS_IMETHOD Close(void) { return mOutput->Close(); }
|
||||
NS_IMETHOD Flush(void) { return mOutput->Flush(); }
|
||||
|
||||
NS_IMETHOD Write(const char * buf,
|
||||
PRUint32 count,
|
||||
PRUint32 * result);
|
||||
|
||||
NS_IMETHOD WriteFrom(nsIInputStream * inStr,
|
||||
PRUint32 count,
|
||||
PRUint32 * result);
|
||||
|
||||
NS_IMETHOD WriteSegments(nsReadSegmentFun reader,
|
||||
void * closure,
|
||||
PRUint32 count,
|
||||
PRUint32 * result);
|
||||
|
||||
NS_IMETHOD GetNonBlocking(PRBool * nonBlocking)
|
||||
{ return mOutput->GetNonBlocking(nonBlocking); }
|
||||
|
||||
NS_IMETHOD SetNonBlocking(PRBool nonBlocking)
|
||||
{ return mOutput->SetNonBlocking(nonBlocking); }
|
||||
|
||||
NS_IMETHOD GetObserver(nsIOutputStreamObserver ** observer)
|
||||
{ return mOutput->GetObserver(observer); }
|
||||
|
||||
NS_IMETHOD SetObserver(nsIOutputStreamObserver * observer)
|
||||
{ return mOutput->SetObserver(observer); }
|
||||
|
||||
nsOutputStreamWrapper(nsCacheEntryDescriptor * descriptor,
|
||||
nsIOutputStream * output)
|
||||
: mDescriptor(nsnull), mOutput(output)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
NS_ADDREF(mDescriptor = descriptor);
|
||||
}
|
||||
|
||||
virtual ~nsOutputStreamWrapper()
|
||||
{
|
||||
NS_RELEASE(mDescriptor);
|
||||
}
|
||||
|
||||
nsresult Init();
|
||||
|
||||
|
||||
private:
|
||||
nsresult OnWrite(PRUint32 count);
|
||||
}; // end of class nsOutputStreamWrapper
|
||||
friend class nsOutputStreamWrapper;
|
||||
|
||||
|
||||
|
||||
static nsresult NewOutputStreamWrapper(nsIOutputStream ** result,
|
||||
nsCacheEntryDescriptor * descriptor,
|
||||
nsIOutputStream * output);
|
||||
private:
|
||||
/**
|
||||
* nsCacheEntryDescriptor data members
|
||||
*/
|
||||
nsCacheEntry * mCacheEntry; // we are a child of the entry
|
||||
nsCacheAccessMode mAccessGranted;
|
||||
nsTransportWrapper mTransportWrapper;
|
||||
};
|
||||
|
||||
|
||||
#endif // _nsCacheEntryDescriptor_h_
|
||||
327
mozilla/netwerk/cache/src/nsCacheMetaData.cpp
vendored
327
mozilla/netwerk/cache/src/nsCacheMetaData.cpp
vendored
@@ -1,327 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheMetaData.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#include "nsCacheMetaData.h"
|
||||
#include "nsString.h"
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
|
||||
|
||||
/*
|
||||
* nsCacheClientHashTable
|
||||
*/
|
||||
|
||||
PLDHashTableOps
|
||||
nsCacheMetaData::ops =
|
||||
{
|
||||
PL_DHashAllocTable,
|
||||
PL_DHashFreeTable,
|
||||
GetKey,
|
||||
HashKey,
|
||||
MatchEntry,
|
||||
MoveEntry,
|
||||
ClearEntry,
|
||||
Finalize
|
||||
};
|
||||
|
||||
|
||||
nsCacheMetaData::nsCacheMetaData()
|
||||
: initialized(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
nsCacheMetaData::~nsCacheMetaData()
|
||||
{
|
||||
if (initialized)
|
||||
PL_DHashTableFinish(&table);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
initialized = PL_DHashTableInit(&table, &ops, nsnull,
|
||||
sizeof(nsCacheMetaDataHashTableEntry), 16);
|
||||
|
||||
if (!initialized) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsCacheMetaData *
|
||||
nsCacheMetaData::Create()
|
||||
{
|
||||
nsCacheMetaData * metaData = new nsCacheMetaData();
|
||||
if (!metaData)
|
||||
return nsnull;
|
||||
|
||||
nsresult rv = metaData->Init();
|
||||
if (NS_FAILED(rv)) {
|
||||
delete metaData;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
return metaData;
|
||||
}
|
||||
|
||||
|
||||
nsAReadableCString *
|
||||
nsCacheMetaData::GetElement(const nsAReadableCString * key)
|
||||
{
|
||||
PLDHashEntryHdr * hashEntry;
|
||||
nsCString * result = nsnull;
|
||||
|
||||
// XXX need to copy string until we have scc's new flat string abstract class
|
||||
// XXX see nsCacheMetaData::HashKey below (bug 70075)
|
||||
nsCString * tempKey = new nsCString(*key);
|
||||
if (!tempKey) return result;
|
||||
|
||||
NS_ASSERTION(initialized, "nsCacheMetaDataHashTable not initialized");
|
||||
hashEntry = PL_DHashTableOperate(&table, tempKey, PL_DHASH_LOOKUP);
|
||||
if (PL_DHASH_ENTRY_IS_BUSY(hashEntry)) {
|
||||
result = ((nsCacheMetaDataHashTableEntry *)hashEntry)->value;
|
||||
}
|
||||
|
||||
delete tempKey;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::SetElement(const nsAReadableCString& key,
|
||||
const nsAReadableCString& value)
|
||||
{
|
||||
nsCacheMetaDataHashTableEntry * metaEntry;
|
||||
nsresult rv = NS_ERROR_OUT_OF_MEMORY; // presume the worst
|
||||
|
||||
NS_ASSERTION(initialized, "nsCacheMetaDataHashTable not initialized");
|
||||
|
||||
// XXX need to copy string until we have scc's new flat string abstract class
|
||||
// XXX see nsCacheMetaData::HashKey below (bug 70075)
|
||||
nsCString * tempKey = new nsCString(key);
|
||||
if (!tempKey) return rv;
|
||||
|
||||
// XXX should empty value remove the key?
|
||||
|
||||
metaEntry = (nsCacheMetaDataHashTableEntry *)
|
||||
PL_DHashTableOperate(&table, tempKey, PL_DHASH_ADD);
|
||||
if (!metaEntry) goto error_exit;
|
||||
|
||||
|
||||
if (metaEntry->key == nsnull) {
|
||||
metaEntry->key = new nsCString(key);
|
||||
if (metaEntry->key == nsnull) {
|
||||
goto error_exit;
|
||||
}
|
||||
}
|
||||
if (metaEntry->value != nsnull)
|
||||
delete metaEntry->value; // clear the old value
|
||||
|
||||
metaEntry->value = new nsCString(value);
|
||||
if (metaEntry->value == nsnull) {
|
||||
// XXX remove key?
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
rv = NS_OK;
|
||||
error_exit:
|
||||
delete tempKey;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
PRUint32
|
||||
nsCacheMetaData::Size(void)
|
||||
{
|
||||
PRUint32 size = 0;
|
||||
(void) PL_DHashTableEnumerate(&table, CalculateSize, &size);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::FlattenMetaData(char ** data, PRUint32 * size)
|
||||
{
|
||||
*size = 0;
|
||||
|
||||
if (PL_DHashTableEnumerate(&table, CalculateSize, size) != 0 && data) {
|
||||
*data = new char[*size];
|
||||
if (*data == nsnull) return NS_ERROR_OUT_OF_MEMORY;
|
||||
char* state = *data;
|
||||
PL_DHashTableEnumerate(&table, AccumulateElement, &state);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::UnflattenMetaData(char * data, PRUint32 size)
|
||||
{
|
||||
nsresult rv = NS_ERROR_UNEXPECTED;
|
||||
char* limit = data + size;
|
||||
while (data < limit) {
|
||||
const char* name = data;
|
||||
PRUint32 nameSize = nsCRT::strlen(name);
|
||||
data += 1 + nameSize;
|
||||
if (data < limit) {
|
||||
const char* value = data;
|
||||
PRUint32 valueSize = nsCRT::strlen(value);
|
||||
data += 1 + valueSize;
|
||||
rv = SetElement(nsLocalCString(name, nameSize),
|
||||
nsLocalCString(value, valueSize));
|
||||
if (NS_FAILED(rv)) break;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::VisitElements(nsICacheMetaDataVisitor * visitor)
|
||||
{
|
||||
(void) PL_DHashTableEnumerate(&table, VisitElement, visitor);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* hash table operation callback functions
|
||||
*/
|
||||
|
||||
const void * PR_CALLBACK
|
||||
nsCacheMetaData::GetKey( PLDHashTable * /* table */, PLDHashEntryHdr *hashEntry)
|
||||
{
|
||||
return ((nsCacheMetaDataHashTableEntry *)hashEntry)->key;
|
||||
}
|
||||
|
||||
|
||||
PLDHashNumber PR_CALLBACK
|
||||
nsCacheMetaData::HashKey( PLDHashTable * table, const void *key)
|
||||
{
|
||||
// XXX need scc's new flat string abstract class here (bug 70075)
|
||||
return PL_DHashStringKey(table, ((nsCString *)key)->get());
|
||||
}
|
||||
|
||||
|
||||
PRBool PR_CALLBACK
|
||||
nsCacheMetaData::MatchEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr * hashEntry,
|
||||
const void * key)
|
||||
{
|
||||
NS_ASSERTION(key != nsnull, "### nsCacheMetaDataHashTable::MatchEntry : null key");
|
||||
nsCString * entryKey = ((nsCacheMetaDataHashTableEntry *)hashEntry)->key;
|
||||
NS_ASSERTION(entryKey, "### hashEntry->key == nsnull");
|
||||
|
||||
return entryKey->Equals(*NS_STATIC_CAST(const nsAReadableCString*,key));
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheMetaData::MoveEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr *from,
|
||||
PLDHashEntryHdr *to)
|
||||
{
|
||||
((nsCacheMetaDataHashTableEntry *)to)->key =
|
||||
((nsCacheMetaDataHashTableEntry *)from)->key;
|
||||
((nsCacheMetaDataHashTableEntry *)to)->value =
|
||||
((nsCacheMetaDataHashTableEntry *)from)->value;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheMetaData::ClearEntry(PLDHashTable * /* table */,
|
||||
PLDHashEntryHdr * hashEntry)
|
||||
{
|
||||
((nsCacheMetaDataHashTableEntry *)hashEntry)->key = 0;
|
||||
((nsCacheMetaDataHashTableEntry *)hashEntry)->value = 0;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheMetaData::Finalize(PLDHashTable * table)
|
||||
{
|
||||
(void) PL_DHashTableEnumerate(table, FreeElement, nsnull);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hash table enumeration callback functions
|
||||
*/
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheMetaData::CalculateSize(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheMetaDataHashTableEntry* hashEntry = (nsCacheMetaDataHashTableEntry *)hdr;
|
||||
*(PRUint32*)arg += (2 + hashEntry->key->Length() + hashEntry->value->Length());
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheMetaData::AccumulateElement(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
char** bufferPtr = (char**) arg;
|
||||
nsCacheMetaDataHashTableEntry* hashEntry = (nsCacheMetaDataHashTableEntry *)hdr;
|
||||
PRUint32 size = 1 + hashEntry->key->Length();
|
||||
nsCRT::memcpy(*bufferPtr, hashEntry->key->get(), size);
|
||||
*bufferPtr += size;
|
||||
size = 1 + hashEntry->value->Length();
|
||||
nsCRT::memcpy(*bufferPtr, hashEntry->value->get(), size);
|
||||
*bufferPtr += size;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheMetaData::FreeElement(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheMetaDataHashTableEntry *entry = (nsCacheMetaDataHashTableEntry *)hdr;
|
||||
delete entry->key;
|
||||
delete entry->value;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheMetaData::VisitElement(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheMetaDataHashTableEntry *entry = (nsCacheMetaDataHashTableEntry *)hdr;
|
||||
nsICacheMetaDataVisitor *visitor = (nsICacheMetaDataVisitor *)arg;
|
||||
const char * key = entry->key ? entry->key->get() : nsnull;
|
||||
const char * value = entry->value ? entry->value->get() : nsnull;
|
||||
|
||||
PRBool keepGoing;
|
||||
nsresult rv = visitor->VisitMetaDataElement(key, value, &keepGoing);
|
||||
|
||||
return NS_SUCCEEDED(rv) && keepGoing ? PL_DHASH_NEXT : PL_DHASH_STOP;
|
||||
}
|
||||
119
mozilla/netwerk/cache/src/nsCacheMetaData.h
vendored
119
mozilla/netwerk/cache/src/nsCacheMetaData.h
vendored
@@ -1,119 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheMetaData.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheMetaData_h_
|
||||
#define _nsCacheMetaData_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "pldhash.h"
|
||||
#include "nscore.h"
|
||||
// #include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
// #include "nsAReadableString.h"
|
||||
|
||||
class nsICacheMetaDataVisitor;
|
||||
|
||||
typedef struct {
|
||||
nsCString * key;
|
||||
nsCString * value;
|
||||
} nsCacheMetaDataKeyValuePair;
|
||||
|
||||
|
||||
typedef struct {
|
||||
PLDHashNumber keyHash;
|
||||
nsCString * key;
|
||||
nsCString * value;
|
||||
} nsCacheMetaDataHashTableEntry;
|
||||
|
||||
|
||||
class nsCacheMetaData {
|
||||
public:
|
||||
nsCacheMetaData();
|
||||
~nsCacheMetaData();
|
||||
|
||||
static
|
||||
nsCacheMetaData * Create(void);
|
||||
|
||||
nsresult Init(void);
|
||||
|
||||
nsAReadableCString * GetElement(const nsAReadableCString * key);
|
||||
|
||||
nsresult SetElement(const nsAReadableCString& key,
|
||||
const nsAReadableCString& value);
|
||||
|
||||
PRUint32 Size(void);
|
||||
|
||||
nsresult FlattenMetaData(char ** data, PRUint32 * size);
|
||||
|
||||
nsresult UnflattenMetaData(char * data, PRUint32 size);
|
||||
|
||||
nsresult VisitElements(nsICacheMetaDataVisitor * visitor);
|
||||
|
||||
private:
|
||||
// PLDHashTable operation callbacks
|
||||
static const void * PR_CALLBACK GetKey( PLDHashTable *table, PLDHashEntryHdr *entry);
|
||||
|
||||
static PLDHashNumber PR_CALLBACK HashKey( PLDHashTable *table, const void *key);
|
||||
|
||||
static PRBool PR_CALLBACK MatchEntry( PLDHashTable * table,
|
||||
const PLDHashEntryHdr * entry,
|
||||
const void * key);
|
||||
|
||||
static void PR_CALLBACK MoveEntry( PLDHashTable *table,
|
||||
const PLDHashEntryHdr *from,
|
||||
PLDHashEntryHdr *to);
|
||||
|
||||
static void PR_CALLBACK ClearEntry( PLDHashTable *table, PLDHashEntryHdr *entry);
|
||||
|
||||
static void PR_CALLBACK Finalize( PLDHashTable *table);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK CalculateSize(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK AccumulateElement(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK FreeElement(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK VisitElement(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
|
||||
// member variables
|
||||
static PLDHashTableOps ops;
|
||||
PLDHashTable table;
|
||||
PRBool initialized;
|
||||
};
|
||||
|
||||
#endif // _nsCacheMetaData_h
|
||||
41
mozilla/netwerk/cache/src/nsCacheModule.cpp
vendored
41
mozilla/netwerk/cache/src/nsCacheModule.cpp
vendored
@@ -1,41 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheModule.cpp, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsCacheService.h"
|
||||
#include "nsNetCID.h"
|
||||
|
||||
// nsCacheService
|
||||
//
|
||||
|
||||
static nsModuleComponentInfo gResComponents[] = {
|
||||
{
|
||||
NS_CACHESERVICE_CLASSNAME,
|
||||
NS_CACHESERVICE_CID,
|
||||
NS_CACHESERVICE_CONTRACTID,
|
||||
nsCacheService::Create
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(cacheservice, gResComponents)
|
||||
178
mozilla/netwerk/cache/src/nsCacheRequest.h
vendored
178
mozilla/netwerk/cache/src/nsCacheRequest.h
vendored
@@ -1,178 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheRequest.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheRequest_h_
|
||||
#define _nsCacheRequest_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsICache.h"
|
||||
#include "nsICacheListener.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsCacheSession.h"
|
||||
|
||||
|
||||
class nsCacheRequest : public PRCList
|
||||
{
|
||||
private:
|
||||
friend class nsCacheService;
|
||||
friend class nsCacheEntry;
|
||||
|
||||
nsCacheRequest( nsCString * key,
|
||||
nsICacheListener * listener,
|
||||
nsCacheAccessMode accessRequested,
|
||||
PRBool blockingMode,
|
||||
nsCacheSession * session)
|
||||
: mKey(key),
|
||||
mInfo(0),
|
||||
mListener(listener),
|
||||
mEventQ(nsnull),
|
||||
mLock(nsnull),
|
||||
mCondVar(nsnull)
|
||||
{
|
||||
PR_INIT_CLIST(this);
|
||||
SetAccessRequested(accessRequested);
|
||||
SetStoragePolicy(session->StoragePolicy());
|
||||
if (session->IsStreamBased()) MarkStreamBased();
|
||||
if (session->WillDoomEntriesIfExpired()) MarkDoomEntriesIfExpired();
|
||||
if (blockingMode == nsICache::BLOCKING) MarkBlockingMode();
|
||||
MarkWaitingForValidation();
|
||||
}
|
||||
|
||||
~nsCacheRequest()
|
||||
{
|
||||
delete mKey;
|
||||
if (mLock) PR_DestroyLock(mLock);
|
||||
if (mCondVar) PR_DestroyCondVar(mCondVar);
|
||||
NS_ASSERTION(PR_CLIST_IS_EMPTY(this), "request still on a list");
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Accessors
|
||||
*/
|
||||
enum CacheRequestInfo {
|
||||
eStoragePolicyMask = 0x000000FF,
|
||||
eStreamBasedMask = 0x00000100,
|
||||
eDoomEntriesIfExpiredMask = 0x00001000,
|
||||
eBlockingModeMask = 0x00010000,
|
||||
eWaitingForValidationMask = 0x00100000,
|
||||
eAccessRequestedMask = 0xFF000000
|
||||
};
|
||||
|
||||
void SetAccessRequested(nsCacheAccessMode mode)
|
||||
{
|
||||
NS_ASSERTION(mode <= 0xFF, "too many bits in nsCacheAccessMode");
|
||||
mInfo &= ~eAccessRequestedMask;
|
||||
mInfo |= mode << 24;
|
||||
}
|
||||
|
||||
nsCacheAccessMode AccessRequested()
|
||||
{
|
||||
return (nsCacheAccessMode)((mInfo >> 24) & 0xFF);
|
||||
}
|
||||
|
||||
void MarkStreamBased() { mInfo |= eStreamBasedMask; }
|
||||
PRBool IsStreamBased() { return (mInfo & eStreamBasedMask) != 0; }
|
||||
|
||||
|
||||
void MarkDoomEntriesIfExpired() { mInfo |= eDoomEntriesIfExpiredMask; }
|
||||
PRBool WillDoomEntriesIfExpired() { return (mInfo & eDoomEntriesIfExpiredMask); }
|
||||
|
||||
void MarkBlockingMode() { mInfo |= eBlockingModeMask; }
|
||||
PRBool IsBlocking() { return (mInfo & eBlockingModeMask); }
|
||||
PRBool IsNonBlocking() { return !(mInfo & eBlockingModeMask); }
|
||||
|
||||
void SetStoragePolicy(nsCacheStoragePolicy policy)
|
||||
{
|
||||
NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy");
|
||||
mInfo &= ~eStoragePolicyMask; // clear storage policy bits
|
||||
mInfo |= policy; // or in new bits
|
||||
}
|
||||
|
||||
nsCacheStoragePolicy StoragePolicy()
|
||||
{
|
||||
return (nsCacheStoragePolicy)(mInfo & 0xFF);
|
||||
}
|
||||
|
||||
void MarkWaitingForValidation() { mInfo |= eWaitingForValidationMask; }
|
||||
void DoneWaitingForValidation() { mInfo &= ~eWaitingForValidationMask; }
|
||||
PRBool WaitingForValidation()
|
||||
{
|
||||
return (mInfo & eWaitingForValidationMask) != 0;
|
||||
}
|
||||
|
||||
nsresult
|
||||
WaitForValidation(void)
|
||||
{
|
||||
if (!WaitingForValidation()) { // flag already cleared
|
||||
MarkWaitingForValidation(); // set up for next time
|
||||
return NS_OK; // early exit;
|
||||
}
|
||||
|
||||
if (!mLock) {
|
||||
mLock = PR_NewLock();
|
||||
if (!mLock) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ASSERTION(!mCondVar,"we have mCondVar, but didn't have mLock?");
|
||||
mCondVar = PR_NewCondVar(mLock);
|
||||
if (!mCondVar) {
|
||||
PR_DestroyLock(mLock);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
PRStatus status = PR_SUCCESS;
|
||||
PR_Lock(mLock);
|
||||
while (WaitingForValidation() && (status == PR_SUCCESS) ) {
|
||||
status = PR_WaitCondVar(mCondVar, PR_INTERVAL_NO_TIMEOUT);
|
||||
}
|
||||
MarkWaitingForValidation(); // set up for next time
|
||||
PR_Unlock(mLock);
|
||||
|
||||
NS_ASSERTION(status == PR_SUCCESS, "PR_WaitCondVar() returned PR_FAILURE?");
|
||||
if (status == PR_FAILURE)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void WakeUp(void) {
|
||||
DoneWaitingForValidation();
|
||||
if (mLock) {
|
||||
PR_Lock(mLock);
|
||||
PR_NotifyCondVar(mCondVar);
|
||||
PR_Unlock(mLock);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data members
|
||||
*/
|
||||
nsCString * mKey;
|
||||
PRUint32 mInfo;
|
||||
nsCOMPtr<nsICacheListener> mListener;
|
||||
nsCOMPtr<nsIEventQueue> mEventQ;
|
||||
PRLock * mLock;
|
||||
PRCondVar * mCondVar;
|
||||
};
|
||||
|
||||
#endif // _nsCacheRequest_h_
|
||||
1145
mozilla/netwerk/cache/src/nsCacheService.cpp
vendored
1145
mozilla/netwerk/cache/src/nsCacheService.cpp
vendored
File diff suppressed because it is too large
Load Diff
194
mozilla/netwerk/cache/src/nsCacheService.h
vendored
194
mozilla/netwerk/cache/src/nsCacheService.h
vendored
@@ -1,194 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheService.h, released February 10, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _nsCacheService_h_
|
||||
#define _nsCacheService_h_
|
||||
|
||||
#include "nsICacheService.h"
|
||||
#include "nsCacheSession.h"
|
||||
#include "nsCacheDevice.h"
|
||||
#include "nsCacheEntry.h"
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsProxiedService.h"
|
||||
|
||||
class nsCacheRequest;
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheService
|
||||
******************************************************************************/
|
||||
|
||||
class nsCacheService : public nsICacheService, public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHESERVICE
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
nsCacheService();
|
||||
virtual ~nsCacheService();
|
||||
|
||||
// Define a Create method to be used with a factory:
|
||||
static NS_METHOD
|
||||
Create(nsISupports* outer, const nsIID& iid, void* *result);
|
||||
|
||||
|
||||
/**
|
||||
* Methods called by nsCacheSession
|
||||
*/
|
||||
nsresult OpenCacheEntry(nsCacheSession * session,
|
||||
const char * key,
|
||||
nsCacheAccessMode accessRequested,
|
||||
PRBool blockingMode,
|
||||
nsICacheListener * listener,
|
||||
nsICacheEntryDescriptor ** result);
|
||||
|
||||
nsresult EvictEntriesForSession(nsCacheSession * session);
|
||||
|
||||
nsresult EvictEntriesForClient(const char * clientID,
|
||||
nsCacheStoragePolicy storagePolicy);
|
||||
|
||||
/**
|
||||
* Methods called by nsCacheEntryDescriptor
|
||||
*/
|
||||
nsresult SetCacheElement(nsCacheEntry * entry, nsISupports * element);
|
||||
|
||||
nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
|
||||
|
||||
nsresult ValidateEntry(nsCacheEntry * entry);
|
||||
|
||||
nsresult GetTransportForEntry(nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport ** result);
|
||||
|
||||
void CloseDescriptor(nsCacheEntryDescriptor * descriptor);
|
||||
|
||||
nsresult GetFileForEntry(nsCacheEntry * entry,
|
||||
nsIFile ** result);
|
||||
|
||||
/**
|
||||
* Methods called by any cache classes
|
||||
*/
|
||||
|
||||
static
|
||||
nsCacheService * GlobalInstance(void) { return gService; };
|
||||
|
||||
nsresult DoomEntry(nsCacheEntry * entry);
|
||||
|
||||
nsresult DoomEntry_Locked(nsCacheEntry * entry);
|
||||
|
||||
/**
|
||||
* Methods called by nsCachePrefObserver
|
||||
*/
|
||||
void SetCacheDevicesEnabled(PRBool disk, PRBool memory);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Internal Methods
|
||||
*/
|
||||
|
||||
nsresult CreateDiskDevice();
|
||||
nsresult CreateMemoryDevice();
|
||||
|
||||
nsresult CreateRequest(nsCacheSession * session,
|
||||
const char * clientKey,
|
||||
nsCacheAccessMode accessRequested,
|
||||
PRBool blockingMode,
|
||||
nsICacheListener * listener,
|
||||
nsCacheRequest ** request);
|
||||
|
||||
nsresult NotifyListener(nsCacheRequest * request,
|
||||
nsICacheEntryDescriptor * descriptor,
|
||||
nsCacheAccessMode accessGranted,
|
||||
nsresult error);
|
||||
|
||||
nsresult ActivateEntry(nsCacheRequest * request, nsCacheEntry ** entry);
|
||||
|
||||
nsCacheDevice * EnsureEntryHasDevice(nsCacheEntry * entry);
|
||||
|
||||
nsCacheEntry * SearchCacheDevices(nsCString * key, nsCacheStoragePolicy policy);
|
||||
|
||||
void DeactivateEntry(nsCacheEntry * entry);
|
||||
|
||||
nsresult ProcessRequest(nsCacheRequest * request,
|
||||
PRBool calledFromOpenCacheEntry,
|
||||
nsICacheEntryDescriptor ** result);
|
||||
|
||||
nsresult ProcessPendingRequests(nsCacheEntry * entry);
|
||||
|
||||
void ClearPendingRequests(nsCacheEntry * entry);
|
||||
void ClearDoomList(void);
|
||||
void ClearActiveEntries(void);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK DeactivateAndClearEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
PRUint32 number,
|
||||
void * arg);
|
||||
#if defined(PR_LOGGING)
|
||||
void LogCacheStatistics();
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Data Members
|
||||
*/
|
||||
|
||||
static nsCacheService * gService; // there can be only one...
|
||||
nsCOMPtr<nsIEventQueueService> mEventQService;
|
||||
nsCOMPtr<nsIProxyObjectManager> mProxyObjectManager;
|
||||
|
||||
PRLock* mCacheServiceLock;
|
||||
|
||||
PRBool mEnableMemoryDevice;
|
||||
PRBool mEnableDiskDevice;
|
||||
|
||||
nsCacheDevice * mMemoryDevice;
|
||||
nsCacheDevice * mDiskDevice;
|
||||
|
||||
nsCacheEntryHashTable mActiveEntries;
|
||||
PRCList mDoomedEntries;
|
||||
|
||||
// stats
|
||||
|
||||
PRUint32 mTotalEntries;
|
||||
PRUint32 mCacheHits;
|
||||
PRUint32 mCacheMisses;
|
||||
PRUint32 mMaxKeyLength;
|
||||
PRUint32 mMaxDataSize;
|
||||
PRUint32 mMaxMetaSize;
|
||||
|
||||
// Unexpected error totals
|
||||
PRUint32 mDeactivateFailures;
|
||||
PRUint32 mDeactivatedUnboundEntries;
|
||||
};
|
||||
|
||||
|
||||
#endif // _nsCacheService_h_
|
||||
104
mozilla/netwerk/cache/src/nsCacheSession.cpp
vendored
104
mozilla/netwerk/cache/src/nsCacheSession.cpp
vendored
@@ -1,104 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheSession.h, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsCacheSession.h"
|
||||
#include "nsCacheService.h"
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsCacheSession, nsICacheSession)
|
||||
|
||||
nsCacheSession::nsCacheSession(const char * clientID,
|
||||
nsCacheStoragePolicy storagePolicy,
|
||||
PRBool streamBased)
|
||||
: mClientID(clientID),
|
||||
mInfo(0)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
SetStoragePolicy(storagePolicy);
|
||||
|
||||
if (streamBased) MarkStreamBased();
|
||||
else SetStoragePolicy(nsICache::STORE_IN_MEMORY);
|
||||
}
|
||||
|
||||
nsCacheSession::~nsCacheSession()
|
||||
{
|
||||
/* destructor code */
|
||||
// notify service we are going away?
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheSession::GetDoomEntriesIfExpired(PRBool *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = WillDoomEntriesIfExpired();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheSession::SetDoomEntriesIfExpired(PRBool doomEntriesIfExpired)
|
||||
{
|
||||
if (doomEntriesIfExpired) MarkDoomEntriesIfExpired();
|
||||
else ClearDoomEntriesIfExpired();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheSession::OpenCacheEntry(const char * key,
|
||||
nsCacheAccessMode accessRequested,
|
||||
PRBool blockingMode,
|
||||
nsICacheEntryDescriptor ** result)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsCacheService::GlobalInstance()->OpenCacheEntry(this,
|
||||
key,
|
||||
accessRequested,
|
||||
blockingMode,
|
||||
nsnull, // no listener
|
||||
result);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(const char *key,
|
||||
nsCacheAccessMode accessRequested,
|
||||
nsICacheListener *listener)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsCacheService::GlobalInstance()->OpenCacheEntry(this,
|
||||
key,
|
||||
accessRequested,
|
||||
nsICache::BLOCKING,
|
||||
listener,
|
||||
nsnull); // no result
|
||||
|
||||
if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) rv = NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCacheSession::EvictEntries()
|
||||
{
|
||||
return nsCacheService::GlobalInstance()->EvictEntriesForSession(this);
|
||||
}
|
||||
76
mozilla/netwerk/cache/src/nsCacheSession.h
vendored
76
mozilla/netwerk/cache/src/nsCacheSession.h
vendored
@@ -1,76 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheSession.h, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheSession_h_
|
||||
#define _nsCacheSession_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsError.h"
|
||||
#include "nsICacheSession.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsCacheSession : public nsICacheSession
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHESESSION
|
||||
|
||||
nsCacheSession(const char * clientID, nsCacheStoragePolicy storagePolicy, PRBool streamBased);
|
||||
virtual ~nsCacheSession();
|
||||
|
||||
nsCString * ClientID() { return &mClientID; }
|
||||
|
||||
enum SessionInfo {
|
||||
eStoragePolicyMask = 0x000000FF,
|
||||
eStreamBasedMask = 0x00000100,
|
||||
eDoomEntriesIfExpiredMask = 0x00001000
|
||||
};
|
||||
|
||||
void MarkStreamBased() { mInfo |= eStreamBasedMask; }
|
||||
void ClearStreamBased() { mInfo &= ~eStreamBasedMask; }
|
||||
PRBool IsStreamBased() { return (mInfo & eStreamBasedMask) != 0; }
|
||||
|
||||
void MarkDoomEntriesIfExpired() { mInfo |= eDoomEntriesIfExpiredMask; }
|
||||
void ClearDoomEntriesIfExpired() { mInfo &= ~eDoomEntriesIfExpiredMask; }
|
||||
PRBool WillDoomEntriesIfExpired() { return (mInfo & eDoomEntriesIfExpiredMask); }
|
||||
|
||||
nsCacheStoragePolicy StoragePolicy()
|
||||
{
|
||||
return (nsCacheStoragePolicy)(mInfo & eStoragePolicyMask);
|
||||
}
|
||||
|
||||
void SetStoragePolicy(nsCacheStoragePolicy policy)
|
||||
{
|
||||
NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy");
|
||||
mInfo &= ~eStoragePolicyMask; // clear storage policy bits
|
||||
mInfo |= policy;
|
||||
}
|
||||
|
||||
private:
|
||||
nsCString mClientID;
|
||||
PRUint32 mInfo;
|
||||
};
|
||||
|
||||
#endif // _nsCacheSession_h_
|
||||
43
mozilla/netwerk/cache/src/nsDiskCache.h
vendored
43
mozilla/netwerk/cache/src/nsDiskCache.h
vendored
@@ -1,43 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheDevice.h, released March 9, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _nsDiskCache_h_
|
||||
#define _nsDiskCache_h_
|
||||
|
||||
#include "nsCacheEntry.h"
|
||||
|
||||
|
||||
class nsDiskCache {
|
||||
public:
|
||||
enum {
|
||||
kCurrentVersion = 0x00010003 // XXX whats the format?
|
||||
};
|
||||
|
||||
enum { kData, kMetaData };
|
||||
|
||||
static PLDHashNumber Hash(const char* key);
|
||||
};
|
||||
|
||||
#endif // _nsDiskCache_h_
|
||||
348
mozilla/netwerk/cache/src/nsDiskCacheBinding.cpp
vendored
348
mozilla/netwerk/cache/src/nsDiskCacheBinding.cpp
vendored
@@ -1,348 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsDiskCacheBinding.cpp, released May 10, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "nsDiskCacheBinding.h"
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* static hash table callback functions
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#pragma mark HASHTABLE CALLBACKS
|
||||
#endif
|
||||
|
||||
struct HashTableEntry : PLDHashEntryHdr {
|
||||
nsDiskCacheBinding * mBinding;
|
||||
};
|
||||
|
||||
|
||||
static const void * PR_CALLBACK
|
||||
GetKey(PLDHashTable * /*table*/, PLDHashEntryHdr * header)
|
||||
{
|
||||
return (void*) ((HashTableEntry *)header)->mBinding->mRecord.HashNumber();
|
||||
}
|
||||
|
||||
|
||||
static PLDHashNumber PR_CALLBACK
|
||||
HashKey( PLDHashTable *table, const void *key)
|
||||
{
|
||||
return (PLDHashNumber) key;
|
||||
}
|
||||
|
||||
|
||||
static PRBool PR_CALLBACK
|
||||
MatchEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr * header,
|
||||
const void * key)
|
||||
{
|
||||
HashTableEntry * hashEntry = (HashTableEntry *) header;
|
||||
return (hashEntry->mBinding->mRecord.HashNumber() == (PLDHashNumber) key);
|
||||
}
|
||||
|
||||
static void PR_CALLBACK
|
||||
MoveEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr * src,
|
||||
PLDHashEntryHdr * dst)
|
||||
{
|
||||
((HashTableEntry *)dst)->mBinding = ((HashTableEntry *)src)->mBinding;
|
||||
}
|
||||
|
||||
|
||||
static void PR_CALLBACK
|
||||
ClearEntry(PLDHashTable * /* table */,
|
||||
PLDHashEntryHdr * header)
|
||||
{
|
||||
((HashTableEntry *)header)->mBinding = nsnull;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Utility Functions
|
||||
*****************************************************************************/
|
||||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#pragma mark DISK CACHE BINDERY
|
||||
#endif
|
||||
|
||||
nsDiskCacheBinding *
|
||||
GetCacheEntryBinding(nsCacheEntry * entry)
|
||||
{
|
||||
nsCOMPtr<nsISupports> data;
|
||||
nsresult rv = entry->GetData(getter_AddRefs(data));
|
||||
if (NS_FAILED(rv)) return nsnull;
|
||||
|
||||
return (nsDiskCacheBinding *)data.get();
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheBinding
|
||||
*****************************************************************************/
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS0(nsDiskCacheBinding);
|
||||
|
||||
nsDiskCacheBinding::nsDiskCacheBinding(nsCacheEntry* entry, nsDiskCacheRecord * record)
|
||||
: mCacheEntry(entry)
|
||||
{
|
||||
NS_ASSERTION(record->ValidRecord(), "bad record");
|
||||
NS_INIT_ISUPPORTS();
|
||||
PR_INIT_CLIST(this);
|
||||
mRecord = *record;
|
||||
mDoomed = entry->IsDoomed();
|
||||
mGeneration = record->Generation(); // 0 == uninitialized, or data & meta using block files
|
||||
}
|
||||
|
||||
nsDiskCacheBinding::~nsDiskCacheBinding()
|
||||
{
|
||||
NS_ASSERTION(PR_CLIST_IS_EMPTY(this), "binding deleted while still on list");
|
||||
if (!PR_CLIST_IS_EMPTY(this))
|
||||
PR_REMOVE_LINK(this); // XXX why are we still on a list?
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheBindery
|
||||
*
|
||||
* Keeps track of bound disk cache entries to detect for collisions.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
PLDHashTableOps nsDiskCacheBindery::ops =
|
||||
{
|
||||
PL_DHashAllocTable,
|
||||
PL_DHashFreeTable,
|
||||
GetKey,
|
||||
HashKey,
|
||||
MatchEntry,
|
||||
MoveEntry,
|
||||
ClearEntry,
|
||||
PL_DHashFinalizeStub
|
||||
};
|
||||
|
||||
|
||||
nsDiskCacheBindery::nsDiskCacheBindery()
|
||||
: initialized(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
nsDiskCacheBindery::~nsDiskCacheBindery()
|
||||
{
|
||||
if (initialized)
|
||||
PL_DHashTableFinish(&table);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheBindery::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
initialized = PL_DHashTableInit(&table, &ops, nsnull, sizeof(HashTableEntry), 0);
|
||||
|
||||
if (!initialized) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsDiskCacheBinding *
|
||||
nsDiskCacheBindery::CreateBinding(nsCacheEntry * entry,
|
||||
nsDiskCacheRecord * record)
|
||||
{
|
||||
NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
|
||||
nsCOMPtr<nsISupports> data;
|
||||
nsresult rv = entry->GetData(getter_AddRefs(data));
|
||||
if (NS_FAILED(rv) || data) {
|
||||
NS_ASSERTION(!data, "cache entry already has bind data");
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsDiskCacheBinding * binding = new nsDiskCacheBinding(entry, record);
|
||||
if (!binding) return nsnull;
|
||||
|
||||
// give ownership of the binding to the entry
|
||||
entry->SetData(binding);
|
||||
|
||||
// add binding to collision detection system
|
||||
rv = AddBinding(binding);
|
||||
if (NS_FAILED(rv)) {
|
||||
entry->SetData(nsnull);
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
return binding;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* FindActiveEntry : to find active colliding entry so we can doom it
|
||||
*/
|
||||
nsDiskCacheBinding *
|
||||
nsDiskCacheBindery::FindActiveBinding(PRUint32 hashNumber)
|
||||
{
|
||||
NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
|
||||
// find hash entry for key
|
||||
HashTableEntry * hashEntry;
|
||||
hashEntry = (HashTableEntry *) PL_DHashTableOperate(&table, (void*) hashNumber, PL_DHASH_LOOKUP);
|
||||
if (PL_DHASH_ENTRY_IS_FREE(hashEntry)) return nsnull;
|
||||
|
||||
// walk list looking for active entry
|
||||
NS_ASSERTION(hashEntry->mBinding, "hash entry left with no binding");
|
||||
nsDiskCacheBinding * binding = hashEntry->mBinding;
|
||||
while (binding->mCacheEntry->IsDoomed()) {
|
||||
binding = (nsDiskCacheBinding *)PR_NEXT_LINK(binding);
|
||||
if (binding == hashEntry->mBinding) return nsnull;
|
||||
}
|
||||
return binding;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* FindBinding : to identify whether a record is 'in use' so we don't evict it
|
||||
*/
|
||||
nsDiskCacheBinding *
|
||||
nsDiskCacheBindery::FindBinding(nsDiskCacheRecord * record)
|
||||
{
|
||||
NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
|
||||
// find hash entry for key
|
||||
HashTableEntry * hashEntry;
|
||||
hashEntry = (HashTableEntry *) PL_DHashTableOperate(&table, (void*) record->HashNumber(), PL_DHASH_LOOKUP);
|
||||
if (PL_DHASH_ENTRY_IS_FREE(hashEntry)) return nsnull;
|
||||
|
||||
// walk list looking for matching record (match on MetaLocation)
|
||||
NS_ASSERTION(hashEntry->mBinding, "hash entry left with no binding");
|
||||
nsDiskCacheBinding * binding = hashEntry->mBinding;
|
||||
while (binding->mRecord.MetaLocation() != record->MetaLocation()) {
|
||||
binding = (nsDiskCacheBinding *)PR_NEXT_LINK(binding);
|
||||
if (binding == hashEntry->mBinding) return nsnull;
|
||||
}
|
||||
return binding;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* AddBinding
|
||||
*
|
||||
* Called from FindEntry() if we read an entry off of disk
|
||||
* - it may already have a generation number
|
||||
* - a generation number conflict is an error
|
||||
*
|
||||
* Called from BindEntry()
|
||||
* - a generation number needs to be assigned
|
||||
*/
|
||||
nsresult
|
||||
nsDiskCacheBindery::AddBinding(nsDiskCacheBinding * binding)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(binding);
|
||||
NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
|
||||
|
||||
// find hash entry for key
|
||||
HashTableEntry * hashEntry;
|
||||
hashEntry = (HashTableEntry *) PL_DHashTableOperate(&table,
|
||||
(void*) binding->mRecord.HashNumber(),
|
||||
PL_DHASH_ADD);
|
||||
if (!hashEntry) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (hashEntry->mBinding == nsnull) {
|
||||
hashEntry->mBinding = binding;
|
||||
if (binding->mGeneration == 0)
|
||||
binding->mGeneration = 1; // if generation uninitialized, set it to 1
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// insert binding in generation order
|
||||
nsDiskCacheBinding * p = hashEntry->mBinding;
|
||||
PRBool calcGeneration = (binding->mGeneration == 0); // do we need to calculate generation?
|
||||
if (calcGeneration) binding->mGeneration = 1; // initialize to 1 if uninitialized
|
||||
while (1) {
|
||||
|
||||
if (binding->mGeneration < p->mGeneration) {
|
||||
// here we are
|
||||
PR_INSERT_BEFORE(binding, p);
|
||||
if (hashEntry->mBinding == p)
|
||||
hashEntry->mBinding = binding;
|
||||
}
|
||||
|
||||
if (binding->mGeneration == p->mGeneration) {
|
||||
if (calcGeneration) ++binding->mGeneration; // try the next generation
|
||||
else {
|
||||
NS_ASSERTION(binding->mGeneration != p->mGeneration, "generations collide!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
}
|
||||
|
||||
p = (nsDiskCacheBinding *)PR_NEXT_LINK(p);
|
||||
if (p == hashEntry->mBinding) {
|
||||
// end of line: insert here or die
|
||||
p = (nsDiskCacheBinding *)PR_PREV_LINK(p); // back up and check generation
|
||||
if (p->mGeneration == 255) {
|
||||
NS_ASSERTION(p->mGeneration < 255, "generation capacity at full, the engines canna take it cap'n");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
PR_INSERT_BEFORE(binding, hashEntry->mBinding);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* RemoveBinding : remove binding from collision detection on deactivation
|
||||
*/
|
||||
void
|
||||
nsDiskCacheBindery::RemoveBinding(nsDiskCacheBinding * binding)
|
||||
{
|
||||
NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
|
||||
if (!initialized) return;
|
||||
|
||||
HashTableEntry * hashEntry;
|
||||
void * key = (void *)binding->mRecord.HashNumber();
|
||||
|
||||
hashEntry = (HashTableEntry*) PL_DHashTableOperate(&table, (void*) key, PL_DHASH_LOOKUP);
|
||||
if (!PL_DHASH_ENTRY_IS_BUSY(hashEntry)) {
|
||||
NS_ASSERTION(PL_DHASH_ENTRY_IS_BUSY(hashEntry), "binding not in disk cache hashtable!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (binding == hashEntry->mBinding) {
|
||||
if (PR_CLIST_IS_EMPTY(binding)) {
|
||||
// remove this hash entry
|
||||
(void) PL_DHashTableOperate(&table, (void*) binding->mRecord.HashNumber(), PL_DHASH_REMOVE);
|
||||
return;
|
||||
|
||||
} else {
|
||||
// promote next binding to head, and unlink this binding
|
||||
hashEntry->mBinding = (nsDiskCacheBinding *)PR_NEXT_LINK(binding);
|
||||
}
|
||||
}
|
||||
PR_REMOVE_AND_INIT_LINK(binding);
|
||||
}
|
||||
143
mozilla/netwerk/cache/src/nsDiskCacheBinding.h
vendored
143
mozilla/netwerk/cache/src/nsDiskCacheBinding.h
vendored
@@ -1,143 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsDiskCacheBinding.h, released May 10, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _nsDiskCacheBinding_h_
|
||||
#define _nsDiskCacheBinding_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "pldhash.h"
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsCacheEntry.h"
|
||||
|
||||
#ifdef MOZ_NEW_CACHE_REUSE_TRANSPORTS
|
||||
#include "nsITransport.h"
|
||||
#endif
|
||||
|
||||
#include "nsDiskCacheMap.h"
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheBinding
|
||||
*
|
||||
* Created for disk cache specific data and stored in nsCacheEntry.mData as
|
||||
* an nsISupports. Also stored in nsDiskCacheHashTable, with collisions
|
||||
* linked by the PRCList.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
class nsDiskCacheBinding : public nsISupports, public PRCList {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsDiskCacheBinding(nsCacheEntry* entry, nsDiskCacheRecord * record);
|
||||
virtual ~nsDiskCacheBinding();
|
||||
|
||||
#ifdef MOZ_NEW_CACHE_REUSE_TRANSPORTS
|
||||
/**
|
||||
* Maps a cache access mode to a cached nsITransport for that access
|
||||
* mode. We keep these cached to avoid repeated trips to the
|
||||
* file transport service.
|
||||
*/
|
||||
nsCOMPtr<nsITransport>& getTransport(nsCacheAccessMode mode)
|
||||
{
|
||||
return mTransports[mode - 1];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// XXX make friends
|
||||
public:
|
||||
nsCacheEntry* mCacheEntry; // back pointer to parent nsCacheEntry
|
||||
nsDiskCacheRecord mRecord;
|
||||
PRBool mDoomed; // record is not stored in cache map
|
||||
PRUint8 mGeneration; // possibly just reservation
|
||||
|
||||
private:
|
||||
#ifdef MOZ_NEW_CACHE_REUSE_TRANSPORTS
|
||||
nsCOMPtr<nsITransport> mTransports[3];
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Utility Functions
|
||||
*****************************************************************************/
|
||||
|
||||
nsDiskCacheBinding * GetCacheEntryBinding(nsCacheEntry * entry);
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheBindery
|
||||
*
|
||||
* Used to keep track of nsDiskCacheBinding associated with active/bound (and
|
||||
* possibly doomed) entries. Lookups on 4 byte disk hash to find collisions
|
||||
* (which need to be doomed, instead of just evicted. Collisions are linked
|
||||
* using a PRCList to keep track of current generation number.
|
||||
*
|
||||
* Used to detect hash number collisions, and find available generation numbers.
|
||||
*
|
||||
* Not all nsDiskCacheBinding have a generation number.
|
||||
*
|
||||
* Generation numbers may be aquired late, or lost (when data fits in block file)
|
||||
*
|
||||
* Collisions can occur:
|
||||
* BindEntry() - hashnumbers collide (possibly different keys)
|
||||
*
|
||||
* Generation number required:
|
||||
* DeactivateEntry() - metadata written to disk, may require file
|
||||
* GetFileForEntry() - force data to require file
|
||||
* writing to stream - data size may require file
|
||||
*
|
||||
* Binding can be kept in PRCList in order of generation numbers.
|
||||
* Binding with no generation number can be Appended to PRCList (last).
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
class nsDiskCacheBindery {
|
||||
public:
|
||||
nsDiskCacheBindery();
|
||||
~nsDiskCacheBindery();
|
||||
|
||||
nsresult Init();
|
||||
|
||||
nsDiskCacheBinding * CreateBinding(nsCacheEntry * entry,
|
||||
nsDiskCacheRecord * record);
|
||||
|
||||
nsDiskCacheBinding * FindActiveBinding(PRUint32 hashNumber);
|
||||
nsDiskCacheBinding * FindBinding(nsDiskCacheRecord * record);
|
||||
nsresult AddBinding(nsDiskCacheBinding * binding);
|
||||
void RemoveBinding(nsDiskCacheBinding * binding);
|
||||
|
||||
|
||||
private:
|
||||
// member variables
|
||||
static PLDHashTableOps ops;
|
||||
PLDHashTable table;
|
||||
PRBool initialized;
|
||||
};
|
||||
|
||||
#endif /* _nsDiskCacheBinding_h_ */
|
||||
422
mozilla/netwerk/cache/src/nsDiskCacheBlockFile.cpp
vendored
422
mozilla/netwerk/cache/src/nsDiskCacheBlockFile.cpp
vendored
@@ -1,422 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsDiskCacheBlockFile.cpp, released April 12, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsCRT.h"
|
||||
#include "nsDiskCacheBlockFile.h"
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheBlockFile -
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Open
|
||||
*****************************************************************************/
|
||||
nsresult
|
||||
nsDiskCacheBlockFile::Open( nsILocalFile * blockFile, PRUint32 blockSize)
|
||||
{
|
||||
PRStatus err = PR_SUCCESS;
|
||||
PRInt32 fileSize;
|
||||
|
||||
mBlockSize = blockSize;
|
||||
|
||||
// open the file
|
||||
nsresult rv = blockFile->OpenNSPRFileDesc(PR_RDWR | PR_CREATE_FILE, 00666, &mFD);
|
||||
if (NS_FAILED(rv)) return rv; // unable to open or create file
|
||||
|
||||
// allocate bit map buffer
|
||||
mBitMap = new PRUint8[kBitMapBytes];
|
||||
if (!mBitMap) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
// check if we just creating the file
|
||||
fileSize = PR_Available(mFD);
|
||||
if (fileSize < 0) {
|
||||
// XXX an error occurred. We could call PR_GetError(), but how would that help?
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
goto error_exit;
|
||||
}
|
||||
mEndOfFile = fileSize;
|
||||
if (mEndOfFile == 0) {
|
||||
// initialize bit map and write it
|
||||
nsCRT::zero(mBitMap, kBitMapBytes);
|
||||
PRInt32 bytesWritten = PR_Write(mFD, mBitMap, kBitMapBytes);
|
||||
if (bytesWritten < kBitMapBytes) goto error_exit;
|
||||
mEndOfFile = kBitMapBytes;
|
||||
|
||||
} else if (mEndOfFile < kBitMapBytes) {
|
||||
rv = NS_ERROR_UNEXPECTED; // XXX NS_ERROR_CACHE_INVALID;
|
||||
goto error_exit;
|
||||
|
||||
} else {
|
||||
// read the bit map
|
||||
PRInt32 bytesRead = PR_Read(mFD, mBitMap, kBitMapBytes);
|
||||
if (bytesRead < kBitMapBytes) {
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
// validate block file
|
||||
rv = ValidateFile();
|
||||
if (NS_FAILED(rv)) goto error_exit;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
error_exit:
|
||||
if (mFD) {
|
||||
(void) PR_Close(mFD);
|
||||
mFD = nsnull;
|
||||
}
|
||||
|
||||
if (mBitMap) {
|
||||
delete [] mBitMap;
|
||||
mBitMap = nsnull;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Close
|
||||
*****************************************************************************/
|
||||
nsresult
|
||||
nsDiskCacheBlockFile::Close()
|
||||
{
|
||||
if (!mFD) return NS_OK;
|
||||
|
||||
nsresult rv = FlushBitMap();
|
||||
PRStatus err = PR_Close(mFD);
|
||||
mFD = nsnull;
|
||||
|
||||
if (mBitMap) {
|
||||
delete [] mBitMap;
|
||||
mBitMap = nsnull;
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv) && (err != PR_SUCCESS))
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Trim
|
||||
*
|
||||
* Truncate the block file to the end of the last allocated block.
|
||||
*
|
||||
*****************************************************************************/
|
||||
nsresult
|
||||
nsDiskCacheBlockFile::Trim()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* AllocateBlocks
|
||||
*
|
||||
* Allocates 1-4 blocks, using a first fit strategy,
|
||||
* so that no group of blocks spans a quad block boundary.
|
||||
*
|
||||
* Returns block number of first block allocated or -1 on failure.
|
||||
*
|
||||
*****************************************************************************/
|
||||
PRInt32
|
||||
nsDiskCacheBlockFile::AllocateBlocks(PRInt32 numBlocks)
|
||||
{
|
||||
if (!mFD) return -1; // NS_ERROR_NOT_AVAILABLE;
|
||||
// return -1 if unable to allocate blocks
|
||||
// PRUint8 mask = (0x01 << numBlocks) - 1;
|
||||
int i = 0;
|
||||
PRUint8 mapByte;
|
||||
PRUint8 mask;
|
||||
|
||||
// presume allocation will succeed
|
||||
PRBool oldValue = mBitMapDirty;
|
||||
mBitMapDirty = PR_TRUE;
|
||||
|
||||
while ((mBitMap[i] == 0xFF) && (i < kBitMapBytes)) ++i; // find first block with a free bit
|
||||
|
||||
if (numBlocks == 1) {
|
||||
if (i < kBitMapBytes) {
|
||||
// don't need a while loop, because we know there's at least 1 free bit in this byte
|
||||
mapByte = ~mBitMap[i]; // flip bits so free bits are 1
|
||||
/*
|
||||
* // Linear search for first free bit in byte
|
||||
* mask = 0x01;
|
||||
* for (int j=0; j<8; ++j, mask <<= 1)
|
||||
* if (mask & mapByte) {mBitMap[i] |= mask; return (i * 8 + j); }
|
||||
*/
|
||||
// Binary search for first free bit in byte
|
||||
PRUint8 bit = 0;
|
||||
if ((mapByte & 0x0F) == 0) { bit |= 4; mapByte >>= 4; }
|
||||
if ((mapByte & 0x03) == 0) { bit |= 2; mapByte >>= 2; }
|
||||
if ((mapByte & 0x01) == 0) { bit |= 1; mapByte >>= 1; }
|
||||
mBitMap[i] |= (PRUint8)1 << bit;
|
||||
return i * 8 + bit;
|
||||
}
|
||||
} else if (numBlocks == 2) {
|
||||
while (i < kBitMapBytes) {
|
||||
mapByte = ~mBitMap[i]; // flip bits so free bits are 1
|
||||
mask = 0x03;
|
||||
// check for fit in lower quad bits
|
||||
if ((mask & mapByte) == mask) { mBitMap[i] |= mask; return (i * 8); } mask <<= 1;
|
||||
if ((mask & mapByte) == mask) { mBitMap[i] |= mask; return (i * 8 + 1); } mask <<= 1;
|
||||
if ((mask & mapByte) == mask) { mBitMap[i] |= mask; return (i * 8 + 2); } mask <<= 2;
|
||||
// check for fit in upper quad bits
|
||||
if ((mask & mapByte) == mask) { mBitMap[i] |= mask; return (i * 8 + 4); } mask <<= 1;
|
||||
if ((mask & mapByte) == mask) { mBitMap[i] |= mask; return (i * 8 + 5); } mask <<= 1;
|
||||
if ((mask & mapByte) == mask) { mBitMap[i] |= mask; return (i * 8 + 6); }
|
||||
++i;
|
||||
}
|
||||
} else if (numBlocks == 3) {
|
||||
while (i < kBitMapBytes) {
|
||||
mapByte = ~mBitMap[i]; // flip bits so free bits are 1
|
||||
mask = 0x07;
|
||||
// check for fit in lower quad bits
|
||||
if ((mask & mapByte) == mask) { mBitMap[i] |= mask; return (i * 8); } mask <<= 1;
|
||||
if ((mask & mapByte) == mask) { mBitMap[i] |= mask; return (i * 8 + 1); } mask <<= 3;
|
||||
// check for fit in upper quad bits
|
||||
if ((mask & mapByte) == mask) { mBitMap[i] |= mask; return (i * 8 + 4); } mask <<= 1;
|
||||
if ((mask & mapByte) == mask) { mBitMap[i] |= mask; return (i * 8 + 5); }
|
||||
++i;
|
||||
}
|
||||
} else if (numBlocks == 4) {
|
||||
while (i < kBitMapBytes) {
|
||||
mapByte = ~mBitMap[i]; // flip bits so free bits are 1
|
||||
mask = 0x0F;
|
||||
// check for fit in lower quad bits
|
||||
if ((mask & mapByte) == mask) { mBitMap[i] |= mask; return (i * 8); } mask <<= 4;
|
||||
// check for fit in upper quad bits
|
||||
if ((mask & mapByte) == mask) { mBitMap[i] |= mask; return (i * 8 + 4); }
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
mBitMapDirty = oldValue;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* DeallocateBlocks
|
||||
*****************************************************************************/
|
||||
nsresult
|
||||
nsDiskCacheBlockFile::DeallocateBlocks( PRInt32 startBlock, PRInt32 numBlocks)
|
||||
{
|
||||
if (!mFD) return NS_ERROR_NOT_AVAILABLE;
|
||||
if ((startBlock < 0) || (startBlock > kBitMapBytes * 8 - 1) ||
|
||||
(numBlocks < 1) || (numBlocks > 4))
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
PRInt32 startByte = startBlock / 8;
|
||||
PRUint8 startBit = startBlock % 8;
|
||||
|
||||
// make sure requested deallocation doesn't span a byte boundary
|
||||
if ((startBlock + numBlocks - 1) / 8 != startByte) return NS_ERROR_UNEXPECTED;
|
||||
PRUint8 mask = ((0x01 << numBlocks) - 1) << startBit;
|
||||
|
||||
PRUint8 mapByte = ~mBitMap[startByte]; // flip so allocated bits are zero
|
||||
|
||||
// make sure requested deallocation is currently allocated
|
||||
if (mapByte & mask) return NS_ERROR_ABORT;
|
||||
|
||||
mBitMap[startByte] ^= mask; // flips the bits off;
|
||||
mBitMapDirty = PR_TRUE;
|
||||
// XXX rv = FlushBitMap(); // coherency vs. performance
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* WriteBlocks
|
||||
*****************************************************************************/
|
||||
nsresult
|
||||
nsDiskCacheBlockFile::WriteBlocks( void * buffer,
|
||||
PRInt32 startBlock,
|
||||
PRInt32 numBlocks)
|
||||
{
|
||||
// presume buffer != nsnull
|
||||
if (!mFD) return NS_ERROR_NOT_AVAILABLE;
|
||||
nsresult rv = VerifyAllocation(startBlock, numBlocks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// seek to block position
|
||||
PRInt32 blockPos = kBitMapBytes + startBlock * mBlockSize;
|
||||
PRInt32 filePos = PR_Seek(mFD, blockPos, PR_SEEK_SET);
|
||||
if (filePos != blockPos) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
if (mEndOfFile < (blockPos + numBlocks * mBlockSize))
|
||||
mEndOfFile = (blockPos + numBlocks * mBlockSize);
|
||||
|
||||
// write the blocks
|
||||
PRInt32 bytesToWrite = numBlocks * mBlockSize;
|
||||
PRInt32 bytesWritten = PR_Write(mFD, buffer, bytesToWrite);
|
||||
if (bytesWritten < bytesToWrite) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// write the bit map and flush the file
|
||||
// XXX rv = FlushBitMap();
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* ReadBlocks
|
||||
*****************************************************************************/
|
||||
nsresult
|
||||
nsDiskCacheBlockFile::ReadBlocks( void * buffer,
|
||||
PRInt32 startBlock,
|
||||
PRInt32 numBlocks)
|
||||
{
|
||||
// presume buffer != nsnull
|
||||
if (!mFD) return NS_ERROR_NOT_AVAILABLE;
|
||||
nsresult rv = VerifyAllocation(startBlock, numBlocks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// seek to block position
|
||||
PRInt32 blockPos = kBitMapBytes + startBlock * mBlockSize;
|
||||
PRInt32 filePos = PR_Seek(mFD, blockPos, PR_SEEK_SET);
|
||||
if (filePos != blockPos) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// read the blocks
|
||||
PRInt32 bytesToRead = numBlocks * mBlockSize;
|
||||
PRInt32 bytesRead = PR_Read(mFD, buffer, bytesToRead);
|
||||
if (bytesRead < bytesToRead) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* FlushBitMap
|
||||
*****************************************************************************/
|
||||
nsresult
|
||||
nsDiskCacheBlockFile::FlushBitMap()
|
||||
{
|
||||
if (!mBitMapDirty) return NS_OK;
|
||||
|
||||
// seek to bitmap
|
||||
PRInt32 filePos = PR_Seek(mFD, 0, PR_SEEK_SET);
|
||||
if (filePos != 0) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// write bitmap
|
||||
PRInt32 bytesWritten = PR_Write(mFD, mBitMap, kBitMapBytes);
|
||||
if (bytesWritten < kBitMapBytes) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
PRStatus err = PR_Sync(mFD);
|
||||
if (err != PR_SUCCESS) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
mBitMapDirty = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* ValidateFile
|
||||
*
|
||||
* Check size of file against last bit allocated for mBlockSize.
|
||||
*
|
||||
*****************************************************************************/
|
||||
nsresult
|
||||
nsDiskCacheBlockFile::ValidateFile()
|
||||
{
|
||||
PRInt32 estimatedSize = kBitMapBytes;
|
||||
PRInt32 lastBlock = LastBlock();
|
||||
if (lastBlock >= 0)
|
||||
estimatedSize += (lastBlock + 1) * mBlockSize;
|
||||
|
||||
// seek to beginning
|
||||
PRInt32 filePos = PR_Seek(mFD, 0, PR_SEEK_SET);
|
||||
if (filePos != 0) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
PRInt32 fileSize = PR_Available(mFD);
|
||||
|
||||
if (estimatedSize > fileSize)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* VerfiyAllocation
|
||||
*
|
||||
* Return values:
|
||||
* NS_OK if all bits are marked allocated
|
||||
* NS_ERROR_ILLEGAL_VALUE if parameters don't obey constraints
|
||||
* NS_ERROR_FAILURE if some or all the bits are marked unallocated
|
||||
*
|
||||
*****************************************************************************/
|
||||
nsresult
|
||||
nsDiskCacheBlockFile::VerifyAllocation( PRInt32 startBlock, PRInt32 numBlocks)
|
||||
{
|
||||
if ((startBlock < 0) || (startBlock > kBitMapBytes * 8 - 1) ||
|
||||
(numBlocks < 1) || (numBlocks > 4))
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
PRInt32 startByte = startBlock / 8;
|
||||
PRUint8 startBit = startBlock % 8;
|
||||
|
||||
// make sure requested deallocation doesn't span a byte boundary
|
||||
if ((startBlock + numBlocks - 1) / 8 != startByte) return NS_ERROR_ILLEGAL_VALUE;
|
||||
PRUint8 mask = ((0x01 << numBlocks) - 1) << startBit;
|
||||
|
||||
// check if all specified blocks are currently allocated
|
||||
if ((mBitMap[startByte] & mask) != mask) return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* LastBlock
|
||||
*
|
||||
* Return last block allocated or -1 if no blocks are allocated.
|
||||
*
|
||||
*****************************************************************************/
|
||||
PRInt32
|
||||
nsDiskCacheBlockFile::LastBlock()
|
||||
{
|
||||
// search for last byte in mBitMap with allocated bits
|
||||
PRInt32 i = kBitMapBytes;
|
||||
while (--i >= 0) {
|
||||
if (mBitMap[i]) break;
|
||||
}
|
||||
|
||||
if (i >= 0) {
|
||||
// binary search to find last allocated bit in byte
|
||||
PRUint8 mapByte = mBitMap[i];
|
||||
PRUint8 lastBit = 7;
|
||||
if ((mapByte & 0xF0) == 0) { lastBit ^= 4; mapByte <<= 4; }
|
||||
if ((mapByte & 0xC0) == 0) { lastBit ^= 2; mapByte <<= 2; }
|
||||
if ((mapByte & 0x80) == 0) { lastBit ^= 1; mapByte <<= 1; }
|
||||
return i * 8 + lastBit;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
76
mozilla/netwerk/cache/src/nsDiskCacheBlockFile.h
vendored
76
mozilla/netwerk/cache/src/nsDiskCacheBlockFile.h
vendored
@@ -1,76 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsDiskCacheBlockFile.h, released April 12, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsDiskCacheBlockFile_h_
|
||||
#define _nsDiskCacheBlockFile_h_
|
||||
|
||||
#include "nsILocalFile.h"
|
||||
#include "nspr.h"
|
||||
|
||||
enum { kBitMapBytes = 4096 };
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheBlockFile
|
||||
*
|
||||
* The structure of a cache block file is a 4096 bytes bit map, followed by
|
||||
* some number of blocks of mBlockSize. The creator of a
|
||||
* nsDiskCacheBlockFile object must provide the block size for a given file.
|
||||
*
|
||||
*****************************************************************************/
|
||||
class nsDiskCacheBlockFile {
|
||||
public:
|
||||
nsDiskCacheBlockFile()
|
||||
: mFD(nsnull)
|
||||
, mBlockSize(0)
|
||||
, mEndOfFile(0)
|
||||
, mBitMap(nsnull)
|
||||
, mBitMapDirty(PR_FALSE)
|
||||
{}
|
||||
~nsDiskCacheBlockFile() { (void) Close(); }
|
||||
|
||||
nsresult Open( nsILocalFile * blockFile, PRUint32 blockSize);
|
||||
nsresult Close();
|
||||
nsresult Trim();
|
||||
PRInt32 AllocateBlocks( PRInt32 numBlocks);
|
||||
nsresult DeallocateBlocks( PRInt32 startBlock, PRInt32 numBlocks);
|
||||
nsresult WriteBlocks( void * buffer, PRInt32 startBlock, PRInt32 numBlocks);
|
||||
nsresult ReadBlocks( void * buffer, PRInt32 startBlock, PRInt32 numBlocks);
|
||||
|
||||
private:
|
||||
nsresult FlushBitMap();
|
||||
nsresult ValidateFile(); // called by Open()
|
||||
nsresult VerifyAllocation( PRInt32 startBlock, PRInt32 numBLocks);
|
||||
PRInt32 LastBlock();
|
||||
|
||||
/**
|
||||
* Data members
|
||||
*/
|
||||
PRFileDesc * mFD;
|
||||
PRUint32 mBlockSize;
|
||||
PRUint32 mEndOfFile;
|
||||
PRUint8 * mBitMap; // XXX future: array of bit map blocks
|
||||
PRBool mBitMapDirty;
|
||||
};
|
||||
|
||||
#endif // _nsDiskCacheBlockFile_h_
|
||||
1092
mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp
vendored
1092
mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp
vendored
File diff suppressed because it is too large
Load Diff
96
mozilla/netwerk/cache/src/nsDiskCacheDevice.h
vendored
96
mozilla/netwerk/cache/src/nsDiskCacheDevice.h
vendored
@@ -1,96 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsDiskCacheDevice.h, released February 20, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsDiskCacheDevice_h_
|
||||
#define _nsDiskCacheDevice_h_
|
||||
|
||||
#include "nsCacheDevice.h"
|
||||
#include "nsDiskCacheBinding.h"
|
||||
#include "nsDiskCacheBlockFile.h"
|
||||
#include "nsDiskCacheEntry.h"
|
||||
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
class nsDiskCacheMap;
|
||||
|
||||
class nsDiskCacheDevice : public nsCacheDevice {
|
||||
public:
|
||||
nsDiskCacheDevice();
|
||||
virtual ~nsDiskCacheDevice();
|
||||
|
||||
static nsresult Create(nsCacheDevice **result);
|
||||
|
||||
virtual nsresult Init();
|
||||
virtual nsresult Shutdown();
|
||||
|
||||
virtual const char * GetDeviceID(void);
|
||||
virtual nsCacheEntry * FindEntry(nsCString * key);
|
||||
virtual nsresult DeactivateEntry(nsCacheEntry * entry);
|
||||
virtual nsresult BindEntry(nsCacheEntry * entry);
|
||||
virtual void DoomEntry( nsCacheEntry * entry );
|
||||
|
||||
virtual nsresult GetTransportForEntry(nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport ** result);
|
||||
|
||||
virtual nsresult GetFileForEntry(nsCacheEntry * entry,
|
||||
nsIFile ** result);
|
||||
|
||||
virtual nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
|
||||
|
||||
virtual nsresult Visit(nsICacheVisitor * visitor);
|
||||
|
||||
virtual nsresult EvictEntries(const char * clientID);
|
||||
|
||||
/* private: */
|
||||
void setPrefsObserver(nsIObserver * observer);
|
||||
void getPrefsObserver(nsIObserver ** result);
|
||||
void setCacheDirectory(nsILocalFile * directory);
|
||||
void getCacheDirectory(nsILocalFile ** result);
|
||||
void setCacheCapacity(PRUint32 capacity);
|
||||
PRUint32 getCacheCapacity();
|
||||
PRUint32 getCacheSize();
|
||||
PRUint32 getEntryCount();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Private methods
|
||||
*/
|
||||
nsresult InitializeCacheDirectory();
|
||||
nsresult GetCacheTrashDirectory(nsIFile ** result);
|
||||
nsresult EvictDiskCacheEntries();
|
||||
|
||||
/**
|
||||
* Member variables
|
||||
*/
|
||||
PRBool mInitialized;
|
||||
nsCOMPtr<nsIObserver> mPrefsObserver; // XXX ?
|
||||
nsCOMPtr<nsILocalFile> mCacheDirectory;
|
||||
nsDiskCacheBindery mBindery;
|
||||
PRUint32 mCacheCapacity; // XXX need soft/hard limits, currentTotal
|
||||
nsDiskCacheMap * mCacheMap;
|
||||
};
|
||||
|
||||
#endif // _nsDiskCacheDevice_h_
|
||||
211
mozilla/netwerk/cache/src/nsDiskCacheEntry.cpp
vendored
211
mozilla/netwerk/cache/src/nsDiskCacheEntry.cpp
vendored
@@ -1,211 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsDiskCacheEntry.cpp, released May 10, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsDiskCache.h"
|
||||
#include "nsDiskCacheEntry.h"
|
||||
#include "nsDiskCacheBinding.h"
|
||||
#include "nsDiskCacheMap.h"
|
||||
|
||||
#include "nsCache.h"
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheEntry
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* CreateCacheEntry()
|
||||
*
|
||||
* Creates an nsCacheEntry and sets all fields except for the binding.
|
||||
*/
|
||||
nsCacheEntry *
|
||||
nsDiskCacheEntry::CreateCacheEntry(nsCacheDevice * device)
|
||||
{
|
||||
nsCacheEntry * entry = nsnull;
|
||||
nsresult rv = nsCacheEntry::Create(mKeyStart,
|
||||
nsICache::STREAM_BASED,
|
||||
nsICache::STORE_ON_DISK,
|
||||
device,
|
||||
&entry);
|
||||
if (NS_FAILED(rv) || !entry) return nsnull;
|
||||
|
||||
entry->SetFetchCount(mFetchCount);
|
||||
entry->SetLastFetched(mLastFetched);
|
||||
entry->SetLastModified(mLastModified);
|
||||
entry->SetExpirationTime(mExpirationTime);
|
||||
entry->SetCacheDevice(device);
|
||||
// XXX why does nsCacheService have to fill out device in BindEntry()?
|
||||
entry->SetDataSize(mDataSize);
|
||||
|
||||
rv = entry->UnflattenMetaData(&mKeyStart[mKeySize], mMetaDataSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete entry;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* CheckConsistency()
|
||||
*
|
||||
* Perform a few simple checks to verify the data looks reasonable.
|
||||
*/
|
||||
PRBool
|
||||
nsDiskCacheEntry::CheckConsistency(PRUint32 size)
|
||||
{
|
||||
if ((mHeaderVersion != nsDiskCache::kCurrentVersion) ||
|
||||
(Size() > size) ||
|
||||
(mKeySize == 0) ||
|
||||
(mKeyStart[mKeySize - 1] != 0)) // key is null terminated
|
||||
return PR_FALSE;
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* CreateDiskCacheEntry(nsCacheEntry * entry)
|
||||
*
|
||||
* Prepare an nsCacheEntry for writing to disk
|
||||
*/
|
||||
nsDiskCacheEntry *
|
||||
CreateDiskCacheEntry(nsDiskCacheBinding * binding)
|
||||
{
|
||||
nsCacheEntry * entry = binding->mCacheEntry;
|
||||
if (!entry) return nsnull;
|
||||
|
||||
PRUint32 keySize = entry->Key()->Length() + 1;
|
||||
PRUint32 size = sizeof(nsDiskCacheEntry) +
|
||||
keySize + entry->MetaDataSize();
|
||||
|
||||
// pad size so we can write to block files without overrunning buffer
|
||||
PRInt32 pad = size;
|
||||
if (pad < 1024) pad = 1024;
|
||||
else if (pad < 4096) pad = 4096;
|
||||
else if (pad < 16384) pad = 16384;
|
||||
// XXX be more precise
|
||||
|
||||
nsDiskCacheEntry * diskEntry = (nsDiskCacheEntry *)new char[pad];
|
||||
if (!diskEntry) return nsnull;
|
||||
|
||||
diskEntry->mHeaderVersion = nsDiskCache::kCurrentVersion;
|
||||
diskEntry->mMetaLocation = binding->mRecord.MetaLocation();
|
||||
diskEntry->mFetchCount = entry->FetchCount();
|
||||
diskEntry->mLastFetched = entry->LastFetched();
|
||||
diskEntry->mLastModified = entry->LastModified();
|
||||
diskEntry->mExpirationTime = entry->ExpirationTime();
|
||||
diskEntry->mDataSize = entry->DataSize();
|
||||
diskEntry->mKeySize = keySize;
|
||||
diskEntry->mMetaDataSize = entry->MetaDataSize();
|
||||
|
||||
nsCRT::memcpy(diskEntry->mKeyStart, entry->Key()->get(),keySize);
|
||||
|
||||
// XXX FIXME FlattenMetaData should not allocate a buffer
|
||||
char * metaData = nsnull;
|
||||
PRUint32 metaSize = 0;
|
||||
nsresult rv = entry->FlattenMetaData(&metaData, &metaSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete diskEntry;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
diskEntry->mMetaDataSize = metaSize;
|
||||
if (metaSize)
|
||||
nsCRT::memcpy(&diskEntry->mKeyStart[keySize], metaData, metaSize);
|
||||
|
||||
delete metaData;
|
||||
return diskEntry;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheEntryInfo
|
||||
*****************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsDiskCacheEntryInfo, nsICacheEntryInfo);
|
||||
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::GetClientID(char ** clientID)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(clientID);
|
||||
return ClientIDFromCacheKey(nsLiteralCString(mDiskEntry->mKeyStart), clientID);
|
||||
}
|
||||
|
||||
extern const char DISK_CACHE_DEVICE_ID[];
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::GetDeviceID(char ** deviceID)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(deviceID);
|
||||
*deviceID = nsCRT::strdup(mDeviceID);
|
||||
return *deviceID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::GetKey(char ** clientKey)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(clientKey);
|
||||
return ClientKeyFromCacheKey(nsLiteralCString(mDiskEntry->mKeyStart), clientKey);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::GetFetchCount(PRInt32 *aFetchCount)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFetchCount);
|
||||
*aFetchCount = mDiskEntry->mFetchCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::GetLastFetched(PRUint32 *aLastFetched)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aLastFetched);
|
||||
*aLastFetched = mDiskEntry->mLastFetched;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::GetLastModified(PRUint32 *aLastModified)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aLastModified);
|
||||
*aLastModified = mDiskEntry->mLastModified;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::GetExpirationTime(PRUint32 *aExpirationTime)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aExpirationTime);
|
||||
*aExpirationTime = mDiskEntry->mExpirationTime;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::IsStreamBased(PRBool *aStreamBased)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aStreamBased);
|
||||
*aStreamBased = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::GetDataSize(PRUint32 *aDataSize)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDataSize);
|
||||
*aDataSize = mDiskEntry->mDataSize;
|
||||
return NS_OK;
|
||||
}
|
||||
126
mozilla/netwerk/cache/src/nsDiskCacheEntry.h
vendored
126
mozilla/netwerk/cache/src/nsDiskCacheEntry.h
vendored
@@ -1,126 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsMemoryCacheDevice.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsDiskCacheEntry_h_
|
||||
#define _nsDiskCacheEntry_h_
|
||||
|
||||
#include "nsDiskCacheMap.h"
|
||||
|
||||
#include "nsCacheEntry.h"
|
||||
|
||||
#include "nsICacheVisitor.h"
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nscore.h"
|
||||
#include "nsError.h"
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheEntry
|
||||
*****************************************************************************/
|
||||
struct nsDiskCacheEntry {
|
||||
PRUint32 mHeaderVersion; // useful for stand-alone metadata files
|
||||
PRUint32 mMetaLocation; // for verification
|
||||
PRInt32 mFetchCount;
|
||||
PRUint32 mLastFetched;
|
||||
PRUint32 mLastModified;
|
||||
PRUint32 mExpirationTime;
|
||||
PRUint32 mDataSize;
|
||||
PRUint32 mKeySize; // includes terminating null byte
|
||||
PRUint32 mMetaDataSize; // includes terminating null byte
|
||||
char mKeyStart[1]; // start of key data
|
||||
// mMetaDataStart = mKeyStart[mKeySize];
|
||||
|
||||
PRUint32 Size() { return sizeof(nsDiskCacheEntry)
|
||||
- sizeof(char) // subtract default key size
|
||||
+ mKeySize // plus actual key size
|
||||
+ mMetaDataSize;
|
||||
}
|
||||
|
||||
nsCacheEntry * CreateCacheEntry(nsCacheDevice * device);
|
||||
|
||||
PRBool CheckConsistency(PRUint32 size);
|
||||
|
||||
void Swap() // host to network (memory to disk)
|
||||
{
|
||||
#if defined(IS_LITTLE_ENDIAN)
|
||||
mHeaderVersion = ::PR_htonl(mHeaderVersion);
|
||||
mMetaLocation = ::PR_htonl(mMetaLocation);
|
||||
mFetchCount = ::PR_htonl(mFetchCount);
|
||||
mLastFetched = ::PR_htonl(mLastFetched);
|
||||
mLastModified = ::PR_htonl(mLastModified);
|
||||
mExpirationTime = ::PR_htonl(mExpirationTime);
|
||||
mDataSize = ::PR_htonl(mDataSize);
|
||||
mKeySize = ::PR_htonl(mKeySize);
|
||||
mMetaDataSize = ::PR_htonl(mMetaDataSize);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Unswap() // network to host (disk to memory)
|
||||
{
|
||||
#if defined(IS_LITTLE_ENDIAN)
|
||||
mHeaderVersion = ::PR_ntohl(mHeaderVersion);
|
||||
mMetaLocation = ::PR_ntohl(mMetaLocation);
|
||||
mFetchCount = ::PR_ntohl(mFetchCount);
|
||||
mLastFetched = ::PR_ntohl(mLastFetched);
|
||||
mLastModified = ::PR_ntohl(mLastModified);
|
||||
mExpirationTime = ::PR_ntohl(mExpirationTime);
|
||||
mDataSize = ::PR_ntohl(mDataSize);
|
||||
mKeySize = ::PR_ntohl(mKeySize);
|
||||
mMetaDataSize = ::PR_ntohl(mMetaDataSize);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
nsDiskCacheEntry * CreateDiskCacheEntry(nsDiskCacheBinding * binding);
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheEntryInfo
|
||||
*****************************************************************************/
|
||||
class nsDiskCacheEntryInfo : public nsICacheEntryInfo {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHEENTRYINFO
|
||||
|
||||
nsDiskCacheEntryInfo(const char * deviceID, nsDiskCacheEntry * diskEntry)
|
||||
: mDeviceID(deviceID)
|
||||
, mDiskEntry(diskEntry)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
virtual ~nsDiskCacheEntryInfo() {}
|
||||
|
||||
const char* Key() { return mDiskEntry->mKeyStart; }
|
||||
|
||||
private:
|
||||
const char * mDeviceID;
|
||||
nsDiskCacheEntry * mDiskEntry;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _nsDiskCacheEntry_h_ */
|
||||
836
mozilla/netwerk/cache/src/nsDiskCacheMap.cpp
vendored
836
mozilla/netwerk/cache/src/nsDiskCacheMap.cpp
vendored
@@ -1,836 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsDiskCacheMap.cpp, released March 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsDiskCacheMap.h"
|
||||
#include "nsDiskCacheBinding.h"
|
||||
#include "nsDiskCacheEntry.h"
|
||||
|
||||
#include "nsCache.h"
|
||||
|
||||
#include "nsCRT.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheBucket
|
||||
*****************************************************************************/
|
||||
|
||||
void
|
||||
nsDiskCacheBucket::Swap()
|
||||
{
|
||||
nsDiskCacheRecord * record = &mRecords[0];
|
||||
for (int i = 0; i < kRecordsPerBucket; ++i) {
|
||||
if (record->HashNumber() == 0)
|
||||
break;
|
||||
record->Swap();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsDiskCacheBucket::Unswap()
|
||||
{
|
||||
nsDiskCacheRecord * record = &mRecords[0];
|
||||
for (int i = 0; i < kRecordsPerBucket; ++i) {
|
||||
if (record->HashNumber() == 0)
|
||||
break;
|
||||
record->Unswap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PRUint32
|
||||
nsDiskCacheBucket::CountRecords()
|
||||
{
|
||||
if (mRecords[0].HashNumber() == 0) return 0;
|
||||
|
||||
PRUint32 i = kRecordsPerBucket >> 1;
|
||||
PRUint32 offset = kRecordsPerBucket >> 2;
|
||||
|
||||
while (offset > 0) {
|
||||
if (mRecords[i].HashNumber()) i += offset;
|
||||
else i -= offset;
|
||||
offset >>= 1;
|
||||
}
|
||||
|
||||
if (mRecords[i].HashNumber() != 0)
|
||||
++i;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
PRUint32
|
||||
nsDiskCacheBucket::EvictionRank()
|
||||
{
|
||||
PRUint32 rank = 0;
|
||||
for (int i = CountRecords() - 1; i >= 0; --i) {
|
||||
if (rank < mRecords[i].EvictionRank())
|
||||
rank = mRecords[i].EvictionRank();
|
||||
}
|
||||
return rank;
|
||||
}
|
||||
|
||||
|
||||
PRInt32
|
||||
nsDiskCacheBucket::VisitEachRecord(nsDiskCacheRecordVisitor * visitor,
|
||||
PRUint32 evictionRank,
|
||||
PRUint32 * result)
|
||||
{
|
||||
PRUint32 recordsDeleted = 0;
|
||||
PRInt32 rv = kVisitNextRecord;
|
||||
PRInt32 last = CountRecords() - 1;
|
||||
|
||||
// call visitor for each entry (equal or greater than evictionRank)
|
||||
for (int i = last; i >= 0; i--) {
|
||||
if (evictionRank > mRecords[i].EvictionRank()) continue;
|
||||
|
||||
rv = visitor->VisitRecord(&mRecords[i]);
|
||||
if (rv == kVisitNextRecord) continue;
|
||||
|
||||
if (rv == kDeleteRecordAndContinue) {
|
||||
mRecords[i] = mRecords[last];
|
||||
mRecords[last].SetHashNumber(0);
|
||||
--last;
|
||||
++recordsDeleted;
|
||||
continue;
|
||||
}
|
||||
|
||||
*result = recordsDeleted;
|
||||
return kStopVisitingRecords; // rv == kStopVisitingRecords
|
||||
}
|
||||
|
||||
*result = recordsDeleted;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheMap
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* File operations
|
||||
*/
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::Open(nsILocalFile * cacheDirectory)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(cacheDirectory);
|
||||
if (mMapFD) return NS_ERROR_ALREADY_INITIALIZED;
|
||||
|
||||
mCacheDirectory = cacheDirectory; // save a reference for ourselves
|
||||
|
||||
// create nsILocalFile for _CACHE_MAP_
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> file;
|
||||
rv = cacheDirectory->Clone(getter_AddRefs(file));
|
||||
nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(file, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = localFile->Append("_CACHE_MAP_");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// open the file
|
||||
rv = localFile->OpenNSPRFileDesc(PR_RDWR | PR_CREATE_FILE, 00666, &mMapFD);
|
||||
if (NS_FAILED(rv)) return rv; // unable to open or create file
|
||||
|
||||
// check size of map file
|
||||
PRUint32 mapSize = PR_Available(mMapFD);
|
||||
if (mapSize < 0) {
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
if (mapSize == 0) {
|
||||
// create the file - initialize in memory
|
||||
mHeader.mVersion = nsDiskCache::kCurrentVersion;
|
||||
mHeader.mDataSize = 0;
|
||||
mHeader.mEntryCount = 0;
|
||||
mHeader.mIsDirty = PR_TRUE;
|
||||
for (int i = 0; i < kBucketsPerTable; ++i) {
|
||||
mHeader.mEvictionRank[i] = 0;
|
||||
}
|
||||
|
||||
nsCRT::zero(mHeader.reserved, nsDiskCacheHeader::kReservedBytes);
|
||||
nsCRT::zero(mBuckets, sizeof(nsDiskCacheBucket) * kBucketsPerTable);
|
||||
|
||||
} else if (mapSize == kCacheMapSize) {
|
||||
// read it in
|
||||
PRUint32 bytesRead = PR_Read(mMapFD, &mHeader, kCacheMapSize);
|
||||
if (kCacheMapSize != bytesRead) {
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
goto error_exit;
|
||||
}
|
||||
mHeader.Unswap();
|
||||
if (mHeader.mIsDirty || mHeader.mVersion != nsDiskCache::kCurrentVersion) {
|
||||
rv = NS_ERROR_FILE_CORRUPTED;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
// Unswap each bucket
|
||||
for (PRUint32 i = 0; i < kBucketsPerTable; ++i) {
|
||||
mBuckets[i].Unswap();
|
||||
}
|
||||
|
||||
// XXX verify entry count, check size(?)
|
||||
|
||||
} else {
|
||||
rv = NS_ERROR_FILE_CORRUPTED;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
rv = OpenBlockFiles();
|
||||
if (NS_FAILED(rv)) goto error_exit;
|
||||
|
||||
// set dirty bit and flush header
|
||||
mHeader.mIsDirty = PR_TRUE;
|
||||
rv = FlushHeader();
|
||||
if (NS_FAILED(rv)) goto error_exit;
|
||||
|
||||
return NS_OK;
|
||||
|
||||
error_exit:
|
||||
(void) CloseBlockFiles();
|
||||
|
||||
if (mMapFD) {
|
||||
(void) PR_Close(mMapFD);
|
||||
mMapFD = nsnull;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::Close()
|
||||
{
|
||||
if (!mMapFD) return NS_OK;
|
||||
|
||||
// close block files
|
||||
nsresult rv = CloseBlockFiles();
|
||||
if (NS_FAILED(rv)) goto exit; // this is going to be a mess...
|
||||
|
||||
// write map record buckets
|
||||
rv = FlushBuckets(PR_FALSE); // don't bother swapping buckets back
|
||||
if (NS_FAILED(rv)) goto exit;
|
||||
|
||||
// clear dirty bit
|
||||
mHeader.mIsDirty = PR_FALSE;
|
||||
|
||||
rv = FlushHeader();
|
||||
|
||||
exit:
|
||||
PRStatus err = PR_Close(mMapFD);
|
||||
mMapFD = nsnull;
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return err == PR_SUCCESS ? NS_OK : NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::FlushHeader()
|
||||
{
|
||||
if (!mMapFD) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
// seek to beginning of cache map
|
||||
PRInt32 filePos = PR_Seek(mMapFD, 0, PR_SEEK_SET);
|
||||
if (filePos != 0) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// write the header
|
||||
mHeader.Swap();
|
||||
PRInt32 bytesWritten = PR_Write(mMapFD, &mHeader, sizeof(nsDiskCacheHeader));
|
||||
mHeader.Unswap();
|
||||
if (sizeof(nsDiskCacheHeader) != bytesWritten) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::FlushBuckets(PRBool unswap)
|
||||
{
|
||||
if (!mMapFD) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
// seek to beginning of buckets
|
||||
PRInt32 filePos = PR_Seek(mMapFD, sizeof(nsDiskCacheHeader), PR_SEEK_SET);
|
||||
if (filePos != sizeof(nsDiskCacheHeader)) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// Swap each bucket
|
||||
for (PRUint32 i = 0; i < kBucketsPerTable; ++i) {
|
||||
mBuckets[i].Swap();
|
||||
}
|
||||
|
||||
PRInt32 bytesWritten = PR_Write(mMapFD, &mBuckets, sizeof(nsDiskCacheBucket) * kBucketsPerTable);
|
||||
|
||||
if (unswap) {
|
||||
// Unswap each bucket
|
||||
for (PRUint32 i = 0; i < kBucketsPerTable; ++i) {
|
||||
mBuckets[i].Unswap();
|
||||
}
|
||||
}
|
||||
|
||||
if ( sizeof(nsDiskCacheBucket) * kBucketsPerTable != bytesWritten) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Record operations
|
||||
*/
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::AddRecord( nsDiskCacheRecord * mapRecord,
|
||||
nsDiskCacheRecord * oldRecord)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 hashNumber = mapRecord->HashNumber();
|
||||
nsDiskCacheBucket * bucket;
|
||||
PRUint32 bucketIndex = GetBucketIndex(hashNumber);
|
||||
int i;
|
||||
|
||||
oldRecord->SetHashNumber(0); // signify no record
|
||||
|
||||
rv = GetBucketForHashNumber(hashNumber, &bucket);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsDiskCacheRecord * mostEvictable = &bucket->mRecords[0];
|
||||
for (i = 0; i < kRecordsPerBucket; ++i) {
|
||||
if (bucket->mRecords[i].HashNumber() == 0) {
|
||||
// stick the new record here
|
||||
bucket->mRecords[i] = *mapRecord;
|
||||
++mHeader.mEntryCount;
|
||||
|
||||
// update eviction rank in header if necessary
|
||||
if (mHeader.mEvictionRank[bucketIndex] < mapRecord->EvictionRank())
|
||||
mHeader.mEvictionRank[bucketIndex] = mapRecord->EvictionRank();
|
||||
|
||||
NS_ASSERTION(mHeader.mEvictionRank[bucketIndex] == bucket->EvictionRank(), "whao!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (bucket->mRecords[i].EvictionRank() > mostEvictable->EvictionRank())
|
||||
mostEvictable = &bucket->mRecords[i];
|
||||
}
|
||||
|
||||
*oldRecord = *mostEvictable; // i == kRecordsPerBucket, so evict the mostEvictable
|
||||
*mostEvictable = *mapRecord; // replace it with the new record
|
||||
|
||||
// check if we need to update mostEvictable entry in header
|
||||
if ((oldRecord->HashNumber() != 0) ||
|
||||
(mapRecord->EvictionRank() > mHeader.mEvictionRank[bucketIndex])) {
|
||||
|
||||
mHeader.mEvictionRank[bucketIndex] = bucket->EvictionRank();
|
||||
}
|
||||
|
||||
NS_ASSERTION(mHeader.mEvictionRank[bucketIndex] == bucket->EvictionRank(), "whao!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::UpdateRecord( nsDiskCacheRecord * mapRecord)
|
||||
{
|
||||
PRUint32 hashNumber = mapRecord->HashNumber();
|
||||
nsDiskCacheBucket * bucket;
|
||||
nsresult rv = GetBucketForHashNumber(hashNumber, &bucket);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
for (int i = 0; i < kRecordsPerBucket; ++i) {
|
||||
if (bucket->mRecords[i].HashNumber() == mapRecord->HashNumber()) {
|
||||
PRUint32 oldRank = bucket->mRecords[i].EvictionRank();
|
||||
|
||||
// stick the new record here
|
||||
bucket->mRecords[i] = *mapRecord;
|
||||
|
||||
// update eviction rank in header if necessary
|
||||
PRUint32 bucketIndex = GetBucketIndex(mapRecord->HashNumber());
|
||||
if (mHeader.mEvictionRank[bucketIndex] < mapRecord->EvictionRank())
|
||||
mHeader.mEvictionRank[bucketIndex] = mapRecord->EvictionRank();
|
||||
else if (mHeader.mEvictionRank[bucketIndex] == oldRank)
|
||||
mHeader.mEvictionRank[bucketIndex] = bucket->EvictionRank();
|
||||
|
||||
NS_ASSERTION(mHeader.mEvictionRank[bucketIndex] == bucket->EvictionRank(), "whao!");
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::FindRecord( PRUint32 hashNumber, nsDiskCacheRecord * result)
|
||||
{
|
||||
nsDiskCacheBucket * bucket;
|
||||
nsresult rv = GetBucketForHashNumber(hashNumber, &bucket);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
for (int i = 0; i < kRecordsPerBucket; ++i) {
|
||||
if (bucket->mRecords[i].HashNumber() == 0) break;
|
||||
|
||||
if (bucket->mRecords[i].HashNumber() == hashNumber) {
|
||||
*result = bucket->mRecords[i]; // copy the record
|
||||
NS_ASSERTION(result->ValidRecord(), "bad cache map record");
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_CACHE_KEY_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::DeleteRecord( nsDiskCacheRecord * mapRecord)
|
||||
{
|
||||
nsDiskCacheBucket * bucket;
|
||||
nsresult rv = GetBucketForHashNumber(mapRecord->HashNumber(), &bucket);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRUint32 count = bucket->CountRecords();
|
||||
for (PRUint32 i = 0; i < count; ++i) {
|
||||
if (bucket->mRecords[i].HashNumber() == mapRecord->HashNumber()) {
|
||||
// found it, now delete it.
|
||||
PRUint32 evictionRank = bucket->mRecords[i].EvictionRank();
|
||||
NS_ASSERTION(evictionRank == mapRecord->EvictionRank(), "evictionRank out of sync");
|
||||
if (i != (count - 1)) { // if not the last record, shift last record into opening
|
||||
bucket->mRecords[i] = bucket->mRecords[count - 1];
|
||||
}
|
||||
bucket->mRecords[count - 1].SetHashNumber(0); // clear last record
|
||||
mHeader.mEntryCount--;
|
||||
// update eviction rank
|
||||
PRUint32 bucketIndex = GetBucketIndex(mapRecord->HashNumber());
|
||||
if (mHeader.mEvictionRank[bucketIndex] <= evictionRank) {
|
||||
mHeader.mEvictionRank[bucketIndex] = bucket->EvictionRank();
|
||||
}
|
||||
|
||||
NS_ASSERTION(mHeader.mEvictionRank[bucketIndex] == bucket->EvictionRank(), "whao!");
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* VisitRecords
|
||||
*
|
||||
* Visit every record in cache map in the most convenient order
|
||||
*/
|
||||
nsresult
|
||||
nsDiskCacheMap::VisitRecords( nsDiskCacheRecordVisitor * visitor)
|
||||
{
|
||||
for (PRUint32 i = 0; i < kBucketsPerTable; ++i) {
|
||||
// get bucket
|
||||
PRUint32 recordsDeleted;
|
||||
PRBool continueFlag = mBuckets[i].VisitEachRecord(visitor, 0, &recordsDeleted);
|
||||
if (recordsDeleted) {
|
||||
// recalc eviction rank
|
||||
mHeader.mEvictionRank[i] = mBuckets[i].EvictionRank();
|
||||
mHeader.mEntryCount -= recordsDeleted;
|
||||
// XXX write bucket
|
||||
}
|
||||
NS_ASSERTION(mHeader.mEvictionRank[i] == mBuckets[i].EvictionRank(), "whao!");
|
||||
if (!continueFlag) break;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* EvictRecords
|
||||
*
|
||||
* Just like VisitRecords, but visits the records in order of their eviction rank
|
||||
*/
|
||||
nsresult
|
||||
nsDiskCacheMap::EvictRecords( nsDiskCacheRecordVisitor * visitor)
|
||||
{
|
||||
while (1) {
|
||||
|
||||
// find bucket with highest eviction rank
|
||||
PRUint32 rank = 0;
|
||||
PRUint32 index = 0;
|
||||
for (int i = 0; i < kBucketsPerTable; ++i) {
|
||||
if (rank < mHeader.mEvictionRank[i]) {
|
||||
rank = mHeader.mEvictionRank[i];
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
|
||||
NS_ASSERTION(mHeader.mEvictionRank[index] == mBuckets[index].EvictionRank(),
|
||||
"header eviction rank out of sync");
|
||||
|
||||
// visit records in bucket with eviction ranks >= target eviction rank
|
||||
PRUint32 recordsDeleted;
|
||||
PRBool continueFlag = mBuckets[index].VisitEachRecord(visitor, rank, &recordsDeleted);
|
||||
if (recordsDeleted) {
|
||||
// recalc eviction rank
|
||||
mHeader.mEvictionRank[index] = mBuckets[index].EvictionRank();
|
||||
mHeader.mEntryCount -= recordsDeleted;
|
||||
// XXX write bucket
|
||||
}
|
||||
if (!continueFlag) break;
|
||||
|
||||
// break if visitor returned stop
|
||||
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::OpenBlockFiles()
|
||||
{
|
||||
// create nsILocalFile for block file
|
||||
nsCOMPtr<nsILocalFile> blockFile;
|
||||
nsresult rv;
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
rv = GetBlockFileForIndex(i, getter_AddRefs(blockFile));
|
||||
if (NS_FAILED(rv)) goto error_exit;
|
||||
|
||||
PRUint32 blockSize = GetBlockSizeForIndex(i);
|
||||
rv = mBlockFile[i].Open(blockFile, blockSize);
|
||||
if (NS_FAILED(rv)) goto error_exit;
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
error_exit:
|
||||
(void)CloseBlockFiles(); // we already have an error to report
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::CloseBlockFiles()
|
||||
{
|
||||
nsresult rv, rv2 = NS_OK;
|
||||
for (int i=0; i < 3; ++i) {
|
||||
rv = mBlockFile[i].Close();
|
||||
if (NS_FAILED(rv)) rv2 = rv; // if one or more errors, report at least one
|
||||
}
|
||||
return rv2;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::ReadDiskCacheEntry(nsDiskCacheRecord * record, nsDiskCacheEntry ** result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsDiskCacheEntry * diskEntry = nsnull;
|
||||
PRUint32 metaFile = record->MetaFile();
|
||||
PRFileDesc * fd = nsnull;
|
||||
*result = nsnull;
|
||||
|
||||
if (metaFile == 0) { // entry/metadata stored in separate file
|
||||
// open and read the file
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
rv = GetLocalFileForDiskCacheRecord(record, nsDiskCache::kMetaData, getter_AddRefs(file));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRFileDesc * fd = nsnull;
|
||||
nsresult rv = file->OpenNSPRFileDesc(PR_RDONLY, 00666, &fd);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRInt32 fileSize = PR_Available(fd);
|
||||
if (fileSize < 0) {
|
||||
// XXX an error occurred. We could call PR_GetError(), but how would that help?
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
diskEntry = (nsDiskCacheEntry *) new char[fileSize];
|
||||
if (!diskEntry) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
PRInt32 bytesRead = PR_Read(fd, diskEntry, fileSize);
|
||||
if (bytesRead < fileSize) {
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
} else if (metaFile < 4) { // XXX magic number: use constant
|
||||
// entry/metadata stored in cache block file
|
||||
|
||||
// allocate buffer
|
||||
PRUint32 blockSize = GetBlockSizeForIndex(metaFile - 1);
|
||||
PRUint32 blockCount = record->MetaBlockCount();
|
||||
diskEntry = (nsDiskCacheEntry *) new char[blockSize * blockCount];
|
||||
|
||||
// read diskEntry
|
||||
rv = mBlockFile[metaFile - 1].ReadBlocks((char *)diskEntry,
|
||||
record->MetaStartBlock(),
|
||||
blockCount);
|
||||
if (NS_FAILED(rv)) goto exit;
|
||||
}
|
||||
|
||||
diskEntry->Unswap(); // disk to memory
|
||||
// pass ownership to caller
|
||||
*result = diskEntry;
|
||||
diskEntry = nsnull;
|
||||
|
||||
exit:
|
||||
// XXX auto ptr would be nice
|
||||
if (fd) (void) PR_Close(fd);
|
||||
delete diskEntry;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::WriteDiskCacheEntry(nsDiskCacheBinding * binding)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsDiskCacheEntry * diskEntry = CreateDiskCacheEntry(binding);
|
||||
if (!diskEntry) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
binding->mRecord.SetEvictionRank(ULONG_MAX - SecondsFromPRTime(PR_Now()));
|
||||
|
||||
PRUint32 size = diskEntry->Size();
|
||||
PRUint32 fileIndex;
|
||||
PRUint32 blocks;
|
||||
|
||||
if (size < 1024) { // block size 256
|
||||
fileIndex = 1;
|
||||
blocks = size / 256 + 1;
|
||||
} else if (size < 4096) { // block size 1024
|
||||
fileIndex = 2;
|
||||
blocks = size / 1024 + 1;
|
||||
} else if (size < 16384) { // block size 4096
|
||||
fileIndex = 3;
|
||||
blocks = size / 4096 + 1;
|
||||
} else { // separate file
|
||||
fileIndex = 0;
|
||||
}
|
||||
|
||||
PRUint32 metaFile = binding->mRecord.MetaFile();
|
||||
|
||||
// Deallocate old storage if necessary
|
||||
if (binding->mRecord.MetaLocationInitialized()) {
|
||||
// we have existing storage
|
||||
|
||||
if ((metaFile == 0) && (fileIndex == 0)) { // keeping the separate file
|
||||
// just decrement total
|
||||
// XXX if bindRecord.MetaFileSize == USHRT_MAX, stat the file to see how big it is
|
||||
DecrementTotalSize(binding->mRecord.MetaFileSize() * 1024);
|
||||
NS_ASSERTION(binding->mRecord.MetaFileGeneration() == binding->mGeneration,
|
||||
"generations out of sync");
|
||||
} else {
|
||||
rv = DeleteStorage(&binding->mRecord, nsDiskCache::kMetaData);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if (fileIndex == 0) {
|
||||
// Write entry data to separate file
|
||||
PRUint32 metaFileSizeK = ((size + 0x0399) >> 10); // round up to nearest 1k
|
||||
nsCOMPtr<nsILocalFile> localFile;
|
||||
|
||||
// XXX handle metaFileSizeK > USHRT_MAX
|
||||
binding->mRecord.SetMetaFileGeneration(binding->mGeneration);
|
||||
binding->mRecord.SetMetaFileSize(metaFileSizeK);
|
||||
rv = UpdateRecord(&binding->mRecord);
|
||||
if (NS_FAILED(rv)) goto exit;
|
||||
|
||||
rv = GetLocalFileForDiskCacheRecord(&binding->mRecord,
|
||||
nsDiskCache::kMetaData,
|
||||
getter_AddRefs(localFile));
|
||||
if (NS_FAILED(rv)) goto exit;
|
||||
|
||||
// open the file
|
||||
PRFileDesc * fd;
|
||||
rv = localFile->OpenNSPRFileDesc(PR_RDWR | PR_TRUNCATE | PR_CREATE_FILE, 00666, &fd);
|
||||
if (NS_FAILED(rv)) goto exit; // unable to open or create file
|
||||
|
||||
// write the file
|
||||
diskEntry->Swap();
|
||||
PRInt32 bytesWritten = PR_Write(fd, diskEntry, size);
|
||||
|
||||
PRStatus err = PR_Close(mMapFD);
|
||||
if ((bytesWritten != size) || (err != PR_SUCCESS)) {
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
goto exit;
|
||||
}
|
||||
// XXX handle metaFileSizeK == USHRT_MAX
|
||||
IncrementTotalSize(metaFileSizeK * 1024);
|
||||
|
||||
} else {
|
||||
// write entry data to disk cache block file
|
||||
PRInt32 startBlock = mBlockFile[fileIndex - 1].AllocateBlocks(blocks);
|
||||
if (startBlock < 0) {
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// update binding and cache map record
|
||||
binding->mRecord.SetMetaBlocks(fileIndex, startBlock, blocks);
|
||||
rv = UpdateRecord(&binding->mRecord);
|
||||
if (NS_FAILED(rv)) goto exit;
|
||||
// XXX we should probably write out bucket ourselves
|
||||
|
||||
// write data
|
||||
diskEntry->Swap();
|
||||
rv = mBlockFile[fileIndex - 1].WriteBlocks(diskEntry, startBlock, blocks);
|
||||
if (NS_FAILED(rv)) goto exit;
|
||||
|
||||
IncrementTotalSize(blocks * GetBlockSizeForIndex(fileIndex - 1));
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::DoomRecord(nsDiskCacheRecord * record)
|
||||
{
|
||||
nsresult rv = DeleteRecord(record);
|
||||
// XXX future: add record to doomed record journal
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::DeleteStorage(nsDiskCacheRecord * record)
|
||||
{
|
||||
nsresult rv1 = DeleteStorage(record, nsDiskCache::kData);
|
||||
nsresult rv2 = DeleteStorage(record, nsDiskCache::kMetaData);
|
||||
return NS_FAILED(rv1) ? rv1 : rv2;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::DeleteStorage(nsDiskCacheRecord * record, PRBool metaData)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 fileIndex = metaData ? record->MetaFile() : record->DataFile();
|
||||
nsCOMPtr<nsIFile> file;
|
||||
|
||||
if (fileIndex == 0) {
|
||||
// delete the file
|
||||
PRUint32 sizeK = metaData ? record->MetaFileSize() : record->DataFileSize();
|
||||
// XXX if sizeK == USHRT_MAX, stat file for actual size
|
||||
|
||||
rv = GetFileForDiskCacheRecord(record, metaData, getter_AddRefs(file));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = file->Delete(PR_FALSE); // false == non-recursive
|
||||
}
|
||||
DecrementTotalSize(sizeK * 1024);
|
||||
|
||||
} else if (fileIndex < 4) {
|
||||
// deallocate blocks
|
||||
PRInt32 startBlock = metaData ? record->MetaStartBlock() : record->DataStartBlock();
|
||||
PRInt32 blockCount = metaData ? record->MetaBlockCount() : record->DataBlockCount();
|
||||
|
||||
rv = mBlockFile[fileIndex - 1].DeallocateBlocks(startBlock, blockCount);
|
||||
DecrementTotalSize(blockCount * GetBlockSizeForIndex(fileIndex - 1));
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::DeleteRecordAndStorage(nsDiskCacheRecord * record)
|
||||
{
|
||||
nsresult rv1 = DeleteStorage(record);
|
||||
nsresult rv2 = DeleteRecord(record);
|
||||
return NS_FAILED(rv1) ? rv1 : rv2;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::GetFileForDiskCacheRecord(nsDiskCacheRecord * record,
|
||||
PRBool meta,
|
||||
nsIFile ** result)
|
||||
{
|
||||
if (!mCacheDirectory) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
nsCOMPtr<nsIFile> file;
|
||||
nsresult rv = mCacheDirectory->Clone(getter_AddRefs(file));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRInt16 generation = record->Generation();
|
||||
char name[32];
|
||||
::sprintf(name, "%08X%c%02X", record->HashNumber(), (meta ? 'm' : 'd'), generation);
|
||||
rv = file->Append(name);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_IF_ADDREF(*result = file);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::GetLocalFileForDiskCacheRecord(nsDiskCacheRecord * record,
|
||||
PRBool meta,
|
||||
nsILocalFile ** result)
|
||||
{
|
||||
nsCOMPtr<nsIFile> file;
|
||||
nsresult rv = GetFileForDiskCacheRecord(record, meta, getter_AddRefs(file));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(file, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_IF_ADDREF(*result = localFile);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheMap::GetBlockFileForIndex(PRUint32 index, nsILocalFile ** result)
|
||||
{
|
||||
if (!mCacheDirectory) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
nsCOMPtr<nsIFile> file;
|
||||
nsresult rv = mCacheDirectory->Clone(getter_AddRefs(file));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char name[32];
|
||||
::sprintf(name, "_CACHE_%03d_", index + 1);
|
||||
rv = file->Append(name);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(file, &rv);
|
||||
NS_IF_ADDREF(*result = localFile);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
PRUint32
|
||||
nsDiskCacheMap::GetBlockSizeForIndex(PRUint32 index)
|
||||
{
|
||||
return 256 << (2 * (index)); // XXX magic numbers
|
||||
|
||||
}
|
||||
499
mozilla/netwerk/cache/src/nsDiskCacheMap.h
vendored
499
mozilla/netwerk/cache/src/nsDiskCacheMap.h
vendored
@@ -1,499 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsDiskCacheMap.h, released March 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsDiskCacheMap_h_
|
||||
#define _nsDiskCacheMap_h_
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prnetdb.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsError.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
#include "nsDiskCache.h"
|
||||
#include "nsDiskCacheBlockFile.h"
|
||||
|
||||
|
||||
class nsDiskCacheBinding;
|
||||
class nsDiskCacheEntry;
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheRecord
|
||||
*
|
||||
* Cache Location Format
|
||||
*
|
||||
* 1000 0000 0000 0000 0000 0000 0000 0000 : initialized bit
|
||||
*
|
||||
* 0011 0000 0000 0000 0000 0000 0000 0000 : File Selector (0 = separate file)
|
||||
* 0000 0011 0000 0000 0000 0000 0000 0000 : number of extra contiguous blocks 1-4
|
||||
* 0100 1100 0000 0000 0000 0000 0000 0000 : reserved bits
|
||||
* 0000 0000 1111 1111 1111 1111 1111 1111 : block# 0-16777216 (2^24)
|
||||
*
|
||||
* 0000 0000 1111 1111 1111 1111 0000 0000 : eFileSizeMask (size of file in k: see note)
|
||||
* 0000 0000 0000 0000 0000 0000 1111 1111 : eFileGenerationMask
|
||||
*
|
||||
* File Selector:
|
||||
* 0 = separate file on disk
|
||||
* 1 = 256 byte block file
|
||||
* 2 = 1k block file
|
||||
* 3 = 4k block file
|
||||
*
|
||||
* eFileSizeMask note: Files larger than 64 Mb have zero size stored in the
|
||||
* location. The file itself must be examined to determine
|
||||
* its actual size.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
class nsDiskCacheRecord {
|
||||
|
||||
private:
|
||||
PRUint32 mHashNumber;
|
||||
PRUint32 mEvictionRank;
|
||||
PRUint32 mDataLocation;
|
||||
PRUint32 mMetaLocation;
|
||||
|
||||
enum {
|
||||
eLocationInitializedMask = 0x80000000,
|
||||
|
||||
eLocationSelectorMask = 0x30000000,
|
||||
eLocationSelectorOffset = 28,
|
||||
|
||||
eExtraBlocksMask = 0x03000000,
|
||||
eExtraBlocksOffset = 24,
|
||||
|
||||
eReservedMask = 0x4C000000,
|
||||
|
||||
eBlockNumberMask = 0x00FFFFFF,
|
||||
|
||||
eFileSizeMask = 0x00FFFF00,
|
||||
eFileSizeOffset = 8,
|
||||
eFileGenerationMask = 0x000000FF,
|
||||
eFileReservedMask = 0x4F000000
|
||||
|
||||
};
|
||||
|
||||
public:
|
||||
nsDiskCacheRecord()
|
||||
: mHashNumber(0), mEvictionRank(0), mDataLocation(0), mMetaLocation(0)
|
||||
{
|
||||
}
|
||||
|
||||
PRBool ValidRecord()
|
||||
{
|
||||
if ((mDataLocation & eReservedMask) || (mMetaLocation & eReservedMask))
|
||||
return PR_FALSE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// HashNumber accessors
|
||||
PRUint32 HashNumber() const { return mHashNumber; }
|
||||
void SetHashNumber( PRUint32 hashNumber) { mHashNumber = hashNumber; }
|
||||
|
||||
// EvictionRank accessors
|
||||
PRUint32 EvictionRank() const { return mEvictionRank; }
|
||||
void SetEvictionRank( PRUint32 rank) { mEvictionRank = rank; }
|
||||
|
||||
// DataLocation accessors
|
||||
PRBool DataLocationInitialized() { return mDataLocation & eLocationInitializedMask; }
|
||||
|
||||
PRUint32 DataLocation() { return mDataLocation; }
|
||||
void SetDataLocation( PRUint32 location) { mDataLocation = location; }
|
||||
|
||||
PRUint32 DataFile() const
|
||||
{
|
||||
return (PRUint32)(mDataLocation & eLocationSelectorMask) >> eLocationSelectorOffset;
|
||||
}
|
||||
|
||||
void SetDataBlocks( PRUint32 index, PRUint32 startBlock, PRUint32 blockCount)
|
||||
{
|
||||
// clear everything
|
||||
mDataLocation = 0;
|
||||
|
||||
// set file index
|
||||
NS_ASSERTION( index < 4,"invalid location index");
|
||||
NS_ASSERTION( index > 0,"invalid location index");
|
||||
mDataLocation |= (index << eLocationSelectorOffset) & eLocationSelectorMask;
|
||||
|
||||
// set startBlock
|
||||
NS_ASSERTION(startBlock == (startBlock & eBlockNumberMask), "invalid block number");
|
||||
mDataLocation |= startBlock & eBlockNumberMask;
|
||||
|
||||
// set blockCount
|
||||
NS_ASSERTION( (blockCount>=1) && (blockCount<=4),"invalid block count");
|
||||
blockCount = --blockCount;
|
||||
mDataLocation |= (blockCount << eExtraBlocksOffset) & eExtraBlocksMask;
|
||||
|
||||
mDataLocation |= eLocationInitializedMask;
|
||||
}
|
||||
|
||||
PRUint32 DataBlockCount() const
|
||||
{
|
||||
return (PRUint32)((mDataLocation & eExtraBlocksMask) >> eExtraBlocksOffset) + 1;
|
||||
}
|
||||
|
||||
PRUint32 DataStartBlock() const
|
||||
{
|
||||
return (mDataLocation & eBlockNumberMask);
|
||||
}
|
||||
|
||||
PRUint32 DataFileSize() const { return (mDataLocation & eFileSizeMask) >> eFileSizeOffset; }
|
||||
void SetDataFileSize(PRUint32 size)
|
||||
{
|
||||
NS_ASSERTION((mDataLocation & eFileReservedMask) == 0, "bad location");
|
||||
mDataLocation &= ~eFileSizeMask; // clear eFileSizeMask
|
||||
mDataLocation |= (size << eFileSizeOffset) & eFileSizeMask;
|
||||
}
|
||||
|
||||
PRUint16 DataFileGeneration() const
|
||||
{
|
||||
return (mDataLocation & eFileGenerationMask);
|
||||
}
|
||||
|
||||
void SetDataFileGeneration( PRUint8 generation)
|
||||
{
|
||||
// clear everything, (separate file index = 0)
|
||||
mDataLocation = 0;
|
||||
mDataLocation |= generation & eFileGenerationMask;
|
||||
mDataLocation |= eLocationInitializedMask;
|
||||
}
|
||||
|
||||
// MetaLocation accessors
|
||||
PRBool MetaLocationInitialized() { return mMetaLocation & eLocationInitializedMask; }
|
||||
|
||||
PRUint32 MetaLocation() { return mMetaLocation; }
|
||||
void SetMetaLocation( PRUint32 location) { mMetaLocation = location; }
|
||||
|
||||
PRUint32 MetaFile() const
|
||||
{
|
||||
return (PRUint32)(mMetaLocation & eLocationSelectorMask) >> eLocationSelectorOffset;
|
||||
}
|
||||
|
||||
void SetMetaBlocks( PRUint32 index, PRUint32 startBlock, PRUint32 blockCount)
|
||||
{
|
||||
// clear everything
|
||||
mMetaLocation = 0;
|
||||
|
||||
// set file index
|
||||
NS_ASSERTION( index < 4, "invalid location index");
|
||||
NS_ASSERTION( index > 0, "invalid location index");
|
||||
mMetaLocation |= (index << eLocationSelectorOffset) & eLocationSelectorMask;
|
||||
|
||||
// set startBlock
|
||||
NS_ASSERTION(startBlock == (startBlock & eBlockNumberMask), "invalid block number");
|
||||
mMetaLocation |= startBlock & eBlockNumberMask;
|
||||
|
||||
// set blockCount
|
||||
NS_ASSERTION( (blockCount>=1) && (blockCount<=4),"invalid block count");
|
||||
blockCount = --blockCount;
|
||||
mMetaLocation |= (blockCount << eExtraBlocksOffset) & eExtraBlocksMask;
|
||||
|
||||
mMetaLocation |= eLocationInitializedMask;
|
||||
}
|
||||
|
||||
PRUint32 MetaBlockCount() const
|
||||
{
|
||||
return (PRUint32)((mMetaLocation & eExtraBlocksMask) >> eExtraBlocksOffset) + 1;
|
||||
}
|
||||
|
||||
PRUint32 MetaStartBlock() const
|
||||
{
|
||||
return (mMetaLocation & eBlockNumberMask);
|
||||
}
|
||||
|
||||
PRUint32 MetaFileSize() const { return (mMetaLocation & eFileSizeMask) >> eFileSizeOffset; }
|
||||
void SetMetaFileSize(PRUint32 size)
|
||||
{
|
||||
mMetaLocation &= ~eFileSizeMask; // clear eFileSizeMask
|
||||
mMetaLocation |= (size << eFileSizeOffset) & eFileSizeMask;
|
||||
}
|
||||
|
||||
PRUint16 MetaFileGeneration() const
|
||||
{
|
||||
return (mMetaLocation & eFileGenerationMask);
|
||||
}
|
||||
|
||||
void SetMetaFileGeneration( PRUint8 generation)
|
||||
{
|
||||
// clear everything, (separate file index = 0)
|
||||
mMetaLocation = 0;
|
||||
mMetaLocation |= generation & eFileGenerationMask;
|
||||
mMetaLocation |= eLocationInitializedMask;
|
||||
}
|
||||
|
||||
PRUint8 Generation() const
|
||||
{
|
||||
if ((mDataLocation & eLocationInitializedMask) &&
|
||||
(DataFile() == 0))
|
||||
return DataFileGeneration();
|
||||
|
||||
if ((mMetaLocation & eLocationInitializedMask) &&
|
||||
(MetaFile() == 0))
|
||||
return MetaFileGeneration();
|
||||
|
||||
return 0; // no generation
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Swap()
|
||||
{
|
||||
#if defined(IS_LITTLE_ENDIAN)
|
||||
mHashNumber = ::PR_htonl(mHashNumber);
|
||||
mEvictionRank = ::PR_htonl(mEvictionRank);
|
||||
mDataLocation = ::PR_htonl(mDataLocation);
|
||||
mMetaLocation = ::PR_htonl(mMetaLocation);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Unswap()
|
||||
{
|
||||
#if defined(IS_LITTLE_ENDIAN)
|
||||
mHashNumber = ::PR_ntohl(mHashNumber);
|
||||
mEvictionRank = ::PR_ntohl(mEvictionRank);
|
||||
mDataLocation = ::PR_ntohl(mDataLocation);
|
||||
mMetaLocation = ::PR_ntohl(mMetaLocation);
|
||||
#endif
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheRecordVisitor
|
||||
*****************************************************************************/
|
||||
|
||||
enum { kDeleteRecordAndContinue = -1,
|
||||
kStopVisitingRecords = 0,
|
||||
kVisitNextRecord = 1
|
||||
};
|
||||
|
||||
class nsDiskCacheRecordVisitor {
|
||||
public:
|
||||
|
||||
virtual PRInt32 VisitRecord( nsDiskCacheRecord * mapRecord) = 0;
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheBucket
|
||||
*****************************************************************************/
|
||||
enum {
|
||||
kRecordsPerBucket = 256,
|
||||
kBucketsPerTable = (1 << 5) // must be a power of 2!
|
||||
};
|
||||
|
||||
struct nsDiskCacheBucket {
|
||||
nsDiskCacheRecord mRecords[kRecordsPerBucket];
|
||||
|
||||
void Swap();
|
||||
void Unswap();
|
||||
PRUint32 CountRecords();
|
||||
PRUint32 EvictionRank(); // return largest rank in bucket
|
||||
PRInt32 VisitEachRecord( nsDiskCacheRecordVisitor * visitor,
|
||||
PRUint32 evictionRank,
|
||||
PRUint32 * recordsDeleted);
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheHeader
|
||||
*****************************************************************************/
|
||||
|
||||
struct nsDiskCacheHeader {
|
||||
PRUint32 mVersion; // cache version.
|
||||
PRInt32 mDataSize; // size of cache in bytes.
|
||||
PRInt32 mEntryCount; // number of entries stored in cache.
|
||||
PRUint32 mIsDirty; // dirty flag.
|
||||
PRUint32 mEvictionRank[kBucketsPerTable];
|
||||
|
||||
// pad to blocksize
|
||||
enum { kReservedBytes = sizeof(nsDiskCacheBucket)
|
||||
- sizeof(PRUint32) * 4 // version, size, count, dirty
|
||||
- sizeof(PRUint32) * kBucketsPerTable // eviction array
|
||||
};
|
||||
|
||||
PRUint8 reserved[kReservedBytes];
|
||||
|
||||
// XXX need a bitmap?
|
||||
|
||||
nsDiskCacheHeader()
|
||||
: mVersion(nsDiskCache::kCurrentVersion)
|
||||
, mDataSize(0)
|
||||
, mEntryCount(0)
|
||||
, mIsDirty(PR_TRUE)
|
||||
{}
|
||||
|
||||
void Swap()
|
||||
{
|
||||
#if defined(IS_LITTLE_ENDIAN)
|
||||
mVersion = ::PR_htonl(mVersion);
|
||||
mDataSize = ::PR_htonl(mDataSize);
|
||||
mEntryCount = ::PR_htonl(mEntryCount);
|
||||
mIsDirty = ::PR_htonl(mIsDirty);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Unswap()
|
||||
{
|
||||
#if defined(IS_LITTLE_ENDIAN)
|
||||
mVersion = ::PR_ntohl(mVersion);
|
||||
mDataSize = ::PR_ntohl(mDataSize);
|
||||
mEntryCount = ::PR_ntohl(mEntryCount);
|
||||
mIsDirty = ::PR_ntohl(mIsDirty);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsDiskCacheMap
|
||||
*****************************************************************************/
|
||||
|
||||
// XXX fixed capacity for 8192 entries. Future: make dynamic
|
||||
|
||||
enum {
|
||||
kCacheMapSize = sizeof(nsDiskCacheHeader) +
|
||||
kBucketsPerTable * sizeof(nsDiskCacheBucket)
|
||||
};
|
||||
|
||||
|
||||
class nsDiskCacheMap {
|
||||
public:
|
||||
|
||||
nsDiskCacheMap()
|
||||
: mCacheDirectory(nsnull)
|
||||
, mMapFD(nsnull)
|
||||
{
|
||||
NS_ASSERTION(sizeof(nsDiskCacheHeader) == sizeof(nsDiskCacheBucket), "structure misalignment");
|
||||
}
|
||||
~nsDiskCacheMap() { (void) Close(); }
|
||||
|
||||
/**
|
||||
* File Operations
|
||||
*
|
||||
* Open
|
||||
*
|
||||
* Creates a new cache map file if one doesn't exist.
|
||||
* Returns error if it detects change in format or cache wasn't closed.
|
||||
*/
|
||||
nsresult Open( nsILocalFile * cacheDirectory);
|
||||
nsresult Close();
|
||||
|
||||
// nsresult Flush();
|
||||
nsresult FlushHeader();
|
||||
nsresult FlushBuckets( PRBool unswap);
|
||||
|
||||
/**
|
||||
* Record operations
|
||||
*/
|
||||
nsresult AddRecord( nsDiskCacheRecord * mapRecord, nsDiskCacheRecord * oldRecord);
|
||||
nsresult UpdateRecord( nsDiskCacheRecord * mapRecord);
|
||||
nsresult FindRecord( PRUint32 hashNumber, nsDiskCacheRecord * mapRecord);
|
||||
nsresult DeleteRecord( nsDiskCacheRecord * mapRecord);
|
||||
nsresult VisitRecords( nsDiskCacheRecordVisitor * visitor);
|
||||
nsresult EvictRecords( nsDiskCacheRecordVisitor * visitor);
|
||||
|
||||
/**
|
||||
* Disk Entry operations
|
||||
*/
|
||||
nsresult DoomRecord( nsDiskCacheRecord * record);
|
||||
nsresult DeleteStorage( nsDiskCacheRecord * record);
|
||||
nsresult DeleteRecordAndStorage( nsDiskCacheRecord * record);
|
||||
|
||||
nsresult GetFileForDiskCacheRecord( nsDiskCacheRecord * record,
|
||||
PRBool meta,
|
||||
nsIFile ** result);
|
||||
|
||||
nsresult GetLocalFileForDiskCacheRecord( nsDiskCacheRecord * record,
|
||||
PRBool meta,
|
||||
nsILocalFile ** result);
|
||||
|
||||
nsresult ReadDiskCacheEntry( nsDiskCacheRecord * record,
|
||||
nsDiskCacheEntry ** result);
|
||||
|
||||
nsresult WriteDiskCacheEntry( nsDiskCacheBinding * binding);
|
||||
|
||||
/**
|
||||
* Statistical Operations
|
||||
*/
|
||||
void IncrementTotalSize( PRInt32 delta)
|
||||
{
|
||||
NS_ASSERTION(mHeader.mDataSize >= 0, "disk cache size negative?");
|
||||
mHeader.mDataSize += delta;
|
||||
mHeader.mIsDirty = PR_TRUE;
|
||||
}
|
||||
|
||||
void DecrementTotalSize( PRInt32 delta)
|
||||
{
|
||||
mHeader.mDataSize -= delta;
|
||||
mHeader.mIsDirty = PR_TRUE;
|
||||
NS_ASSERTION(mHeader.mDataSize >= 0, "disk cache size negative?");
|
||||
}
|
||||
|
||||
PRInt32 TotalSize() { return mHeader.mDataSize; }
|
||||
|
||||
PRInt32 EntryCount() { return mHeader.mEntryCount; }
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Private methods
|
||||
*/
|
||||
nsresult OpenBlockFiles();
|
||||
nsresult CloseBlockFiles();
|
||||
|
||||
nsresult GetBlockFileForIndex( PRUint32 index, nsILocalFile ** result);
|
||||
PRUint32 GetBlockSizeForIndex( PRUint32 index);
|
||||
|
||||
nsresult DeleteStorage( nsDiskCacheRecord * record, PRBool metaData);
|
||||
|
||||
nsresult GetBucketForHashNumber( PRUint32 hashNumber, nsDiskCacheBucket ** result)
|
||||
{
|
||||
*result = &mBuckets[GetBucketIndex(hashNumber)];
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRUint32 GetBucketIndex( PRUint32 hashNumber)
|
||||
{
|
||||
return (hashNumber & (kBucketsPerTable - 1));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* data members
|
||||
*/
|
||||
private:
|
||||
nsCOMPtr<nsILocalFile> mCacheDirectory;
|
||||
PRFileDesc * mMapFD;
|
||||
nsDiskCacheBlockFile mBlockFile[3];
|
||||
nsDiskCacheHeader mHeader;
|
||||
nsDiskCacheBucket mBuckets[kBucketsPerTable];
|
||||
};
|
||||
|
||||
#endif // _nsDiskCacheMap_h_
|
||||
496
mozilla/netwerk/cache/src/nsMemoryCacheDevice.cpp
vendored
496
mozilla/netwerk/cache/src/nsMemoryCacheDevice.cpp
vendored
@@ -1,496 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsMemoryCacheDevice.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsMemoryCacheDevice.h"
|
||||
#include "nsCacheService.h"
|
||||
#include "nsICacheService.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsICacheVisitor.h"
|
||||
#include "nsITransport.h"
|
||||
#include "signal.h"
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kStorageTransportCID, NS_STORAGETRANSPORT_CID);
|
||||
|
||||
const char *gMemoryDeviceID = "memory";
|
||||
const char *gMemoryCacheSizePref = "browser.cache.memory_cache_size";
|
||||
|
||||
|
||||
nsMemoryCacheDevice::nsMemoryCacheDevice()
|
||||
: mEvictionThreshold(40 * 1024),
|
||||
mHardLimit(0),
|
||||
mSoftLimit(0),
|
||||
mTotalSize(0),
|
||||
mInactiveSize(0),
|
||||
mEntryCount(0),
|
||||
mMaxEntryCount(0)
|
||||
{
|
||||
PR_INIT_CLIST(&mEvictionList[mostLikelyToEvict]);
|
||||
PR_INIT_CLIST(&mEvictionList[leastLikelyToEvict]);
|
||||
}
|
||||
|
||||
|
||||
nsMemoryCacheDevice::~nsMemoryCacheDevice()
|
||||
{
|
||||
#if DEBUG
|
||||
printf("### starting ~nsMemoryCacheDevice()\n");
|
||||
#endif
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
prefs->UnregisterCallback(gMemoryCacheSizePref, MemoryCacheSizeChanged, this);
|
||||
}
|
||||
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
|
||||
int PR_CALLBACK
|
||||
nsMemoryCacheDevice::MemoryCacheSizeChanged(const char * pref, void * closure)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 softLimit = 0;
|
||||
nsMemoryCacheDevice * device = (nsMemoryCacheDevice *)closure;
|
||||
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = prefs->GetIntPref(gMemoryCacheSizePref, (PRInt32 *)&softLimit);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
softLimit *= 1024; // convert k into bytes
|
||||
PRUint32 hardLimit = softLimit + 1024*1024*2; // XXX find better limit than +2Meg
|
||||
device->AdjustMemoryLimits(softLimit, hardLimit);
|
||||
|
||||
return 0; // XXX what are we supposed to return?
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = mMemCacheEntries.Init();
|
||||
|
||||
// set some default memory limits, in case prefs aren't available
|
||||
mSoftLimit = 1024 * 1024 * 3;
|
||||
mHardLimit = mSoftLimit + 1024 *1024 * 2;
|
||||
|
||||
// read user prefs for memory cache limits
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
rv = prefs->RegisterCallback(gMemoryCacheSizePref, MemoryCacheSizeChanged, this);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Initialize the pref
|
||||
MemoryCacheSizeChanged(gMemoryCacheSizePref, this);
|
||||
}
|
||||
|
||||
// Register as a memory pressure observer
|
||||
NS_WITH_SERVICE(nsIObserverService,
|
||||
observerService,
|
||||
NS_OBSERVERSERVICE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// XXX rv = observerServcie->AddObserver(this, NS_MEMORY_PRESSURE_TOPIC);
|
||||
}
|
||||
// Ignore failure of memory pressure registration
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::Shutdown()
|
||||
{
|
||||
mMemCacheEntries.Shutdown();
|
||||
|
||||
// evict all entries
|
||||
nsCacheEntry * entry, * next;
|
||||
|
||||
for (int i=mostLikelyToEvict; i <= leastLikelyToEvict; ++i) {
|
||||
entry = (nsCacheEntry *)PR_LIST_HEAD(&mEvictionList[i]);
|
||||
while (entry != &mEvictionList[i]) {
|
||||
NS_ASSERTION(entry->IsInUse() == PR_FALSE, "### shutting down with active entries.\n");
|
||||
next = (nsCacheEntry *)PR_NEXT_LINK(entry);
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
|
||||
// update statistics
|
||||
PRUint32 memoryRecovered = entry->Size();
|
||||
mTotalSize -= memoryRecovered;
|
||||
mInactiveSize -= memoryRecovered;
|
||||
--mEntryCount;
|
||||
|
||||
delete entry;
|
||||
entry = next;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* we're not factoring in changes to meta data yet...
|
||||
* NS_ASSERTION(mTotalSize == 0, "### mem cache leaking entries?\n");
|
||||
*/
|
||||
NS_ASSERTION(mInactiveSize == 0, "### mem cache leaking entries?\n");
|
||||
NS_ASSERTION(mEntryCount == 0, "### mem cache leaking entries?\n");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const char *
|
||||
nsMemoryCacheDevice::GetDeviceID()
|
||||
{
|
||||
return gMemoryDeviceID;
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntry *
|
||||
nsMemoryCacheDevice::FindEntry(nsCString * key)
|
||||
{
|
||||
nsCacheEntry * entry = mMemCacheEntries.GetEntry(key);
|
||||
if (!entry) return nsnull;
|
||||
|
||||
// move entry to the tail of an eviction list
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
PR_APPEND_LINK(entry, &mEvictionList[EvictionList(entry, 0)]);
|
||||
|
||||
mInactiveSize -= entry->Size();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::DeactivateEntry(nsCacheEntry * entry)
|
||||
{
|
||||
if (entry->IsDoomed()) {
|
||||
#if debug
|
||||
// XXX verify we've removed it from mMemCacheEntries & eviction list
|
||||
#endif
|
||||
// update statistics
|
||||
mTotalSize -= entry->Size();
|
||||
--mEntryCount;
|
||||
|
||||
delete entry;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCacheEntry * ourEntry = mMemCacheEntries.GetEntry(entry->Key());
|
||||
NS_ASSERTION(ourEntry, "DeactivateEntry called for an entry we don't have!");
|
||||
NS_ASSERTION(entry == ourEntry, "entry doesn't match ourEntry");
|
||||
if (ourEntry != entry)
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
|
||||
mInactiveSize += entry->Size();
|
||||
EvictEntriesIfNecessary();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::BindEntry(nsCacheEntry * entry)
|
||||
{
|
||||
NS_ASSERTION(PR_CLIST_IS_EMPTY(entry),"entry is already on a list!");
|
||||
|
||||
if (!entry->IsDoomed()) {
|
||||
// append entry to the eviction list
|
||||
PR_APPEND_LINK(entry, &mEvictionList[EvictionList(entry, 0)]);
|
||||
|
||||
// add entry to hashtable of mem cache entries
|
||||
nsresult rv = mMemCacheEntries.AddEntry(entry);
|
||||
if (NS_FAILED(rv)) {
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// add size of entry to memory totals
|
||||
++mEntryCount;
|
||||
if (mMaxEntryCount < mEntryCount) mMaxEntryCount = mEntryCount;
|
||||
|
||||
mTotalSize += entry->Size();
|
||||
EvictEntriesIfNecessary();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsMemoryCacheDevice::DoomEntry(nsCacheEntry * entry)
|
||||
{
|
||||
// XXX debug code to verify we have entry
|
||||
mMemCacheEntries.RemoveEntry(entry);
|
||||
|
||||
// remove entry from our eviction list
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::GetTransportForEntry( nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport ** transport )
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(entry);
|
||||
NS_ENSURE_ARG_POINTER(transport);
|
||||
|
||||
nsCOMPtr<nsISupports> data;
|
||||
|
||||
nsresult rv = entry->GetData(getter_AddRefs(data));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (data)
|
||||
return CallQueryInterface(data, transport);
|
||||
else {
|
||||
// create a new transport for this entry
|
||||
rv = nsComponentManager::CreateInstance(kStorageTransportCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsITransport),
|
||||
(void **) transport);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
entry->SetData(*transport);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::GetFileForEntry( nsCacheEntry * entry,
|
||||
nsIFile ** result )
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize)
|
||||
{
|
||||
if (entry->IsStreamData()) {
|
||||
// we have the right to refuse or pre-evict
|
||||
}
|
||||
|
||||
// adjust our totals
|
||||
mTotalSize += deltaSize;
|
||||
|
||||
if (!entry->IsDoomed()) {
|
||||
// move entry to the tail of the appropriate eviction list
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
PR_APPEND_LINK(entry, &mEvictionList[EvictionList(entry, deltaSize)]);
|
||||
}
|
||||
|
||||
EvictEntriesIfNecessary();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsMemoryCacheDevice::AdjustMemoryLimits(PRUint32 softLimit, PRUint32 hardLimit)
|
||||
{
|
||||
mSoftLimit = softLimit;
|
||||
mHardLimit = hardLimit;
|
||||
EvictEntriesIfNecessary();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsMemoryCacheDevice::EvictEntry(nsCacheEntry * entry)
|
||||
{
|
||||
// remove entry from our hashtable
|
||||
mMemCacheEntries.RemoveEntry(entry);
|
||||
|
||||
// remove entry from the eviction list
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
|
||||
// update statistics
|
||||
PRUint32 memoryRecovered = entry->Size();
|
||||
mTotalSize -= memoryRecovered;
|
||||
mInactiveSize -= memoryRecovered;
|
||||
--mEntryCount;
|
||||
|
||||
delete entry;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsMemoryCacheDevice::EvictEntriesIfNecessary(void)
|
||||
{
|
||||
nsCacheEntry * entry, * next;
|
||||
|
||||
if ((mTotalSize < mHardLimit) && (mInactiveSize < mSoftLimit))
|
||||
return;
|
||||
|
||||
for (int i=mostLikelyToEvict; i<=leastLikelyToEvict; ++i) {
|
||||
entry = (nsCacheEntry *)PR_LIST_HEAD(&mEvictionList[i]);
|
||||
while (entry != &mEvictionList[i]) {
|
||||
if (entry->IsInUse()) {
|
||||
entry = (nsCacheEntry *)PR_NEXT_LINK(entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
next = (nsCacheEntry *)PR_NEXT_LINK(entry);
|
||||
EvictEntry(entry);
|
||||
entry = next;
|
||||
|
||||
if ((mTotalSize < mHardLimit) && (mInactiveSize < mSoftLimit))
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
nsMemoryCacheDevice::EvictionList(nsCacheEntry * entry, PRUint32 deltaSize)
|
||||
{
|
||||
PRUint32 size = entry->Size() + deltaSize;
|
||||
if ((size > mEvictionThreshold) || (entry->ExpirationTime() != 0))
|
||||
return mostLikelyToEvict;
|
||||
|
||||
return leastLikelyToEvict;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::Visit(nsICacheVisitor * visitor)
|
||||
{
|
||||
nsMemoryCacheDeviceInfo * deviceInfo = new nsMemoryCacheDeviceInfo(this);
|
||||
nsCOMPtr<nsICacheDeviceInfo> deviceRef(deviceInfo);
|
||||
if (!deviceInfo) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PRBool keepGoing;
|
||||
nsresult rv = visitor->VisitDevice(gMemoryDeviceID, deviceInfo, &keepGoing);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!keepGoing)
|
||||
return NS_OK;
|
||||
|
||||
nsCacheEntry * entry;
|
||||
nsCOMPtr<nsICacheEntryInfo> entryRef;
|
||||
|
||||
for (int i=mostLikelyToEvict; i <= leastLikelyToEvict; ++i) {
|
||||
entry = (nsCacheEntry *)PR_LIST_HEAD(&mEvictionList[i]);
|
||||
while (entry != &mEvictionList[i]) {
|
||||
nsCacheEntryInfo * entryInfo = new nsCacheEntryInfo(entry);
|
||||
if (!entryInfo) return NS_ERROR_OUT_OF_MEMORY;
|
||||
entryRef = entryInfo;
|
||||
|
||||
rv = visitor->VisitEntry(gMemoryDeviceID, entryInfo, &keepGoing);
|
||||
entryInfo->DetachEntry();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!keepGoing) break;
|
||||
|
||||
entry = (nsCacheEntry *)PR_NEXT_LINK(entry);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::EvictEntries(const char * clientID)
|
||||
{
|
||||
nsCacheEntry * entry;
|
||||
PRUint32 prefixLength = (clientID ? nsCRT::strlen(clientID) : 0);
|
||||
|
||||
for (int i=mostLikelyToEvict; i<=leastLikelyToEvict; ++i) {
|
||||
PRCList * elem = PR_LIST_HEAD(&mEvictionList[i]);
|
||||
while (elem != &mEvictionList[i]) {
|
||||
entry = (nsCacheEntry *)elem;
|
||||
elem = PR_NEXT_LINK(elem);
|
||||
|
||||
const char * key = entry->Key()->get();
|
||||
if (clientID && nsCRT::strncmp(clientID, key, prefixLength) != 0)
|
||||
continue;
|
||||
|
||||
if (entry->IsInUse()) {
|
||||
nsresult rv = nsCacheService::GlobalInstance()->DoomEntry_Locked(entry);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
} else {
|
||||
EvictEntry(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsMemoryCacheDeviceInfo - for implementing about:cache
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsMemoryCacheDeviceInfo, nsICacheDeviceInfo);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetDescription(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = nsCRT::strdup("Memory cache device");
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetUsageReport(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = nsCRT::strdup("Memory cache usage report:");
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetEntryCount(PRUint32 * result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
// XXX compare calculated count vs. mEntryCount
|
||||
*result = mDevice->mEntryCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetTotalSize(PRUint32 * result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = mDevice->mTotalSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetMaximumSize(PRUint32 * result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = mDevice->mHardLimit;
|
||||
return NS_OK;
|
||||
}
|
||||
119
mozilla/netwerk/cache/src/nsMemoryCacheDevice.h
vendored
119
mozilla/netwerk/cache/src/nsMemoryCacheDevice.h
vendored
@@ -1,119 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsMemoryCacheDevice.h, released February 20, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 20-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsMemoryCacheDevice_h_
|
||||
#define _nsMemoryCacheDevice_h_
|
||||
|
||||
#include "nsCacheDevice.h"
|
||||
#include "pldhash.h"
|
||||
#include "nsCacheEntry.h"
|
||||
|
||||
|
||||
class nsMemoryCacheDeviceInfo;
|
||||
|
||||
/******************************************************************************
|
||||
* nsMemoryCacheDevice
|
||||
******************************************************************************/
|
||||
class nsMemoryCacheDevice : public nsCacheDevice
|
||||
{
|
||||
public:
|
||||
nsMemoryCacheDevice();
|
||||
virtual ~nsMemoryCacheDevice();
|
||||
|
||||
virtual nsresult Init();
|
||||
virtual nsresult Shutdown();
|
||||
|
||||
virtual const char * GetDeviceID(void);
|
||||
|
||||
virtual nsresult BindEntry( nsCacheEntry * entry );
|
||||
virtual nsCacheEntry * FindEntry( nsCString * key );
|
||||
virtual void DoomEntry( nsCacheEntry * entry );
|
||||
virtual nsresult DeactivateEntry( nsCacheEntry * entry );
|
||||
|
||||
virtual nsresult GetTransportForEntry( nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport **transport );
|
||||
|
||||
virtual nsresult GetFileForEntry( nsCacheEntry * entry,
|
||||
nsIFile ** result );
|
||||
|
||||
virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize );
|
||||
|
||||
virtual nsresult Visit( nsICacheVisitor * visitor );
|
||||
|
||||
virtual nsresult EvictEntries(const char * clientID);
|
||||
|
||||
static int PR_CALLBACK MemoryCacheSizeChanged(const char * pref, void * closure);
|
||||
|
||||
private:
|
||||
friend class nsMemoryCacheDeviceInfo;
|
||||
void AdjustMemoryLimits( PRUint32 softLimit, PRUint32 hardLimit);
|
||||
void EvictEntry( nsCacheEntry * entry );
|
||||
void EvictEntriesIfNecessary();
|
||||
int EvictionList(nsCacheEntry * entry, PRUint32 deltaSize);
|
||||
|
||||
/*
|
||||
* Data members
|
||||
*/
|
||||
|
||||
nsCacheEntryHashTable mMemCacheEntries;
|
||||
|
||||
enum { mostLikelyToEvict = 0, leastLikelyToEvict = 1 }; // constants to differentiate eviction lists
|
||||
PRCList mEvictionList[2];
|
||||
PRUint32 mEvictionThreshold;
|
||||
|
||||
PRUint32 mHardLimit;
|
||||
PRUint32 mSoftLimit;
|
||||
|
||||
PRUint32 mTotalSize;
|
||||
PRUint32 mInactiveSize;
|
||||
|
||||
PRUint32 mEntryCount;
|
||||
|
||||
PRUint32 mMaxEntryCount;
|
||||
// XXX what other stats do we want to keep?
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsMemoryCacheDeviceInfo - used to call nsIVisitor for about:cache
|
||||
******************************************************************************/
|
||||
class nsMemoryCacheDeviceInfo : public nsICacheDeviceInfo {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHEDEVICEINFO
|
||||
|
||||
nsMemoryCacheDeviceInfo(nsMemoryCacheDevice* device)
|
||||
: mDevice(device)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
virtual ~nsMemoryCacheDeviceInfo() {}
|
||||
|
||||
private:
|
||||
nsMemoryCacheDevice* mDevice;
|
||||
};
|
||||
|
||||
|
||||
#endif // _nsMemoryCacheDevice_h_
|
||||
231
mozilla/netwerk/cache/src/win32.order
vendored
231
mozilla/netwerk/cache/src/win32.order
vendored
@@ -1,231 +0,0 @@
|
||||
?AddRef@nsCacheEntryDescriptor@@UAGKXZ ; 35743
|
||||
?HashKey@nsCacheEntryHashTable@@CAIPAUPLDHashTable@@PBX@Z ; 29743
|
||||
?Release@nsCacheEntryDescriptor@@UAGKXZ ; 21199
|
||||
??_EnsCString@@UAEPAXI@Z ; 19905
|
||||
?AddRef@nsCacheSession@@UAGKXZ ; 17435
|
||||
?GetEntry@nsCacheEntryHashTable@@QAEPAVnsCacheEntry@@PBVnsCString@@@Z ; 17433
|
||||
?SecondsFromPRTime@@YAI_J@Z ; 14263
|
||||
?CalculateSize@nsCacheMetaData@@CA?AW4PLDHashOperator@@PAUPLDHashTable@@PAUPLDHashEntryHdr@@IPAX@Z ; 14243
|
||||
?Release@nsCacheEntryInfo@@UAGKXZ ; 10964
|
||||
?GetLastModified@nsDiskCacheEntryInfo@@UAGIPAI@Z ; 9800
|
||||
?Release@nsANSIOutputStream@@UAGKXZ ; 9758
|
||||
?MatchEntry@nsCacheEntryHashTable@@CAHPAUPLDHashTable@@PBUPLDHashEntryHdr@@PBX@Z ; 9663
|
||||
?QueryInterface@nsCacheEntryInfo@@UAGIABUnsID@@PAPAX@Z ; 8638
|
||||
??Rdo_QueryElementAt@@UBEIABUnsID@@PAPAX@Z ; 8638
|
||||
?assign_assuming_AddRef@nsCOMPtr_base@@IAEXPAVnsISupports@@@Z ; 8259
|
||||
??0nsDiskCacheRecord@@QAE@XZ ; 8192
|
||||
?EnsureEntryHasDevice@nsCacheService@@AAEPAVnsCacheDevice@@PAVnsCacheEntry@@@Z ; 7918
|
||||
?MoveEntry@nsCacheEntryHashTable@@CAXPAUPLDHashTable@@PBUPLDHashEntryHdr@@PAU3@@Z ; 7653
|
||||
?GetKey@nsCacheEntryHashTable@@CAPBXPAUPLDHashTable@@PAUPLDHashEntryHdr@@@Z ; 7653
|
||||
?Close@nsANSIOutputStream@@UAGIXZ ; 7092
|
||||
?Write@nsANSIOutputStream@@UAGIPBDIPAI@Z ; 7067
|
||||
?AccumulateElements@nsCacheMetaData@@CA?AW4PLDHashOperator@@PAUPLDHashTable@@PAUPLDHashEntryHdr@@IPAX@Z ; 7063
|
||||
?Release@nsDiskCacheDeviceInfo@@UAGKXZ ; 6471
|
||||
?CreateRequest@nsCacheService@@AAEIPAVnsCacheSession@@PBDHPAVnsICacheListener@@PAPAVnsCacheRequest@@@Z ; 6468
|
||||
?ActivateEntry@nsCacheService@@AAEIPAVnsCacheRequest@@PAPAVnsCacheEntry@@@Z ; 6468
|
||||
?ProcessRequest@nsCacheService@@AAEIPAVnsCacheRequest@@PAPAVnsICacheEntryDescriptor@@@Z ; 6468
|
||||
??1nsCacheRequest@@AAE@XZ ; 6468
|
||||
?OpenCacheEntry@nsCacheService@@QAEIPAVnsCacheSession@@PBDHPAVnsICacheListener@@PAPAVnsICacheEntryDescriptor@@@Z ; 6468
|
||||
??0nsCacheRequest@@AAE@PAVnsCString@@PAVnsICacheListener@@HPAVnsCacheSession@@@Z ; 6468
|
||||
?Hash@nsDiskCacheEntry@@SAIPBD@Z ; 6166
|
||||
?HashKey@nsDiskCacheEntryHashTable@@CAIPAUPLDHashTable@@PBX@Z ; 6037
|
||||
?EvictEntriesIfNecessary@nsMemoryCacheDevice@@AAEXXZ ; 5780
|
||||
?TouchData@nsCacheEntry@@QAEXXZ ; 5503
|
||||
?OpenCacheEntry@nsCacheSession@@UAGIPBDHPAPAVnsICacheEntryDescriptor@@@Z ; 5165
|
||||
?RequestAccess@nsCacheEntry@@QAEIPAVnsCacheRequest@@PAH@Z ; 5099
|
||||
?Fetched@nsCacheEntry@@QAEXXZ ; 5094
|
||||
??0nsTransportWrapper@nsCacheEntryDescriptor@@QAE@XZ ; 5092
|
||||
?CreateDescriptor@nsCacheEntry@@QAEIPAVnsCacheRequest@@HPAPAVnsICacheEntryDescriptor@@@Z ; 5092
|
||||
??0nsCacheEntryDescriptor@@QAE@PAVnsCacheEntry@@H@Z ; 5092
|
||||
?RemoveDescriptor@nsCacheEntry@@QAEHPAVnsCacheEntryDescriptor@@@Z ; 5090
|
||||
?CloseDescriptor@nsCacheService@@QAEXPAVnsCacheEntryDescriptor@@@Z ; 5090
|
||||
?Close@nsCacheEntryDescriptor@@UAGIXZ ; 5090
|
||||
??_GnsCacheEntryDescriptor@@UAEPAXI@Z ; 5090
|
||||
??1nsCacheEntryDescriptor@@UAE@XZ ; 5090
|
||||
?SearchCacheDevices@nsCacheService@@AAEPAVnsCacheEntry@@PAVnsCString@@H@Z ; 4993
|
||||
?AddEntry@nsCacheEntryHashTable@@QAEIPAVnsCacheEntry@@@Z ; 4993
|
||||
?FindEntry@nsMemoryCacheDevice@@UAEPAVnsCacheEntry@@PAVnsCString@@@Z ; 4993
|
||||
?ClearEntry@nsCacheEntryHashTable@@CAXPAUPLDHashTable@@PAUPLDHashEntryHdr@@@Z ; 4993
|
||||
?RemoveEntry@nsCacheEntryHashTable@@QAEXPAVnsCacheEntry@@@Z ; 4921
|
||||
?GetData@nsCacheEntry@@QAEIPAPAVnsISupports@@@Z ; 4811
|
||||
?Release@nsDiskCacheEntry@@UAGKXZ ; 4784
|
||||
?RequestDataSizeChange@nsCacheEntryDescriptor@@QAEIH@Z ; 4127
|
||||
?OnDataSizeChange@nsCacheService@@QAEIPAVnsCacheEntry@@H@Z ; 4127
|
||||
?SetElement@nsCacheMetaData@@QAEIABVnsACString@@0@Z ; 3682
|
||||
?ClearEntry@nsCacheMetaData@@CAXPAUPLDHashTable@@PAUPLDHashEntryHdr@@@Z ; 3681
|
||||
?FreeElements@nsCacheMetaData@@CA?AW4PLDHashOperator@@PAUPLDHashTable@@PAUPLDHashEntryHdr@@IPAX@Z ; 3681
|
||||
?GetEntry@nsDiskCacheEntryHashTable@@QAEPAVnsDiskCacheEntry@@PBD@Z ; 3651
|
||||
?GetRecord@nsDiskCacheMap@@QAEPAVnsDiskCacheRecord@@I@Z ; 3650
|
||||
?Size@nsCacheMetaData@@QAEIXZ ; 3628
|
||||
?DeactivateEntry@nsCacheService@@AAEXPAVnsCacheEntry@@@Z ; 3619
|
||||
?TouchMetaData@nsCacheEntry@@QAEXXZ ; 3601
|
||||
?SetMetaDataElement@nsCacheEntryDescriptor@@UAGIPBD0@Z ; 3601
|
||||
?SetMetaDataElement@nsCacheEntry@@QAEIABVnsACString@@0@Z ; 3601
|
||||
?getFileForHashNumber@nsDiskCacheDevice@@QAEIIHIPAPAVnsIFile@@@Z ; 3587
|
||||
?Read@nsANSIInputStream@@UAGIPADIPAI@Z ; 3570
|
||||
?getFileForDiskCacheEntry@nsDiskCacheDevice@@QAEIPAVnsDiskCacheEntry@@HPAPAVnsIFile@@@Z ; 3560
|
||||
?Unswap@MetaDataHeader@@QAEXXZ ; 3545
|
||||
??1MetaDataFile@@QAE@XZ ; 3545
|
||||
?OnDataSizeChange@nsDiskCacheDevice@@UAEIPAVnsCacheEntry@@H@Z ; 3210
|
||||
?ProcessPendingRequests@nsCacheService@@AAEIPAVnsCacheEntry@@@Z ; 2800
|
||||
??0nsCacheEntry@@QAE@PAVnsCString@@HH@Z ; 2673
|
||||
??1nsCacheEntry@@QAE@XZ ; 2673
|
||||
?MarkValid@nsCacheEntryDescriptor@@UAGIXZ ; 2592
|
||||
?ValidateEntry@nsCacheService@@QAEIPAVnsCacheEntry@@@Z ; 2592
|
||||
?GetCacheElement@nsCacheEntryDescriptor@@UAGIPAPAVnsISupports@@@Z ; 2413
|
||||
?MatchEntry@nsDiskCacheEntryHashTable@@CAHPAUPLDHashTable@@PBUPLDHashEntryHdr@@PBX@Z ; 2383
|
||||
?Release@nsANSIInputStream@@UAGKXZ ; 2380
|
||||
?AddRef@nsANSIInputStream@@UAGKXZ ; 2380
|
||||
?MatchEntry@nsCacheMetaData@@CAHPAUPLDHashTable@@PBUPLDHashEntryHdr@@PBX@Z ; 2365
|
||||
?GetMetaDataElement@nsCacheEntry@@QAEIABVnsACString@@PAPBV2@@Z ; 2365
|
||||
?GetElement@nsCacheMetaData@@QAEPBVnsACString@@PBV2@@Z ; 2365
|
||||
?GetMetaDataElement@nsCacheEntryDescriptor@@UAGIPBDPAPAD@Z ; 2365
|
||||
?openOutputStream@nsDiskCacheDevice@@SAIPAVnsIFile@@PAPAVnsIOutputStream@@@Z ; 2356
|
||||
?updateDiskCacheEntry@nsDiskCacheDevice@@QAEIPAVnsDiskCacheEntry@@@Z ; 2356
|
||||
??0nsANSIOutputStream@@QAE@PAU_iobuf@@@Z ; 2356
|
||||
??_EnsANSIOutputStream@@UAEPAXI@Z ; 2356
|
||||
??1nsANSIOutputStream@@UAE@XZ ; 2356
|
||||
?Swap@MetaDataHeader@@QAEXXZ ; 2355
|
||||
?FlattenMetaData@nsCacheMetaData@@QAEIPAPADPAI@Z ; 2355
|
||||
?Init@MetaDataFile@@QAEIPAVnsCacheEntry@@@Z ; 2355
|
||||
?updateCacheMap@nsDiskCacheDevice@@QAEIPAVnsDiskCacheEntry@@@Z ; 2355
|
||||
??0MetaDataHeader@@QAE@PAVnsCacheEntry@@@Z ; 2355
|
||||
?Write@MetaDataFile@@QAEIPAVnsIOutputStream@@@Z ; 2355
|
||||
?FlattenMetaData@nsCacheEntry@@QAEIPAPADPAI@Z ; 2355
|
||||
?DeactivateEntry@nsMemoryCacheDevice@@UAEIPAVnsCacheEntry@@@Z ; 2322
|
||||
?SetExpirationTime@nsCacheEntryDescriptor@@UAGII@Z ; 2259
|
||||
?QueryInterface@nsCacheEntryDescriptor@@UAGIABUnsID@@PAPAX@Z ; 2186
|
||||
?GetDataSize@nsCacheEntryDescriptor@@UAGIPAI@Z ; 2107
|
||||
?OnDataSizeChange@nsMemoryCacheDevice@@UAEIPAVnsCacheEntry@@H@Z ; 2082
|
||||
?SetDataSize@nsCacheEntryDescriptor@@UAGII@Z ; 2082
|
||||
?Write@nsOutputStreamWrapper@nsCacheEntryDescriptor@@UAGIPBDIPAI@Z ; 2045
|
||||
?OnWrite@nsOutputStreamWrapper@nsCacheEntryDescriptor@@AAEII@Z ; 2045
|
||||
?GetNonBlocking@nsOutputStreamWrapper@nsCacheEntryDescriptor@@UAGIPAH@Z ; 1550
|
||||
?SetCacheElement@nsCacheEntryDescriptor@@UAGIPAVnsISupports@@@Z ; 1376
|
||||
?BindEntry@nsMemoryCacheDevice@@UAEIPAVnsCacheEntry@@@Z ; 1376
|
||||
?AsyncOpenCacheEntry@nsCacheSession@@UAGIPBDHPAVnsICacheListener@@@Z ; 1303
|
||||
?NotifyListener@nsCacheService@@AAEIPAVnsCacheRequest@@PAVnsICacheEntryDescriptor@@HI@Z ; 1303
|
||||
??0nsCacheMetaData@@QAE@XZ ; 1298
|
||||
??1nsCacheMetaData@@QAE@XZ ; 1298
|
||||
?FindEntry@nsDiskCacheDevice@@UAEPAVnsCacheEntry@@PAVnsCString@@@Z ; 1295
|
||||
?Init@nsCacheMetaData@@QAEIXZ ; 1295
|
||||
?Finalize@nsCacheMetaData@@CAXPAUPLDHashTable@@@Z ; 1295
|
||||
?Create@nsCacheMetaData@@SAPAV1@XZ ; 1295
|
||||
?getTransportForFile@nsDiskCacheDevice@@SAIPAVnsIFile@@HPAPAVnsITransport@@@Z ; 1199
|
||||
?GetTransportForEntry@nsDiskCacheDevice@@UAEIPAVnsCacheEntry@@HPAPAVnsITransport@@@Z ; 1198
|
||||
?AddRef@nsTransportWrapper@nsCacheEntryDescriptor@@UAGKXZ ; 1198
|
||||
?EnsureTransportWithAccess@nsTransportWrapper@nsCacheEntryDescriptor@@QAEIH@Z ; 1198
|
||||
?GetTransport@nsCacheEntryDescriptor@@UAGIPAPAVnsITransport@@@Z ; 1198
|
||||
?GetTransportForEntry@nsCacheService@@QAEIPAVnsCacheEntry@@HPAPAVnsITransport@@@Z ; 1198
|
||||
?Release@nsTransportWrapper@nsCacheEntryDescriptor@@UAGKXZ ; 1198
|
||||
?GetSecurityInfo@nsCacheEntryDescriptor@@UAGIPAPAVnsISupports@@@Z ; 1195
|
||||
?GetSecurityInfo@nsCacheEntry@@QAEIPAPAVnsISupports@@@Z ; 1195
|
||||
??1nsDiskCacheEntry@@UAE@XZ ; 1193
|
||||
??0nsDiskCacheEntry@@QAE@PAVnsCacheEntry@@@Z ; 1193
|
||||
??_EnsDiskCacheEntry@@UAEPAXI@Z ; 1193
|
||||
?DeactivateEntry@nsDiskCacheDevice@@UAEIPAVnsCacheEntry@@@Z ; 1193
|
||||
?AddEntry@nsDiskCacheEntryHashTable@@QAEIPAVnsDiskCacheEntry@@@Z ; 1193
|
||||
?ClearEntry@nsDiskCacheEntryHashTable@@CAXPAUPLDHashTable@@PAUPLDHashEntryHdr@@@Z ; 1193
|
||||
?RemoveEntry@nsDiskCacheEntryHashTable@@QAEXPAVnsDiskCacheEntry@@@Z ; 1193
|
||||
?openInputStream@nsDiskCacheDevice@@SAIPAVnsIFile@@PAPAVnsIInputStream@@@Z ; 1191
|
||||
??1nsANSIInputStream@@UAE@XZ ; 1190
|
||||
?Read@MetaDataFile@@QAEIPAVnsIInputStream@@@Z ; 1190
|
||||
??0nsANSIInputStream@@QAE@PAU_iobuf@@@Z ; 1190
|
||||
??_EnsANSIInputStream@@UAEPAXI@Z ; 1190
|
||||
??0MetaDataHeader@@QAE@XZ ; 1190
|
||||
?OpenOutputStream@nsTransportWrapper@nsCacheEntryDescriptor@@UAGIIIIPAPAVnsIOutputStream@@@Z ; 1166
|
||||
?BindEntry@nsDiskCacheDevice@@UAEIPAVnsCacheEntry@@@Z ; 1166
|
||||
?IsAllowedOnDisk@nsCacheEntry@@QAEHXZ ; 1166
|
||||
??1nsOutputStreamWrapper@nsCacheEntryDescriptor@@UAE@XZ ; 1165
|
||||
?NewOutputStreamWrapper@nsCacheEntryDescriptor@@CAIPAPAVnsIOutputStream@@PAV1@PAV2@@Z ; 1165
|
||||
?GetAccessGranted@nsCacheEntryDescriptor@@UAGIPAH@Z ; 1165
|
||||
??0nsOutputStreamWrapper@nsCacheEntryDescriptor@@QAE@PAV1@PAVnsIOutputStream@@@Z ; 1165
|
||||
?Init@nsOutputStreamWrapper@nsCacheEntryDescriptor@@QAEIXZ ; 1165
|
||||
??_GnsOutputStreamWrapper@nsCacheEntryDescriptor@@UAEPAXI@Z ; 1165
|
||||
??0MetaDataFile@@QAE@XZ ; 1163
|
||||
?GetDataSize@nsDiskCacheEntryInfo@@UAGIPAI@Z ; 1163
|
||||
??_GnsDiskCacheEntryInfo@@UAEPAXI@Z ; 1163
|
||||
?Swap@nsDiskCacheRecord@@QAEXXZ ; 1123
|
||||
?Unswap@nsDiskCacheRecord@@QAEXXZ ; 1123
|
||||
?GetExpirationTime@nsCacheEntryDescriptor@@UAGIPAI@Z ; 1118
|
||||
?GetKey@nsDiskCacheEntryHashTable@@CAPBXPAUPLDHashTable@@PAUPLDHashEntryHdr@@@Z ; 395
|
||||
?MoveEntry@nsDiskCacheEntryHashTable@@CAXPAUPLDHashTable@@PBUPLDHashEntryHdr@@PAU3@@Z ; 395
|
||||
?DoomEntry_Locked@nsCacheService@@QAEIPAVnsCacheEntry@@@Z ; 106
|
||||
?DoomEntry@nsCacheService@@QAEIPAVnsCacheEntry@@@Z ; 104
|
||||
?Doom@nsCacheEntryDescriptor@@UAGIXZ ; 104
|
||||
?FreeCacheEntries@nsCacheEntryHashTable@@CA?AW4PLDHashOperator@@PAUPLDHashTable@@PAUPLDHashEntryHdr@@IPAX@Z ; 72
|
||||
?AsyncRead@nsTransportWrapper@nsCacheEntryDescriptor@@UAGIPAVnsIStreamListener@@PAVnsISupports@@IIIPAPAVnsIRequest@@@Z ; 32
|
||||
??_H@YGXPAXIHP6EX0@Z@Z ; 32
|
||||
?getFileForKey@nsDiskCacheDevice@@QAEIPBDHIPAPAVnsIFile@@@Z ; 27
|
||||
?UnflattenMetaData@nsCacheMetaData@@QAEIPADI@Z ; 27
|
||||
?UnflattenMetaData@nsCacheEntry@@QAEIPADI@Z ; 27
|
||||
?readDiskCacheEntry@nsDiskCacheDevice@@QAEIPBDPAPAVnsDiskCacheEntry@@@Z ; 27
|
||||
?GetLastModified@nsCacheEntryDescriptor@@UAGIPAI@Z ; 25
|
||||
?AddRef@nsDiskCacheObserver@@UAGKXZ ; 12
|
||||
?Release@nsDiskCacheObserver@@UAGKXZ ; 12
|
||||
?AddRef@nsCacheService@@UAGKXZ ; 9
|
||||
?Release@nsCacheService@@UAGKXZ ; 9
|
||||
?QueryInterface@nsDiskCacheObserver@@UAGIABUnsID@@PAPAX@Z ; 6
|
||||
?QueryInterface@nsCacheService@@UAGIABUnsID@@PAPAX@Z ; 6
|
||||
?do_GetService@@YA?BVnsGetServiceByContractID@@PBDPAI@Z ; 5
|
||||
?DeleteRecord@nsDiskCacheMap@@QAEXI@Z ; 3
|
||||
??0nsCacheSession@@QAE@PBDHH@Z ; 3
|
||||
??1nsCacheSession@@UAE@XZ ; 3
|
||||
??_EnsCacheSession@@UAEPAXI@Z ; 3
|
||||
?deleteDiskCacheEntry@nsDiskCacheDevice@@QAEIPAVnsDiskCacheEntry@@@Z ; 3
|
||||
?DoomEntry@nsDiskCacheDevice@@UAEXPAVnsCacheEntry@@@Z ; 3
|
||||
?CreateSession@nsCacheService@@UAGIPBDHHPAPAVnsICacheSession@@@Z ; 3
|
||||
?setPrefsObserver@nsDiskCacheDevice@@QAEXPAVnsIObserver@@@Z ; 2
|
||||
?VisitEntries@nsDiskCacheEntryHashTable@@QAEXPAVVisitor@1@@Z ; 2
|
||||
?DetachDescriptors@nsCacheEntry@@AAEXXZ ; 2
|
||||
?ClearPendingRequests@nsCacheService@@AAEXPAVnsCacheEntry@@@Z ; 2
|
||||
?SetDoomEntriesIfExpired@nsCacheSession@@UAGIH@Z ; 2
|
||||
?Finalize@nsCacheEntryHashTable@@CAXPAUPLDHashTable@@@Z ; 2
|
||||
?DeactivateAndClearEntry@nsCacheService@@CA?AW4PLDHashOperator@@PAUPLDHashTable@@PAUPLDHashEntryHdr@@IPAX@Z ; 2
|
||||
?Init@nsCacheEntryHashTable@@QAEIXZ ; 2
|
||||
?updateDiskCacheEntries@nsDiskCacheDevice@@QAEIXZ ; 2
|
||||
?scanDiskCacheEntries@nsDiskCacheDevice@@QAEIPAPAVnsISupportsArray@@@Z ; 2
|
||||
?AdjustMemoryLimits@nsMemoryCacheDevice@@AAEXII@Z ; 1
|
||||
_NSGetModule ; 1
|
||||
?Finalize@nsDiskCacheEntryHashTable@@CAXPAUPLDHashTable@@@Z ; 1
|
||||
??0nsMemoryCacheDevice@@QAE@XZ ; 1
|
||||
?evictDiskCacheEntries@nsDiskCacheDevice@@QAEIXZ ; 1
|
||||
??0nsDiskCacheMap@@QAE@XZ ; 1
|
||||
?ClearActiveEntries@nsCacheService@@AAEXXZ ; 1
|
||||
?setCacheCapacity@nsDiskCacheDevice@@QAEXI@Z ; 1
|
||||
?Init@nsDiskCacheEntryHashTable@@QAEIXZ ; 1
|
||||
?DoomEntry@nsMemoryCacheDevice@@UAEXPAVnsCacheEntry@@@Z ; 1
|
||||
?getPrefsObserver@nsDiskCacheDevice@@QAEXPAPAVnsIObserver@@@Z ; 1
|
||||
??_EnsMemoryCacheDevice@@UAEPAXI@Z ; 1
|
||||
?setCacheDirectory@nsDiskCacheDevice@@QAEXPAVnsILocalFile@@@Z ; 1
|
||||
?Shutdown@nsCacheService@@UAGIXZ ; 1
|
||||
??_GnsCacheService@@UAEPAXI@Z ; 1
|
||||
?ClearDoomList@nsCacheService@@AAEXXZ ; 1
|
||||
?QueryInterface@nsANSIOutputStream@@UAGIABUnsID@@PAPAX@Z ; 1
|
||||
?Init@nsCacheService@@UAGIXZ ; 1
|
||||
??0nsDiskCacheDevice@@QAE@XZ ; 1
|
||||
?Swap@nsDiskCacheHeader@@QAEXXZ ; 1
|
||||
?GetFileForEntry@nsCacheService@@QAEIPAVnsCacheEntry@@PAPAVnsIFile@@@Z ; 1
|
||||
??_GnsDiskCacheDevice@@UAEPAXI@Z ; 1
|
||||
??1nsCacheService@@UAE@XZ ; 1
|
||||
?GetFileForEntry@nsDiskCacheDevice@@UAEIPAVnsCacheEntry@@PAPAVnsIFile@@@Z ; 1
|
||||
?Init@nsMemoryCacheDevice@@UAEIXZ ; 1
|
||||
?GetFile@nsCacheEntryDescriptor@@UAGIPAPAVnsIFile@@@Z ; 1
|
||||
?Seek@nsANSIOutputStream@@UAGIHH@Z ; 1
|
||||
?MemoryCacheSizeChanged@nsMemoryCacheDevice@@SAHPBDPAX@Z ; 1
|
||||
?SetStoragePolicy@nsCacheEntryDescriptor@@UAGIH@Z ; 1
|
||||
??0nsCacheService@@QAE@XZ ; 1
|
||||
?Observe@nsCacheService@@UAGIPAVnsISupports@@PBG1@Z ; 1
|
||||
?writeCacheMap@nsDiskCacheDevice@@QAEIXZ ; 1
|
||||
?Init@nsDiskCacheDevice@@UAEIXZ ; 1
|
||||
?Create@nsCacheService@@SGIPAVnsISupports@@ABUnsID@@PAPAX@Z ; 1
|
||||
?NS_GetSpecialDirectory@@YAIPBDPAPAVnsIFile@@@Z ; 1
|
||||
??1nsDiskCacheDevice@@UAE@XZ ; 1
|
||||
?readCacheMap@nsDiskCacheDevice@@QAEIXZ ; 1
|
||||
??1nsDiskCacheMap@@QAE@XZ ; 1
|
||||
??_EnsDiskCacheObserver@@UAEPAXI@Z ; 1
|
||||
?Unswap@nsDiskCacheHeader@@QAEXXZ ; 1
|
||||
?CreateDiskDevice@nsCacheService@@AAEIXZ ; 1
|
||||
??1nsMemoryCacheDevice@@UAE@XZ ; 1
|
||||
?Shutdown@nsDiskCacheDevice@@UAEIXZ ; 1
|
||||
?Write@nsDiskCacheMap@@QAEIPAVnsIOutputStream@@@Z ; 1
|
||||
Reference in New Issue
Block a user