Compare commits

..

27 Commits

Author SHA1 Message Date
gagan%netscape.com
3eeb8561a1 Added the memstream file.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@9000 18797224-902f-48f8-a5cc-f745e15eee43
1998-09-01 19:35:57 +00:00
gagan%netscape.com
280a09abc4 Added streams based changes.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@8724 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-28 20:24:48 +00:00
gagan%netscape.com
d1401c09ab Test
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@8507 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-26 18:26:31 +00:00
gagan%netscape.com
4a9ef1b8cb Misc. changes
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@8506 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-26 18:25:43 +00:00
gagan%netscape.com
a7537cf1dc Removed unneccessary dependencies on xp stuff.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@8097 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-17 18:52:40 +00:00
gagan%netscape.com
c54efd75e9 Replaced #include <> with #include "", since Mac doesn't like <>.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@8096 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-17 18:38:46 +00:00
gagan%netscape.com
5a30b4e55a Added nsMonitorable class to do the basic functionality of Enter/Exit Monitors. Made corresponding changes in nsCacheManager, nsCacheModule, nsDiskModule, and nsMemModule.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@8079 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-15 20:45:50 +00:00
gagan%netscape.com
3b59088a0b Added missing files.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@8077 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-15 18:19:37 +00:00
(no author)
bf5c968c5a This commit was manufactured by cvs2svn to create branch 'NuCache_BRANCH'.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@8052 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-14 23:48:06 +00:00
gagan%netscape.com
18216e82d4 Replaced cache_object instead of memory_copy.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@7926 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-13 08:09:39 +00:00
gagan%netscape.com
9cd35b92eb Added PR_ASSERT(0) for stuff that shouldn't be getting called.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@7925 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-13 08:08:31 +00:00
gagan%netscape.com
e22a85b2a0 Post Data, Page Services URLs added.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@7899 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-13 04:17:41 +00:00
gagan%netscape.com
48053e6550 Added nucacheproto.c for NU_CACHE.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@7876 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-12 21:35:43 +00:00
gagan%netscape.com
d125038cb3 Writes ok now.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@7738 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-11 09:25:54 +00:00
gagan%netscape.com
acf204eec6 misc. changes and reverting back to just the basics...
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@7735 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-11 06:27:25 +00:00
gagan%netscape.com
a0197ad679 Added mozilla\network\cache\nu to build.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@7700 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-10 22:41:00 +00:00
gagan%netscape.com
2022f54469 Added these missing files.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@7536 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-07 05:24:16 +00:00
gagan%netscape.com
60e4ff2b8f Content length and type + misc.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@7535 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-07 05:23:11 +00:00
gagan%netscape.com
9655d5b93d update
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@6850 18797224-902f-48f8-a5cc-f745e15eee43
1998-07-30 05:35:41 +00:00
gagan%netscape.com
993ba757db aaaahpdate.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@6849 18797224-902f-48f8-a5cc-f745e15eee43
1998-07-30 05:35:05 +00:00
gagan%netscape.com
f30b2b6d08 Todo list
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@6382 18797224-902f-48f8-a5cc-f745e15eee43
1998-07-24 06:02:59 +00:00
gagan%netscape.com
248e293e2a update
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@6142 18797224-902f-48f8-a5cc-f745e15eee43
1998-07-22 03:33:07 +00:00
gagan%netscape.com
cce44aa1b0 temp checkin
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@6052 18797224-902f-48f8-a5cc-f745e15eee43
1998-07-21 03:27:44 +00:00
gagan%netscape.com
d8c5fa6511 Define NU_CACHE if env is available.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@6045 18797224-902f-48f8-a5cc-f745e15eee43
1998-07-21 02:37:54 +00:00
gagan%netscape.com
3a14fa3dda Updates for Cachestubs.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@6033 18797224-902f-48f8-a5cc-f745e15eee43
1998-07-21 01:03:51 +00:00
gagan%netscape.com
f4d254645c Added cachelib for NuCache.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@6031 18797224-902f-48f8-a5cc-f745e15eee43
1998-07-21 00:54:39 +00:00
(no author)
4bce2b926e This commit was manufactured by cvs2svn to create branch 'NuCache_BRANCH'.
git-svn-id: svn://10.0.0.236/branches/NuCache_BRANCH@5718 18797224-902f-48f8-a5cc-f745e15eee43
1998-07-16 18:22:24 +00:00
391 changed files with 127743 additions and 5146 deletions

File diff suppressed because it is too large Load Diff

408
mozilla/config/config.mak Normal file
View File

@@ -0,0 +1,408 @@
# 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.
!if !defined(CONFIG_CONFIG_MAK)
CONFIG_CONFIG_MAK=1
#//------------------------------------------------------------------------
#//
#// Define public make variables:
#//
#// OBJDIR - Specifies the location of intermediate files (ie. objs...)
#// Currently, the names are WINxx_O.OBJ or WINxx_D.OBJ for
#// optimized and debug builds respectively.
#//
#// DIST - Specifies the location of the distribution directory where
#// all targets are delivered.
#//
#// CFGFILE - Specifies the name of the temporary configuration file
#// containing the arguments to the current command.
#//
#// INCS - Default include paths.
#//
#// CFLAGS - Default compiler options.
#//
#// LFLAGS - Default linker options.
#//
#//------------------------------------------------------------------------
!if [$(MOZ_TOOLS)\bin\uname > osuname.inc]
!endif
WINOS=\
!include "osuname.inc"
WINOS=$(WINOS: =)^
!if [del osuname.inc]
!endif
## Include support for MOZ_LITE/MOZ_MEDIUM
include <$(DEPTH)/config/liteness.mak>
!if "$(MOZ_BITS)" == "16"
!if "$(MAKE_OBJ_TYPE)" == "DLL"
OBJTYPE=D
!else
OBJTYPE=E
!endif
!else
OBJTYPE=
!endif
XPDIST=$(DEPTH)\dist
PUBLIC=$(XPDIST)\public
#//-----------------------------------------------------------------------
#// OBJDIR is NOT the same as DIST for Win16. The Win16 dist stuff can
#// be built with EXE or DLL compiler flags, but the DIST directory
#// has the same name no matter what
#//-----------------------------------------------------------------------
!ifdef NGLAYOUT_BUILD_PREFIX
DIST_PREFIX=NGL
!else
!ifdef MOZ_NAV_BUILD_PREFIX
DIST_PREFIX=NAV
!else
DIST_PREFIX=WIN
!endif
!endif
!ifndef MOZ_DEBUG
OBJDIR=$(DIST_PREFIX)$(MOZ_BITS)$(OBJTYPE)_O.OBJ
JAVA_OPTIMIZER = -O
!ifdef NO_CAFE
JAVAC_OPTIMIZER =
!else
#JAVAC_OPTIMIZER= -O -noinline
JAVAC_OPTIMIZER =
!endif
!else
OBJDIR=$(DIST_PREFIX)$(MOZ_BITS)$(OBJTYPE)_D.OBJ
JAVA_OPTIMIZER = -g
JAVAC_OPTIMIZER = -g
!endif
#//
#// DIST DEFINES SHOULD NEVER BE COMPONENT SPECIFIC.
#//
!ifndef MOZ_DEBUG
DIST=$(XPDIST)\$(DIST_PREFIX)$(MOZ_BITS)_O.OBJ
!else
DIST=$(XPDIST)\$(DIST_PREFIX)$(MOZ_BITS)_D.OBJ
!endif
# This will always give the location of NGLayout's dist, even if "NGLAYOUT_BUILD_PREFIX" is not defined.
!if defined(MOZ_NGLAYOUT)
!ifndef MOZ_DEBUG
NGLAYOUT_DIST=$(XPDIST)\NGL$(MOZ_BITS)_O.OBJ
!else
NGLAYOUT_DIST=$(XPDIST)\NGL$(MOZ_BITS)_D.OBJ
!endif
!endif
CFGFILE=$(OBJDIR)\cmd.cfg
!if "$(MOZ_BITS)" == "16"
INCS=-I$(XPDIST)\public\win16 $(INCS) -I$(DEPTH)\include -I$(DIST)\include -I..\include
!else
INCS=$(INCS) -I$(DEPTH)\include -I$(DIST)\include \
-I$(XPDIST)\public\img -I$(XPDIST)\public\util \
-I$(XPDIST)\public\coreincl
!endif # 16
!ifndef NO_LAYERS
INCS=$(INCS) -I$(DEPTH)\lib\liblayer\include
!endif
!if "$(STAND_ALONE_JAVA)" == "1"
LCFLAGS=$(LCFLAGS) -DSTAND_ALONE_JAVA
!endif
!if defined(MOZ_JAVA)
MOZ_JAVA_FLAG=-DJAVA
!if defined(MOZ_OJI)
!error You can't define both MOZ_JAVA and MOZ_OJI anymore.
!endif
JAVA_OR_OJI=1
!endif
!if defined(MOZ_OJI)
LCFLAGS=$(LCFLAGS) -DOJI
JAVA_OR_OJI=1
!endif
# Perhaps we should add MOZ_LITENESS_FLAGS to 16 bit build
!if "$(MOZ_BITS)" == "16"
CFLAGS=$(MOZ_JAVA_FLAG) -DMOCHA -DLAYERS -DEDITOR $(OS_CFLAGS) $(MOZ_CFLAGS)
!else
CFLAGS=$(MOZ_JAVA_FLAG) -DMOCHA -DLAYERS $(OS_CFLAGS) $(MOZ_CFLAGS) $(MOZ_LITENESS_FLAGS)
!endif
LFLAGS=$(OS_LFLAGS) $(LLFLAGS) $(MOZ_LFLAGS)
!ifdef NO_SECURITY
CFLAGS = $(CFLAGS) -DNO_SECURITY
!endif
# This compiles in heap dumping utilities and other good stuff
# for developers -- maybe we only want it in for a special SDK
# nspr/java runtime(?):
!if "$(MOZ_BITS)"=="32" || defined(MOZ_DEBUG)
CFLAGS = $(CFLAGS) -DDEVELOPER_DEBUG
!endif
!ifdef STANDALONE_IMAGE_LIB
CFLAGS=$(CFLAGS) -DSTANDALONE_IMAGE_LIB
!endif
!ifdef MODULAR_NETLIB
CFLAGS=$(CFLAGS) -DMODULAR_NETLIB
!else
# Defines for new cookie management...
CFLAGS=$(CFLAGS) -DCookieManagement -DSingleSignon
!endif
# TODO Remove later - Gagan
!ifdef NU_CACHE
CFLAGS=$(CFLAGS) -DNU_CACHE
!endif
# always need these:
CFLAGS = $(CFLAGS) -DNETSCAPE
# Specify that we are building a client.
# This will instruct the cross platform libraries to
# include all the client specific cruft.
!if defined(SERVER_BUILD)
CFLAGS = $(CFLAGS) -DSERVER_BUILD
!elseif defined(LIVEWIRE)
CFLAGS = $(CFLAGS) -DLIVEWIRE
!else
CFLAGS = $(CFLAGS) -DMOZILLA_CLIENT
!endif
PERL= $(MOZ_TOOLS)\perl5\perl.exe
MASM = $(MOZ_TOOLS)\bin\ml.exe
!if "$(WINOS)" == "WIN95"
MKDIR = $(DEPTH)\config\w95mkdir
QUIET =
!else
MKDIR = mkdir
QUIET=@
!endif
#//------------------------------------------------------------------------
#//
#// Include the OS dependent configuration information
#//
#//------------------------------------------------------------------------
include <$(DEPTH)/config/WIN$(MOZ_BITS)>
!ifdef MOZ_DEBUG
!ifdef USERNAME
CFLAGS = $(CFLAGS) -DDEBUG_$(USERNAME)
!endif
!if defined(GLOWCODE) && defined(GLOWPROF) && "$(MOZ_BITS)"=="32"
CFLAGS = $(CFLAGS) -Gh
!endif
!endif
#//------------------------------------------------------------------------
#//
#// Define the global make commands.
#//
#// MAKE_INSTALL - Copy a target to the distribution directory.
#//
#// MAKE_OBJDIRS - Create an object directory (if necessary).
#//
#// MAKE_MANGLE - Convert all long filenames into 8.3 names
#//
#// MAKE_UNMANGLE - Restore all long filenames
#//
#//------------------------------------------------------------------------
!if !defined(MOZ_SRC)
#enable builds on any drive if defined.
MOZ_SRC=y:
!endif
MAKE_INSTALL=$(QUIET)$(DEPTH)\config\makecopy.exe
MAKE_MANGLE=$(DEPTH)\config\mangle.exe
MAKE_UNMANGLE=if exist unmangle.bat call unmangle.bat
#//------------------------------------------------------------------------
#//
#// Common Libraries
#//
#//------------------------------------------------------------------------
!ifdef NSPR20
!if "$(MOZ_BITS)" == "16"
LIBNSPR=$(DIST)\lib\nspr21.lib
LIBNSPR=$(LIBNSPR) $(DIST)\lib\plds21.lib
LIBNSPR=$(LIBNSPR) $(DIST)\lib\msgc21.lib
!else
LIBNSPR=$(DIST)\lib\libnspr21.lib
LIBNSPR=$(LIBNSPR) $(DIST)\lib\libplds21.lib
LIBNSPR=$(LIBNSPR) $(DIST)\lib\libmsgc21.lib
!endif
!else
LIBNSPR=$(DIST)\lib\pr$(MOZ_BITS)$(VERSION_NUMBER).lib
!endif
!ifdef NSPR20
NSPRDIR = nsprpub
CFLAGS = $(CFLAGS) -DNSPR20
!else
NSPRDIR = nspr
!endif
LIBJPEG=$(DIST)\lib\jpeg$(MOZ_BITS)$(VERSION_NUMBER).lib
######################################################################
### Windows-Specific Java Stuff
PATH_SEPARATOR = ;
# where the bytecode will go
!if "$(AWT_11)" == "1"
JAVA_DESTPATH = $(DEPTH)\dist\classes11
!else
JAVA_DESTPATH = $(DEPTH)\dist\classes
!endif
# where the source are
DEFAULT_JAVA_SOURCEPATH = $(DEPTH)\sun-java\classsrc
!ifndef JAVA_SOURCEPATH
!if "$(AWT_11)" == "1"
JAVA_SOURCEPATH = $(DEPTH)\sun-java\classsrc11;$(DEFAULT_JAVA_SOURCEPATH)
!else
JAVA_SOURCEPATH = $(DEFAULT_JAVA_SOURCEPATH)
!endif
!endif
JAVA_PROG=$(MOZ_TOOLS)\bin\java.exe
#JAVA_PROG=$(DIST)\bin\java
JAVAC_ZIP=$(MOZ_TOOLS)/lib/javac.zip
ZIP_PROG = $(MOZ_TOOLS)\bin\zip
UNZIP_PROG = $(MOZ_TOOLS)\bin\unzip
ZIP_FLAGS = -0 -r -q
CFLAGS = $(CFLAGS) -DOS_HAS_DLL
DLL_SUFFIX = dll
LIB_SUFFIX = lib
!if "$(STAND_ALONE_JAVA)" == "1"
STAND_ALONE_JAVA_DLL_SUFFIX=s
!else
STAND_ALONE_JAVA_DLL_SUFFIX=
!endif
MOD_JRT=jrt$(MOZ_BITS)$(VERSION_NUMBER)
MOD_MM =mm$(MOZ_BITS)$(VERSION_NUMBER)
MOD_AWT=awt$(MOZ_BITS)$(VERSION_NUMBER)
MOD_AWTS=awt$(MOZ_BITS)$(VERSION_NUMBER)$(STAND_ALONE_JAVA_DLL_SUFFIX)
MOD_JIT=jit$(MOZ_BITS)$(VERSION_NUMBER)
MOD_JSJ=jsj$(MOZ_BITS)$(VERSION_NUMBER)
MOD_NET=net$(MOZ_BITS)$(VERSION_NUMBER)
MOD_JBN=jbn$(MOZ_BITS)$(VERSION_NUMBER)
MOD_NSC=nsc$(MOZ_BITS)$(VERSION_NUMBER)
MOD_JPW=jpw$(MOZ_BITS)$(VERSION_NUMBER)
MOD_JDB=jdb$(MOZ_BITS)$(VERSION_NUMBER)
MOD_ZIP=zip$(MOZ_BITS)$(VERSION_NUMBER)
MOD_ZPW=zpw$(MOZ_BITS)$(VERSION_NUMBER)
MOD_CON=con$(MOZ_BITS)$(VERSION_NUMBER)
MOD_NPJ=npj$(MOZ_BITS)$(VERSION_NUMBER)
JRTDLL=$(MOD_JRT).$(DLL_SUFFIX)
MMDLL =$(MOD_MM).$(DLL_SUFFIX)
AWTDLL=$(MOD_AWT).$(DLL_SUFFIX)
AWTSDLL=$(MOD_AWT)$(STAND_ALONE_JAVA_DLL_SUFFIX).$(DLL_SUFFIX)
JITDLL=$(MOD_JIT).$(DLL_SUFFIX)
JSJDLL=$(MOD_JSJ).$(DLL_SUFFIX)
NETDLL=$(MOD_NET).$(DLL_SUFFIX)
JBNDLL=$(MOD_JBN).$(DLL_SUFFIX)
NSCDLL=$(MOD_NSC).$(DLL_SUFFIX)
JPWDLL=$(MOD_JPW).$(DLL_SUFFIX)
JDBDLL=$(MOD_JDB).$(DLL_SUFFIX)
ZIPDLL=$(MOD_ZIP).$(DLL_SUFFIX)
ZPWDLL=$(MOD_ZPW).$(DLL_SUFFIX)
CONDLL=$(MOD_CON).$(DLL_SUFFIX)
NPJDLL=$(MOD_NPJ).$(DLL_SUFFIX)
ZIPLIB=$(DIST)\lib\$(MOD_ZIP).$(LIB_SUFFIX)
AWTLIB=$(DIST)\lib\$(MOD_AWT).$(LIB_SUFFIX)
######################################################################
include <$(DEPTH)/config/common.mk>
JAVA_DEFINES = \
-DJAR_NAME=\"$(JAR_NAME)\" \
-DJRTDLL=\"$(JRTDLL)\" \
-DMMDLL=\"$(MMDLL)\" \
-DAWTDLL=\"$(AWTDLL)\" \
-DAWTSDLL=\"$(AWTSDLL)\" \
-DJSJDLL=\"$(JSJDLL)\" \
-DJITDLL=\"$(JITDLL)\" \
-DNETDLL=\"$(NETDLL)\" \
-DJBNDLL=\"$(JBNDLL)\" \
-DNSCDLL=\"$(NSCDLL)\" \
-DJDBDLL=\"$(JDBDLL)\" \
-DJPWDLL=\"$(JPWDLL)\" \
-DZPWDLL=\"$(ZPWDLL)\" \
-DCONDLL=\"$(CONDLL)\"
!if "$(MOZ_BITS)" == "16"
# Override JAVA_DEFINES to make command line short for win16.
# Put any new defines into javadefs.h in ns/sun-java/include.
# This is to shorten the command line in order not to break Win16.
JAVA_DEFINES = -DJAR_NAME=\"$(JAR_NAME)\" -DMOZ_BITS=\"$(MOZ_BITS)\" -DVERSION_NUMBER=\"$(VERSION_NUMBER)\" -DDLL_SUFFIX=\".$(DLL_SUFFIX)\"
!endif
!if "$(AWT_11)" == "1"
JAVA_DEFINES = $(JAVA_DEFINES) -DAWT_11
!else
JAVA_DEFINES = $(JAVA_DEFINES) -DAWT_102
!endif
#JAVA_CLASSPATH = $(JAVA_CLASSPATH:/=\)
JMCSRCDIR = $(JMCSRCDIR:/=\)
JAVA_BOOT_CLASSPATH = $(JAVA_BOOT_CLASSPATH:/=\)
NMAKE=nmake -nologo -$(MAKEFLAGS)
########
# Get the cwd to prepend to all compiled source
# files. Will allow debugger to automatically find sources
# instead of asking for the path info.
# Win16 will break if enabled, guess we continue to live in pain
# therein.
########
!if "$(MOZ_BITS)" == "32"
CURDIR=$(MAKEDIR)^\
!endif
!endif # CONFIG_CONFIG_MAK

632
mozilla/config/config.mk Normal file
View File

@@ -0,0 +1,632 @@
#
# 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.
#
#
# config.mk
#
# Determines the platform and builds the macros needed to load the
# appropriate platform-specific .mk file, then defines all (most?)
# of the generic macros.
#
# This wastes time.
include $(DEPTH)/config/common.mk
#
# Important internal static macros
#
OS_ARCH := $(subst /,_,$(shell uname -s))
OS_RELEASE := $(shell uname -r)
OS_TEST := $(shell uname -m)
#
# Tweak the default OS_ARCH and OS_RELEASE macros as needed.
#
ifeq ($(OS_ARCH),AIX)
OS_RELEASE := $(shell uname -v).$(shell uname -r)
endif
ifeq ($(OS_ARCH),BSD_386)
OS_ARCH := BSD_OS
endif
ifeq ($(OS_ARCH),IRIX64)
OS_ARCH := IRIX
endif
ifeq ($(OS_ARCH),UNIX_SV)
ifneq ($(findstring NCR,$(shell grep NCR /etc/bcheckrc | head -1 )),)
OS_ARCH := NCR
else
OS_ARCH := UNIXWARE
OS_RELEASE := $(shell uname -v)
endif
endif
ifeq ($(OS_ARCH),ncr)
OS_ARCH := NCR
endif
# This is the only way to correctly determine the actual OS version on NCR boxes.
ifeq ($(OS_ARCH),NCR)
OS_RELEASE := $(shell awk '{print $$3}' /etc/.relid | sed 's/^\([0-9]\)\(.\)\(..\)\(.*\)$$/\2.\3/')
endif
ifeq ($(OS_ARCH),UNIX_System_V)
OS_ARCH := NEC
endif
ifeq ($(OS_ARCH),QNX)
OS_RELEASE := $(shell uname -v | sed 's/^\([0-9]\)\([0-9]*\)$$/\1.\2/')
endif
ifeq ($(OS_ARCH),SCO_SV)
OS_ARCH := SCOOS
OS_RELEASE := 5.0
endif
ifneq (,$(filter SINIX-N SINIX-Y SINIX-Z ReliantUNIX-M,$(OS_ARCH)))
OS_ARCH := SINIX
OS_TEST := $(shell uname -p)
endif
ifeq ($(OS_ARCH),UnixWare)
OS_ARCH := UNIXWARE
endif
#
# Strip off the excessively long version numbers on these platforms,
# but save the version to allow multiple versions of the same base
# platform to be built in the same tree.
#
ifneq (,$(filter FreeBSD HP-UX IRIX Linux NetBSD OSF1 SunOS,$(OS_ARCH)))
OS_VERS := $(suffix $(OS_RELEASE))
OS_RELEASE := $(basename $(OS_RELEASE))
OS_VERSION := $(shell echo $(OS_VERS) | sed 's/-.*//')
endif
OS_CONFIG := $(OS_ARCH)$(OS_RELEASE)
#
# Personal makefile customizations go in these optional make include files.
#
MY_CONFIG := $(DEPTH)/config/myconfig.mk
MY_RULES := $(DEPTH)/config/myrules.mk
#
# Relative pathname from top-of-tree to current source directory
#
ifneq (,$(filter-out OS2 WINNT,$(OS_ARCH)))
REVDEPTH := $(DEPTH)/config/revdepth
SRCDIR = $(shell $(PERL) $(REVDEPTH).pl $(DEPTH))
endif
#
# Define an include-at-most-once flag
#
NS_CONFIG_MK = 1
#
# Provide the means to easily override our tool directory locations.
#
ifdef NETSCAPE_HIERARCHY
NETSCAPE_BUILD = 1 # Defines XFEPRIVDIR, below.
CONTRIB_BIN := /tools/contrib/bin/
JAVA_BIN := /usr/local/java/bin/
LOCAL_BIN := /usr/local/bin/
LOCAL_SUN4 := /usr/local/sun4/bin/
NS_BIN := /tools/ns/bin/
NS_LIB := /tools/ns/lib
JAVA_LIB := /usr/local/netscape/java/lib
else
NS_LIB := .
JAVA_LIB := .
endif
# Allow NETSCAPE_BUILD to include XFEPRIVDIR w/o NETSCAPE_HIERARCHY
ifdef NETSCAPE_BUILD
XFEPRIVDIR := $(DEPTH)/../ns/cmd/xfe/
endif
#
# Default command macros; can be overridden in <arch>.mk.
#
AS = $(CC)
ASFLAGS = $(CFLAGS)
BSDECHO = echo
CC = gcc
CCC = g++
CCF = $(CC) $(CFLAGS)
LINK_EXE = $(LINK) $(OS_LFLAGS) $(LFLAGS)
LINK_DLL = $(LINK) $(OS_DLLFLAGS) $(DLLFLAGS)
NFSPWD = $(DEPTH)/config/nfspwd
PURIFY = purify $(PURIFYOPTIONS)
QUANTIFY = quantify $(QUANTIFYOPTIONS)
RANLIB = /bin/true
SDKINSTALL = $(NSINSTALL) -t
UNZIP_PROG = $(LOCAL_BIN)/unzip
ZIP_PROG = $(LOCAL_BIN)/zip
ZIP_FLAGS = -0rq
ifeq ($(OS_ARCH),OS2)
EMPTY :=
SLASH := /$(EMPTY)
BSLASH := \$(EMPTY)
SEMICOLON := ;$(EMPTY)
SPACE := $(EMPTY) $(EMPTY)
PATH_SEPARATOR := \;
RC = flipper rc$(BIN_SUFFIX)
XP_DEFINE = -DXP_PC
LIB_SUFFIX = lib
DLL_SUFFIX = dll
MAP_SUFFIX = map
BIN_SUFFIX = .exe
AR = flipper ILibo //noignorecase //nologo $@
IMPLIB = flipper ILibo //noignorecase //nologo $@
DLLFLAGS = -DLL -OUT:$@ $(XLFLAGS) -MAP:$(@:.dll=.map)
LFLAGS = $(OBJS) -OUT:$@ $(XLFLAGS) $(DEPLIBS) $(EXTRA_LIBS) -MAP:$(@:.dll=.map) $(DEF_FILE)
NSINSTALL = nsinstall
INSTALL = $(NSINSTALL)
JAVA_PROG = flipper java -norestart
JAVAC_ZIP = $(subst $(BSLASH),$(SLASH),$(JAVA_HOME))/lib/classes.zip
else
ifeq ($(OS_ARCH),WINNT)
PATH_SEPARATOR := :
RC = rc$(BIN_SUFFIX)
XP_DEFINE = -DXP_PC
LIB_SUFFIX = lib
DLL_SUFFIX = dll
BIN_SUFFIX = .exe
AR = lib -NOLOGO -OUT:"$@"
DLLFLAGS = $(XLFLAGS) -OUT:"$@"
LFLAGS = $(OBJS) $(DEPLIBS) $(EXTRA_LIBS) -OUT:"$@"
NSINSTALL = nsinstall
INSTALL = $(NSINSTALL)
JAVA_PROG = java
else
PATH_SEPARATOR := :
XP_DEFINE = -DXP_UNIX
AR = ar cr $@
DLL_SUFFIX = so
LIB_SUFFIX = a
ifeq ($(AWT_11),1)
JAVA_PROG = $(NS_BIN)java
JAVAC_ZIP = $(NS_LIB)/classes.zip
else
JAVA_PROG = $(LOCAL_BIN)java
JAVAC_ZIP = $(JAVA_LIB)/javac.zip
endif
PERL = $(NS_BIN)perl
TAR = tar
EMACS = xemacs
WHOAMI = /usr/bin/whoami
endif
endif
#
# Debug by default.
#
OBJDIR_TAG = _DBG
OPTIMIZER = -g
JAVA_OPTIMIZER = -g
XBCFLAGS = -FR$*
XCFLAGS = $(LCFLAGS)
XLFLAGS = $(LLFLAGS)
ifeq ($(OS_ARCH),OS2)
OPTIMIZER = -Ti+
XLFLAGS += -DEBUG
ifdef BUILD_PROFILE
OPTIMIZER += -Gh+
OBJDIR_TAG = _PRF
else
OPTIMIZER += -DDEBUG
ifdef BUILD_MEMDBG
OPTIMIZER += -Tm+ -DXP_OS2_MEMDEBUG=1
OBJDIR_TAG = _MEM
endif
endif
else
ifeq ($(OS_ARCH),WINNT)
OPTIMIZER = -Od -Z7
JAVA_OPTIMIZER = $(OPTIMIZER)
XLFLAGS += -DEBUG
else
DEFINES = -DDEBUG -UNDEBUG -DDEBUG_$(shell $(WHOAMI)) -DTRACING
endif
endif
ifdef BUILD_OPT
OBJDIR_TAG = _OPT
XBCFLAGS =
ifeq ($(OS_ARCH),OS2)
OPTIMIZER = -O+ -Oi -DNDEBUG
else
ifeq ($(OS_ARCH),WINNT)
OPTIMIZER = -O2
else
OPTIMIZER = -O
DEFINES = -UDEBUG -DNDEBUG -DTRIMMED
endif
endif
endif
#
# XXX For now, we're including $(DEPTH)/include directly instead of
# getting this stuff from dist. This stuff is old and will eventually
# be put in the library directories where it belongs so that it can
# get exported to dist properly.
#
INCLUDES = $(LOCAL_PREINCLUDES) $(MODULE_PREINCLUDES) -I$(DEPTH)/include $(LOCAL_INCLUDES) $(OS_INCLUDES)
LIBNT = $(DIST)/lib/libnt.$(LIB_SUFFIX)
LIBAWT = $(DIST)/lib/libawt.$(LIB_SUFFIX)
LIBMMEDIA = $(DIST)/lib/libmmedia.$(LIB_SUFFIX)
#
# NSPR 2.0 is now the default, "setenv NSPR10 1" to go back to 1.0
#
ifndef NSPR10
NSPR20 = 1
NSPRDIR = nsprpub
DEFINES += -DNSPR20
INCLUDES += -I$(DIST)/include
LIBNSPR = $(DIST)/lib/libplds21.$(LIB_SUFFIX) \
$(DIST)/lib/libmsgc21.$(LIB_SUFFIX) \
$(DIST)/lib/libnspr21.$(LIB_SUFFIX)
PURELIBNSPR = $(DIST)/lib/purelibplds21.$(LIB_SUFFIX) \
$(DIST)/lib/purelibmsgc21.$(LIB_SUFFIX) \
$(DIST)/lib/purelibnspr21.$(LIB_SUFFIX)
else
NSPRDIR = nspr
LIBNSPR = $(DIST)/lib/libnspr.$(LIB_SUFFIX)
PURELIBNSPR = $(DIST)/lib/libpurenspr.$(LIB_SUFFIX)
endif
ifdef DBMALLOC
LIBNSPR += $(DIST)/lib/libdbmalloc.$(LIB_SUFFIX)
endif
ifeq ($(OS_ARCH),OS2)
LIBNSJAVA = $(DIST)/lib/jrt$(MOZ_BITS)$(VERSION_NUMBER).$(LIB_SUFFIX)
LIBMD = $(DIST)/lib/libjmd.$(LIB_SUFFIX)
LIBJAVA = $(DIST)/lib/libjrt.$(LIB_SUFFIX)
LIBNSPR = $(DIST)/lib/pr$(MOZ_BITS)$(VERSION_NUMBER).$(LIB_SUFFIX)
LIBXP = $(DIST)/lib/libxp.$(LIB_SUFFIX)
else
ifeq ($(OS_ARCH),WINNT)
LIBNSJAVA = $(DIST)/lib/jrt3221.$(LIB_SUFFIX)
else
LIBNSJAVA = $(DIST)/lib/nsjava32.$(LIB_SUFFIX)
endif
endif
CFLAGS = $(XP_DEFINE) $(OPTIMIZER) $(OS_CFLAGS) $(MDUPDATE_FLAGS) $(DEFINES) $(INCLUDES) $(XCFLAGS) $(PROF_FLAGS)
NOMD_CFLAGS = $(XP_DEFINE) $(OPTIMIZER) $(OS_CFLAGS) $(DEFINES) $(INCLUDES) $(XCFLAGS)
#
# Include the binary distrib stuff, if necessary.
#
ifdef NS_BUILD_CORE
include $(DEPTH)/config/coreconf.mk
endif
#
# Now include the platform-specific stuff.
#
include $(DEPTH)/config/$(OS_ARCH).mk
#
# Some platforms (Solaris) might require builds using either
# (or both) compiler(s).
#
ifdef SHOW_CC_TYPE
COMPILER = _$(notdir $(CC))
endif
#
# Name of the binary code directories
#
ifeq ($(OS_ARCH)_$(PROCESSOR_ARCHITECTURE),WINNT_x86)
OBJDIR_NAME = $(OS_CONFIG)$(OS_VERSION)$(OBJDIR_TAG).OBJ
else
OBJDIR_NAME = $(OS_CONFIG)$(OS_VERSION)$(PROCESSOR_ARCHITECTURE)$(COMPILER)$(IMPL_STRATEGY)$(OBJDIR_TAG).OBJ
endif
# Figure out where the binary code lives. It either lives in the src
# tree (NSBUILDROOT is undefined) or somewhere else.
ifdef NSBUILDROOT
BUILD = $(NSBUILDROOT)/$(OBJDIR_NAME)/build
OBJDIR = $(BUILD)/$(SRCDIR)
XPDIST = $(NSBUILDROOT)
DIST = $(NSBUILDROOT)/$(OBJDIR_NAME)/dist
else
BUILD = $(OBJDIR_NAME)
OBJDIR = $(OBJDIR_NAME)
XPDIST = $(DEPTH)/dist
DIST = $(DEPTH)/dist/$(OBJDIR_NAME)
endif
# all public include files go in subdirectories of PUBLIC:
PUBLIC = $(XPDIST)/public
VPATH = $(OBJDIR)
DEPENDENCIES = $(OBJDIR)/.md
ifneq ($(OS_ARCH),WINNT)
MKDEPEND_DIR = $(DEPTH)/config/mkdepend
MKDEPEND = $(MKDEPEND_DIR)/$(OBJDIR_NAME)/mkdepend
MKDEPENDENCIES = $(OBJDIR)/depend.mk
endif
#
# Include any personal overrides the user might think are needed.
#
-include $(MY_CONFIG)
######################################################################
# Now test variables that might have been set or overridden by $(MY_CONFIG).
DEFINES += -DNETSCAPE -DOSTYPE=\"$(OS_CONFIG)\"
# Specify that we are building a client.
# This will instruct the cross platform libraries to
# include all the client specific cruft.
ifdef SERVER_BUILD
DEFINES += -DSERVER_BUILD
ifdef LIVEWIRE
DEFINES += -DLIVEWIRE
endif
STATIC_JAVA = yes
else
MOZILLA_CLIENT = 1
DEFINES += -DMOZILLA_CLIENT
endif
ifdef MOZ_SINGLESIGNON
DEFINES += -DSingleSignon
endif
ifdef MOZ_COOKIEMANAGE
DEFINES += -DCookieManagement
endif
ifdef MOZ_LITE
NO_EDITOR = 1
NO_UNIX_LDAP = 1
MOZ_JSD = 1
MOZ_NAV_BUILD_PREFIX = 1
endif
ifdef MOZ_MEDIUM
DEFINES += -DEDITOR -DMOZ_COMMUNICATOR_IIDS
EDITOR = 1
MOZ_JSD = 1
MOZ_COMMUNICATOR_IIDS = 1
MOZ_COMMUNICATOR_CONFIG_JS = 1
MOZ_COPY_ALL_JARS = 1
ifndef MOZ_SECURITY
NO_SECURITY = 1
endif
endif
ifdef MOZ_DARK
DEFINES += -DEDITOR -DMOZ_COMMUNICATOR_IIDS -DMOZ_MAIL_NEWS -DMOZ_OFFLINE \
-DMOZ_TASKBAR -DMOZ_LDAP -DMOZ_NEO
#-DMOZ_CALENDAR
EDITOR = 1
MOZ_JSD = 1
MOZ_COMMUNICATOR_IIDS = 1
MOZ_COMMUNICATOR_CONFIG_JS = 1
MOZ_COPY_ALL_JARS = 1
MOZ_OFFLINE=1
MOZ_TASKBAR=1
MOZ_LDAP=1
MOZ_MAIL_NEWS=1
#MOZ_CALENDAR=1
MOZ_NEO=1
endif
ifdef MOZ_GOLD
DEFINES += -DGOLD
BUILD_GOLD = 1
endif
ifdef NO_SECURITY
DEFINES += -DNO_SECURITY
endif
# Crash-reporting system
ifdef MOZ_FULLCIRCLE
DEFINES += -DMOZ_FULLCIRCLE
endif
ifdef EDITOR
DEFINES += -DEDITOR -DEDITOR_UI
BUILD_EDITOR = 1
BUILD_EDITOR_UI = 1
BUILD_EDT = 1
endif
# Build layers by default
ifndef NO_LAYERS
DEFINES += -DLAYERS
endif
ifdef BUILD_DEBUG_GC
DEFINES += -DDEBUG_GC
endif
ifdef BUILD_UNIX_PLUGINS
# UNIX_EMBED Should not be needed. For now these two defines go
# together until I talk with jg. --dp
DEFINES += -DUNIX_EMBED -DX_PLUGINS
endif
ifndef NO_UNIX_LDAP
DEFINES += -DUNIX_LDAP
endif
#
# Platform dependent switching off of NSPR, JAVA and MOCHA
#
ifndef NO_NSPR
DEFINES += -DNSPR
endif
ifdef MOZ_JAVA
DEFINES += -DJAVA
ifdef MOZ_OJI
error You can't define both MOZ_JAVA and MOZ_OJI anymore.
endif
JAVA_OR_OJI = 1
endif
ifdef MOZ_OJI
DEFINES += -DOJI
JAVA_OR_OJI = 1
endif
ifdef JAVA_OR_OJI
MOZ_SMARTUPDATE = 1
endif
ifndef NO_MOCHA
DEFINES += -DMOCHA
endif
ifdef FORTEZZA
DEFINES += -DFORTEZZA
endif
ifdef UNIX_SKIP_ASSERTS
DEFINES += -DUNIX_SKIP_ASSERTS
endif
ifdef SHACK
DEFINES += -DSHACK
endif
ifndef NO_UNIX_ASYNC_DNS
DEFINES += -DUNIX_ASYNC_DNS
endif
# For profiling
ifdef MOZILLA_GPROF
# Don't want profiling on build tools..
ifneq ($(SRCDIR),config)
PROF_FLAGS = $(OS_GPROF_FLAGS) -DMOZILLA_GPROF
endif
endif
# This compiles in heap dumping utilities and other good stuff
# for developers -- maybe we only want it in for a special SDK
# nspr/java runtime(?):
DEFINES += -DDEVELOPER_DEBUG
#
# For the standalone image lib
#
ifdef STANDALONE_IMAGE_LIB
DEFINES += -DSTANDALONE_IMAGE_LIB
endif
ifdef MODULAR_NETLIB
DEFINES += -DMODULAR_NETLIB
endif
######################################################################
GARBAGE = $(DEPENDENCIES) core $(wildcard core.[0-9]*)
ifndef SDK
SDK = $(DEPTH)/dist/sdk
endif
ifneq ($(OS_ARCH),WINNT)
NSINSTALL = $(DEPTH)/config/$(OBJDIR_NAME)/nsinstall
ifeq ($(NSDISTMODE),copy)
# copy files, but preserve source mtime
INSTALL = $(NSINSTALL) -t
else
ifeq ($(NSDISTMODE),absolute_symlink)
# install using absolute symbolic links
INSTALL = $(NSINSTALL) -L `$(NFSPWD)`
else
# install using relative symbolic links
INSTALL = $(NSINSTALL) -R
endif
endif
endif
######################################################################
### Java Stuff - see common.mk
######################################################################
# where the bytecode will go
JAVA_DESTPATH = $(XPDIST)/classes
# where the sources for the module you are compiling are
# default is sun-java/classsrc, override for other modules
ifndef JAVA_SOURCEPATH
JAVA_SOURCEPATH = $(DEPTH)/sun-java/classsrc
endif
ifndef JAVAH_IN_JAVA
ifeq ($(OS_ARCH),OS2)
JAVAH_PROG = flipper $(DIST)/bin/javah
else
JAVAH_PROG = $(DIST)/bin/javah
endif
else
JAVAH_PROG = $(JAVA) netscape.tools.jric.Main
endif
ifeq ($(STAND_ALONE_JAVA),1)
STAND_ALONE_JAVA_DLL_SUFFIX = s
endif
ifeq ($(OS_ARCH),OS2)
AWTDLL = awt$(MOZ_BITS)$(VERSION_NUMBER).$(DLL_SUFFIX)
AWTSDLL = awt$(MOZ_BITS)$(VERSION_NUMBER)$(STAND_ALONE_JAVA_DLL_SUFFIX).$(DLL_SUFFIX)
CONDLL = con.$(MOZ_BITS)$(VERSION_NUMBER)(DLL_SUFFIX)
JBNDLL = jbn.$(MOZ_BITS)$(VERSION_NUMBER)(DLL_SUFFIX)
JDBCDLL = jdb.$(MOZ_BITS)$(VERSION_NUMBER)(DLL_SUFFIX)
JITDLL = jit.$(MOZ_BITS)$(VERSION_NUMBER)(DLL_SUFFIX)
JPWDLL = jpw.$(MOZ_BITS)$(VERSION_NUMBER)(DLL_SUFFIX)
JRTDLL = jrt$(MOZ_BITS)$(VERSION_NUMBER).$(DLL_SUFFIX)
JSJDLL = jsj.$(MOZ_BITS)$(VERSION_NUMBER)(DLL_SUFFIX)
MMDLL = mm$(MOZ_BITS)$(VERSION_NUMBER).$(DLL_SUFFIX)
NETDLL = net.$(MOZ_BITS)$(VERSION_NUMBER)(DLL_SUFFIX)
NSCDLL = nsc.$(MOZ_BITS)$(VERSION_NUMBER)(DLL_SUFFIX)
ZIPDLL = zip.$(MOZ_BITS)$(VERSION_NUMBER)(DLL_SUFFIX)
ZPWDLL = zpw.$(MOZ_BITS)$(VERSION_NUMBER)(DLL_SUFFIX)
else
AWTDLL = libawt.$(DLL_SUFFIX)
AWTSDLL = libawt$(STAND_ALONE_JAVA_DLL_SUFFIX).$(DLL_SUFFIX)
CONDLL = libcon.$(DLL_SUFFIX)
JBNDLL = libjbn.$(DLL_SUFFIX)
JDBCDLL = libjdb.$(DLL_SUFFIX)
JITDLL = libjit.$(DLL_SUFFIX)
JPWDLL = libjpw.$(DLL_SUFFIX)
JRTDLL = libjrt.$(DLL_SUFFIX)
JSJDLL = libjsj.$(DLL_SUFFIX)
MMDLL = libmm.$(DLL_SUFFIX)
NETDLL = libnet.$(DLL_SUFFIX)
NSCDLL = libnsc.$(DLL_SUFFIX)
ZIPDLL = libzip.$(DLL_SUFFIX)
ZPWDLL = libzpw.$(DLL_SUFFIX)
endif
JAVA_DEFINES += -DAWTSDLL=\"$(AWTSDLL)\" -DCONDLL=\"$(CONDLL)\" -DJBNDLL=\"$(JBNDLL)\" -DJDBDLL=\"$(JDBDLL)\" \
-DJSJDLL=\"$(JSJDLL)\" -DNETDLL=\"$(NETDLL)\" -DNSCDLL=\"$(NSCDLL)\" -DZPWDLL=\"$(ZPWDLL)\" \
-DJAR_NAME=\"$(JAR_NAME)\"
ifeq ($(AWT_11),1)
JAVA_DEFINES += -DAWT_11
else
JAVA_DEFINES += -DAWT_102
endif

View File

@@ -1,134 +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.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

View File

@@ -1,195 +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.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

View File

@@ -1,159 +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.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_

View File

@@ -1,283 +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.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

View File

@@ -1,284 +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.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));
}

View File

@@ -1,212 +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.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

View File

@@ -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 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_

View File

@@ -1,97 +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.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_

View File

@@ -1,213 +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.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_

View File

@@ -1,258 +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.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_

View File

@@ -1,87 +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.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_

View File

@@ -1,163 +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.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_

View File

@@ -1,301 +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.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_

View File

@@ -1,40 +0,0 @@
#! 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)

View File

@@ -1,392 +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.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_

View File

@@ -1,155 +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.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;
}

View File

@@ -1,88 +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.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_

View File

@@ -1,355 +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.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

View File

@@ -1,117 +0,0 @@
// -*- 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_

View File

@@ -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 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_

View File

@@ -1,168 +0,0 @@
// -*- 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_

View File

@@ -1,270 +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.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

View File

@@ -1,269 +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.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_

View File

@@ -1,239 +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.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_

View File

@@ -1,186 +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.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();
}

View File

@@ -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 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_ */

View File

@@ -1,116 +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.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 &regA == &regB;}
//------------------------------------------------------------------------------
// 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_

2199
mozilla/include/net.h Normal file

File diff suppressed because it is too large Load Diff

39
mozilla/network/Makefile Normal file
View File

@@ -0,0 +1,39 @@
#! gmake
#
# 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.
#
#
DEPTH = ..
DIRS = \
cache \
client \
cnvts \
mimetype \
main \
protocol \
util
ifdef MODULAR_NETLIB
DIRS += module
endif
include $(DEPTH)/config/rules.mk
INCLUDE += $(PUBLIC)\ldap $(PUBLIC)\security

6
mozilla/network/cache/MANIFEST vendored Normal file
View File

@@ -0,0 +1,6 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#
extcache.h
netcache.h

42
mozilla/network/cache/Makefile vendored Normal file
View File

@@ -0,0 +1,42 @@
#!gmake
#
# 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.
DEPTH = ../..
MODULE = netcache
LIBRARY_NAME = netcache
CSRCS = \
cachedump.c \
extcache.c \
mkcache.c \
mkextcac.c \
mkmemcac.c \
$(NULL)
ifdef NU_CACHE
CSRCS += \
nucacheproto.c \
$(NULL)
endif
EXPORTS= netcache.h mkcache.h mkmemcac.h extcache.h
REQUIRES = network nspr2 dbm util pref js java fileurl security layer img jtools cachelib
include $(DEPTH)/config/rules.mk

139
mozilla/network/cache/cachedump.c vendored Normal file
View File

@@ -0,0 +1,139 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
/* this little program will sequentially dump out
* every record in the database
*/
#include "mkcache.h"
#include "extcache.h"
#include "plstr.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <assert.h>
#ifdef _sgi
#include <sys/endian.h>
#endif /* _sgi */
/* URL methods
*/
#define URL_GET_METHOD 0
#define URL_POST_METHOD 1
#define URL_HEAD_METHOD 2
static DB *
net_OpenExtCacheFatDB(char *filename)
{
DB *rv;
HASHINFO hash_info = {
16*1024, /* bucket size */
0, /* fill factor */
0, /* number of elements */
0, /* bytes to cache */
0, /* hash function */
0}; /* byte order */
rv = dbopen(filename,
O_RDWR | O_CREAT,
0644,
DB_HASH,
&hash_info);
if(!rv)
{
printf("Could not open cache database: %s\n", filename);
exit(1);
}
return(rv);
}
int main(int argc, char **argv)
{
char url[4028];
struct stat stat_s;
net_CacheObject * cache_obj;
DB * ext_cache_database=0;
DBT key;
DBT data;
int len;
char *end;
memset(&cache_obj, 0, sizeof(net_CacheObject));
if(argc != 2)
{
printf("Usage:\n"
"%s database\n"
"\n"
"database: path and name of the database\n", argv[0]);
exit(1);
}
/* open the cache database */
ext_cache_database = net_OpenExtCacheFatDB(argv[1]);
if(!ext_cache_database)
{
perror("Could not open cache database");
exit(1);
}
while(!(ext_cache_database->seq)(ext_cache_database, &key, &data, 0))
{
if(key.size == PL_strlen(EXT_CACHE_NAME_STRING)
&& !PL_strcmp(key.data, EXT_CACHE_NAME_STRING))
{
/* make sure it's a terminated string */
if(((char *)data.data)[data.size-1] == '\0')
printf("\n\nDatabase Name: %s\n", (char*)data.data);
else
printf("\n\nDatabase Name is corrupted!\n");
printf("\n--------------------------------------\n");
continue;
}
/* try and convert the db struct to a cache struct */
cache_obj = net_DBDataToCacheStruct(&data);
if(!cache_obj)
{
printf("Malformed database entry:\n");
printf("key: ");
fwrite(key.data, 1, key.size, stdout);
printf("\ndata: ");
fwrite(data.data, 1, data.size, stdout);
printf("\n");
printf("--------------------------------------\n");
continue;
}
/* the URL is 8 bytes into the key struct
*/
printf("URL: %s\n",(char*)key.data+8);
printf("file: %s\n", cache_obj->filename);
printf("is_relative_path: %s\n", cache_obj->is_relative_path ? "TRUE" : "FALSE");
printf("content_type: %s\n", cache_obj->content_type);
printf("content_length: %d\n", cache_obj->content_length);
printf("last_modified: %s\n", ctime(&cache_obj->last_modified));
printf("--------------------------------------\n");
}
}

21
mozilla/network/cache/cacheutils.h vendored Normal file
View File

@@ -0,0 +1,21 @@
#ifndef CACHEUTILS_H
#define CACHEUTILS_H
/* Find an actively-loading cache file for URL_s in context, and copy the first
* nbytes of it to a new cache file. Return a cache converter stream by which
* the caller can append to the cloned cache file.
*/
extern NET_VoidStreamClass *
NET_CloneWysiwygCacheFile(MWContext *context, URL_Struct *URL_s,
uint32 nbytes, const char * wysiwyg_url,
const char * base_href);
/* Create a wysiwyg cache converter to a copy of the current entry for URL_s.
*/
extern NET_VoidStreamClass *
net_CloneWysiwygMemCacheEntry(MWContext *window_id, URL_Struct *URL_s,
uint32 nbytes, const char * wysiwyg_url,
const char * base_href);
#endif /* CACHEUTILS_H */

6
mozilla/network/cache/export.mac vendored Normal file
View File

@@ -0,0 +1,6 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#
extcache.h
netcache.h

857
mozilla/network/cache/extcache.c vendored Normal file
View File

@@ -0,0 +1,857 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
/* Please leave outside of ifdef for window precompiled headers */
#include "mkcache.h"
#ifdef MOZILLA_CLIENT
#include "mktrace.h"
#include "prmem.h"
#include "plstr.h"
/* Publicly released Netscape cache access routines.
*
* These routines are shared between the netscape executable
* and the programs released as a cache developers kit.
*
* Created: Lou Montulli <montulli@netscape.com>, July-95.
* Modifications/Addition: Gagan Saksena, 97
*/
#include "rosetta.h"
#ifndef EXT_DB_ROUTINES
#include "secnav.h"
#include "sechash.h"
#endif
#include "extcache.h" /* include this for everything */
#ifdef EXT_DB_ROUTINES
#include <fcntl.h>
#include <sys/stat.h>
#include <assert.h>
typedef struct {
int32 len;
char *data;
} SECItem;
#ifdef _sgi
#include <sys/endian.h>
#endif /* _sgi */
/* URL methods
*/
#define URL_GET_METHOD 0
#define URL_POST_METHOD 1
#define URL_HEAD_METHOD 2
#endif /* DB_STORE */
MODULE_PRIVATE DBT *
net_CacheDBTDup(DBT *obj)
{
DBT * rv = PR_NEW(DBT);
if(!rv)
return(NULL);
rv->size = obj->size;
rv->data = PR_Malloc(rv->size);
if(!rv->data)
{
PR_Free(rv);
return(NULL);
}
memcpy(rv->data, obj->data, rv->size);
return(rv);
}
/* free the cache object
*/
MODULE_PRIVATE void net_freeCacheObj (net_CacheObject * cache_obj)
{
PR_FREEIF(cache_obj->address);
PR_FREEIF(cache_obj->post_data);
PR_FREEIF(cache_obj->post_headers);
PR_FREEIF(cache_obj->content_type);
PR_FREEIF(cache_obj->charset);
PR_FREEIF(cache_obj->content_encoding);
PR_FREEIF(cache_obj->page_services_url);
PR_FREEIF(cache_obj->filename);
#ifndef EXT_DB_ROUTINES
PR_FREEIF(cache_obj->sec_info);
#endif
PR_Free(cache_obj);
}
/* returns true if this DBT looks like a valid
* entry. It looks at the checksum and the
* version number to see if it's valid
*/
#define MAX_VALID_DBT_SIZE 10000
MODULE_PRIVATE PRBool
net_IsValidCacheDBT(DBT *obj)
{
char *cur_ptr, *max_ptr;
uint32 len;
if(!obj || obj->size < 9 || obj->size > MAX_VALID_DBT_SIZE)
return(FALSE);
cur_ptr = (char *)obj->data;
max_ptr = cur_ptr+obj->size;
/* get the total size of the struct out of
* the first field to check it
*/
COPY_INT32(&len, cur_ptr);
cur_ptr += sizeof(int32);
if(len != obj->size)
{
TRACEMSG(("Size going in is not the same as size coming out"));
return(FALSE);
}
/* get the version number of the written structure
*/
if(cur_ptr > max_ptr)
return(FALSE);
COPY_INT32(&len, cur_ptr);
cur_ptr += sizeof(int32);
if(len != CACHE_FORMAT_VERSION)
{
TRACEMSG(("Version of cache structure is wrong!: %d", len));
return(FALSE);
}
/* looks good to me... */
return(TRUE);
}
/* takes a cache object and returns a malloc'd
* (void *) suitible for passing in as a database
* data storage object
*/
MODULE_PRIVATE DBT *
net_CacheStructToDBData(net_CacheObject * old_obj)
{
int32 len;
char *cur_ptr;
void *new_obj;
int32 total_size;
DBT *rv;
rv = PR_NEW(DBT);
if(!rv)
return(NULL);
total_size = sizeof(net_CacheObject);
#define ADD_STRING_SIZE(string) \
total_size += old_obj->string ? PL_strlen(old_obj->string)+1 : 0
ADD_STRING_SIZE(address);
total_size += old_obj->post_data_size+1;
ADD_STRING_SIZE(post_headers);
ADD_STRING_SIZE(content_type);
ADD_STRING_SIZE(content_encoding);
ADD_STRING_SIZE(charset);
ADD_STRING_SIZE(filename);
total_size += sizeof(uint32); /* size of secinfo */
total_size += HG73653(old_obj->sec_info);
ADD_STRING_SIZE(page_services_url);
#undef ADD_STRING_SIZE
new_obj = PR_Malloc(total_size * sizeof(char));
if(!new_obj)
{
PR_Free(rv);
return NULL;
}
memset(new_obj, 0, total_size * sizeof(char));
/*
* order is:
* int32 size of the entire structure;
*
* int32 version of the structure format (CACHE_FORMAT_VERSION)
*
* time_t last_modified;
* time_t last_accessed;
* time_t expires;
* uint32 content_length;
* XP_Bool is_netsite;
*
* time_t lock_date;
*
* char * filename;
* int32 filename_len;
*
* int32 HG52242;
* unsigned char * HG42320;
*
* int32 method;
*
* # don't store address, or post_data stuff
* # char * address;
* # uint32 post_data_size;
* # char * post_data;
*
* char * post_headers;
* char * content_type;
* char * content_encoding;
* char * charset;
*
* XP_Bool incomplete_file;
* uint32 total_content_length;
*
* char * page_services_url;
*
* string lengths all include null terminators
* all integer constants are stored as 4 bytes
* all booleans are stored as one byte
*/
/* VERY VERY IMPORTANT. Whenever the
* format of the record structure changes
* you must verify that the byte positions
* in extcache.h are updated
*/
#define STUFF_STRING(string) \
{ \
len = (old_obj->string ? PL_strlen(old_obj->string)+1 : 0); \
COPY_INT32((void *)cur_ptr, &len); \
cur_ptr = cur_ptr + sizeof(int32); \
if(len) \
memcpy((void *)cur_ptr, old_obj->string, len); \
cur_ptr += len; \
}
#define STUFF_NUMBER(number) \
{ \
COPY_INT32((void *)cur_ptr, &old_obj->number); \
cur_ptr = cur_ptr + sizeof(int32); \
}
#define STUFF_TIMET(number) \
{ \
COPY_INT32((void *)cur_ptr, &old_obj->number); \
cur_ptr = cur_ptr + sizeof(time_t); \
}
#define STUFF_BOOL(bool_val) \
{ \
if(old_obj->bool_val) \
((char *)(cur_ptr))[0] = 1; \
else \
((char *)(cur_ptr))[0] = 0; \
cur_ptr = cur_ptr + sizeof(char); \
}
cur_ptr = (char *)new_obj;
/* put the total size of the struct into
* the first field so that we have
* a cross check against corruption
*/
COPY_INT32((void *)cur_ptr, &total_size);
cur_ptr = cur_ptr + sizeof(int32);
HG73209
/* put the version number of the structure
* format that we are using
* By using a version string when writting
* we can support backwards compatibility
* in our reading code
* (use "len" as a temp variable)
*/
len = CACHE_FORMAT_VERSION;
COPY_INT32((void *)cur_ptr, &len);
cur_ptr = cur_ptr + sizeof(int32);
STUFF_TIMET(last_modified);
STUFF_TIMET(last_accessed);
STUFF_TIMET(expires);
STUFF_NUMBER(content_length);
STUFF_BOOL(is_netsite);
STUFF_TIMET(lock_date);
STUFF_STRING(filename);
STUFF_NUMBER(filename_len);
STUFF_BOOL(is_relative_path);
STUFF_NUMBER(security_on);
#ifndef EXT_DB_ROUTINES
HG42539
/* save the security info */
if ( old_obj->sec_info ) {
len = HG65293(old_obj->sec_info);
COPY_INT32((void *)cur_ptr, &len);
cur_ptr = cur_ptr + sizeof(int32);
memcpy((void *)cur_ptr, old_obj->sec_info, len);
cur_ptr += len;
} else
#endif
{
len = 0;
COPY_INT32((void *)cur_ptr, &len);
cur_ptr = cur_ptr + sizeof(int32);
}
STUFF_NUMBER(method);
#ifdef STORE_ADDRESS_AND_POST_DATA
STUFF_STRING(address);
STUFF_NUMBER(post_data_size);
/* post_data
* this is special since it not necessarily a string
*/
if(old_obj->post_data_size)
{
memcpy(cur_ptr, old_obj->post_data, old_obj->post_data_size+1);
cur_ptr += old_obj->post_data_size+1;
}
#endif /* STORE_ADDRESS_AND_POST_DATA */
STUFF_STRING(post_headers);
STUFF_STRING(content_type);
STUFF_STRING(content_encoding);
STUFF_STRING(charset);
STUFF_BOOL(incomplete_file);
STUFF_NUMBER(real_content_length);
STUFF_STRING(page_services_url);
#undef STUFF_STRING
#undef STUFF_NUMBER
#undef STUFF_BOOL
rv->data = new_obj;
rv->size = total_size;
return(rv);
}
/* takes a database storage object and returns a malloc'd
* cache data object. The cache object needs all of
* it's parts free'd.
*
* returns NULL on parse error
*/
MODULE_PRIVATE net_CacheObject *
net_DBDataToCacheStruct(DBT * db_obj)
{
net_CacheObject * rv = PR_NEW(net_CacheObject);
char * cur_ptr;
char * max_ptr;
uint32 len;
int32 version;
if(!rv)
return NULL;
memset(rv, 0, sizeof(net_CacheObject));
/* if any strings are larger than this then
* there was a serious database error
*/
#define MAX_HUGE_STRING_SIZE 10000
#define RETRIEVE_STRING(string) \
{ \
if(cur_ptr > max_ptr) \
{ \
net_freeCacheObj(rv); \
return(NULL); \
} \
COPY_INT32(&len, cur_ptr); \
cur_ptr += sizeof(int32); \
if(len) \
{ \
if(len > MAX_HUGE_STRING_SIZE) \
{ \
net_freeCacheObj(rv); \
return(NULL); \
} \
rv->string = (char*)PR_Malloc(len); \
if(!rv->string) \
{ \
net_freeCacheObj(rv); \
return(NULL); \
} \
memcpy(rv->string, cur_ptr, len); \
cur_ptr += len; \
} \
}
#define RETRIEVE_NUMBER(number) \
{ \
if(cur_ptr > max_ptr) \
return(rv); \
COPY_INT32(&rv->number, cur_ptr); \
cur_ptr += sizeof(int32); \
}
#define RETRIEVE_TIMET(number) \
{ \
if(cur_ptr > max_ptr) \
return(rv); \
COPY_INT32(&rv->number, cur_ptr); \
cur_ptr += sizeof(time_t); \
}
#define RETRIEVE_BOOL(bool) \
{ \
if(cur_ptr > max_ptr) \
return(rv); \
if(((char *)(cur_ptr))[0]) \
rv->bool = TRUE; \
else \
rv->bool = FALSE; \
cur_ptr += sizeof(char); \
}
cur_ptr = (char *)db_obj->data;
max_ptr = cur_ptr+db_obj->size;
/* get the total size of the struct out of
* the first field to check it
*/
COPY_INT32(&len, cur_ptr);
cur_ptr += sizeof(int32);
if(len != db_obj->size)
{
TRACEMSG(("Size going in is not the same as size coming out"));
PR_Free(rv);
return(NULL);
}
/* get the version number of the written structure
*/
if(cur_ptr > max_ptr)
return(rv);
COPY_INT32(&version, cur_ptr);
cur_ptr += sizeof(int32);
if(version != CACHE_FORMAT_VERSION)
{
TRACEMSG(("Version of cache structure is wrong!: %d", version));
PR_Free(rv);
return(NULL);
}
HG32839
RETRIEVE_TIMET(last_modified);
RETRIEVE_TIMET(last_accessed);
RETRIEVE_TIMET(expires);
RETRIEVE_NUMBER(content_length);
RETRIEVE_BOOL(is_netsite);
RETRIEVE_TIMET(lock_date);
RETRIEVE_STRING(filename);
RETRIEVE_NUMBER(filename_len);
RETRIEVE_BOOL(is_relative_path);
HG72761
RETRIEVE_NUMBER(method);
#ifdef STORE_ADDRESS_AND_POST_DATA
RETRIEVE_STRING(address);
RETRIEVE_NUMBER(post_data_size);
/* post_data
* this is special since it not necessarily a string
*/
if(rv->post_data_size)
{
rv->post_data = PR_Malloc(rv->post_data_size+1);
if(rv->post_data)
memcpy(rv->post_data, cur_ptr, rv->post_data_size+1);
cur_ptr += rv->post_data_size+1;
}
#endif /* STORE_ADDRESS_AND_POST_DATA */
RETRIEVE_STRING(post_headers);
RETRIEVE_STRING(content_type);
RETRIEVE_STRING(content_encoding);
RETRIEVE_STRING(charset);
RETRIEVE_BOOL(incomplete_file);
RETRIEVE_NUMBER(real_content_length);
RETRIEVE_STRING(page_services_url);
#undef RETRIEVE_STRING
#undef RETRIEVE_NUMBER
#undef RETRIEVE_BOOL
return(rv);
}
#if defined(DEBUG) && defined(UNIX)
int
cache_test_me()
{
net_CacheObject test;
net_CacheObject *rv;
int32 total_size;
DBT *db_obj;
memset(&test, 0, sizeof(net_CacheObject));
StrAllocCopy(test.address, "test1");
db_obj = net_CacheStructToDBData(&test);
rv = net_DBDataToCacheStruct(db_obj);
printf("test1: %s\n", rv->address);
memset(&test, 0, sizeof(net_CacheObject));
StrAllocCopy(test.address, "test2");
StrAllocCopy(test.charset, "test2");
db_obj = net_CacheStructToDBData(&test);
rv = net_DBDataToCacheStruct(db_obj);
printf("test2: %s %s\n", rv->address, rv->charset);
memset(&test, 0, sizeof(net_CacheObject));
StrAllocCopy(test.address, "test3");
StrAllocCopy(test.charset, "test3");
test.content_length = 3 ;
test.method = 3 ;
test.is_netsite = 3 ;
db_obj = net_CacheStructToDBData(&test);
rv = net_DBDataToCacheStruct(db_obj);
printf("test3: %s %s %d %d %s\n",
rv->address, rv->charset,
rv->content_length, rv->method,
(rv->is_netsite == 3 ? "TRUE" : "FALSE"));
}
#endif
/* generates a key for use in the cache database
* from a CacheObject struct
*
* Key is based on the address and the post_data
*
* looks like:
* size checksum | size of address | ADDRESS | size of post data | POST DATA
*/
MODULE_PRIVATE DBT *
net_GenCacheDBKey(char *address, char *post_data, int32 post_data_size)
{
DBT *rv = PR_NEW(DBT);
char *hash;
char *data_ptr;
int32 str_len;
int32 size;
#define MD5_HASH_SIZE 16 /* always 16 due to md5 hash type */
if(!rv)
return(NULL);
if(!address)
{
PR_ASSERT(0);
rv->size = 0;
return(rv);
}
hash = PL_strchr(address, '#');
/* don't include '#' in a key */
if(hash)
*hash = '\0';
str_len = PL_strlen(address)+1;
size = sizeof(int32); /* for check sum */
size += sizeof(int32); /* for size of address */
size += str_len; /* for address string */
size += sizeof(int32); /* for size of post_data */
HG42490
rv->size = size;
rv->data = PR_Malloc(size);
if(!rv->data)
{
PR_Free(rv);
return NULL;
}
data_ptr = (char *) rv->data;
/* put in the checksum size */
COPY_INT32(data_ptr, &size);
data_ptr = data_ptr + sizeof(int32);
HG83777
/* put in the size of the address string */
COPY_INT32(data_ptr, &str_len);
data_ptr = data_ptr + sizeof(int32);
/* put in the address string data */
memcpy(data_ptr, address, str_len);
data_ptr = data_ptr + str_len;
/* set the address back to it's original form */
if(hash)
*hash = '#';
/* put in the size of the post data */
HG73699
{
COPY_INT32(data_ptr, &post_data_size);
data_ptr = data_ptr + sizeof(int32);
}
return(rv);
}
/* returns a static string that contains the
* URL->address of the key
*
* returns NULL on error
*/
MODULE_PRIVATE char *
net_GetAddressFromCacheKey(DBT *key)
{
uint32 size;
char *data;
/* check for minimum size */
if(key->size < 10)
return(NULL);
HG72873
/* validate size checksum */
data = (char *)key->data;
COPY_INT32(&size, data);
data += sizeof(int32);
if(size != key->size)
return(NULL);
/* get size of address string */
COPY_INT32(&size, data);
data += sizeof(int32);
/* make sure it's a valid c string */
if(data[size] != '\0')
return(NULL);
/* it's valid return it */
return(data);
}
/* checks a date within a DBT struct so
* that we don't have to convert it into a CacheObject
*
* This works because of the fixed length record format
* of the first part of the specific DBT format I'm
* using
*
* returns 0 on error
*/
MODULE_PRIVATE time_t
net_GetTimeInCacheDBT(DBT *data, int byte_position)
{
time_t date;
char *ptr = (char *)data->data;
if(data->size < byte_position+sizeof(time_t))
return(0);
if(!net_IsValidCacheDBT(data))
return(0);
COPY_INT32(&date, ptr+byte_position);
/* TRACEMSG(("Got date from cache DBT: %d", date)); */
return(date);
}
/* Sets a date within a DBT struct so
* that we don't have to convert it into a CacheObject
*
* This works because of the fixed length record format
* of the first part of the specific DBT format I'm
* using
*
* returns 0 on error
*/
MODULE_PRIVATE void
net_SetTimeInCacheDBT(DBT *data, int byte_position, time_t date)
{
char *ptr = (char *)data->data;
if(data->size < byte_position+sizeof(time_t))
return;
if(!net_IsValidCacheDBT(data))
return;
COPY_INT32(ptr+byte_position, &date);
return;
}
/* Gets the filename within a cache DBT struct so
* that we don't have to convert it into a CacheObject
*
* This works because of the fixed length record format
* of the first part of the specific DBT format I'm
* using
*
* returns NULL on error
*/
#define MAX_FILE_SIZE 2048
MODULE_PRIVATE char *
net_GetFilenameInCacheDBT(DBT *data)
{
int32 size;
char *rv;
char *ptr = (char*)data->data;
if(data->size < FILENAME_BYTE_POSITION)
return(NULL);
if(!net_IsValidCacheDBT(data))
return(0);
COPY_INT32(&size, ptr+FILENAME_SIZE_BYTE_POSITION);
if(data->size < FILENAME_BYTE_POSITION+size
|| size > MAX_FILE_SIZE)
return(NULL);
rv = (char *)PR_Malloc(size);
if(!rv)
return(NULL);
memcpy(rv, ptr+FILENAME_BYTE_POSITION, size);
TRACEMSG(("Got filename: %s from DBT", rv));
return(rv);
}
/* Gets a int32 within a DBT struct so
* that we don't have to convert it into a CacheObject
*
* This works because of the fixed length record format
* of the first part of the specific DBT format I'm
* using
*
* returns 0 on error
*/
MODULE_PRIVATE time_t
net_GetInt32InCacheDBT(DBT *data, int byte_position)
{
int32 num;
char *ptr = (char *)data->data;
if(!net_IsValidCacheDBT(data))
return(0);
if(data->size < byte_position+sizeof(time_t))
return(0);
COPY_INT32(&num, ptr+byte_position);
/* TRACEMSG(("Got int32 from cache DBT: %d", num)); */
return(num);
}
MODULE_PRIVATE void
net_FreeCacheDBTdata(DBT *stuff)
{
if(stuff)
{
PR_Free(stuff->data);
PR_Free(stuff);
}
}
/* takes a database storage object and returns an un-malloc'd
* cache data object. The structure returned has pointers
* directly into the database memory and are only valid
* until the next call to any database function
*
* do not free anything returned by this structure
*/
MODULE_PRIVATE net_CacheObject *
net_Fast_DBDataToCacheStruct(DBT *obj)
{
static net_CacheObject *rv=0;
/* free any previous one */
if(rv)
net_freeCacheObj(rv);
rv = net_DBDataToCacheStruct(obj);
return(rv);
}
#endif /* MOZILLA_CLIENT */

272
mozilla/network/cache/extcache.h vendored Normal file
View File

@@ -0,0 +1,272 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 EXT_CACHE_H
#define EXT_CACHE_H
#ifndef EXT_DB_ROUTINES
#include "mcom_db.h"
#endif
#ifdef EXT_DB_ROUTINES
#define PRBool char
#define uint32 unsigned int
#define int32 int
#define PR_NEW(structure) ((structure *) malloc(sizeof(structure)))
#define PR_Malloc (void *) malloc
#define memcpy memcpy
#define memset memset
#define TRACEMSG(x) printf x
#define FREEIF(x) do { if(x) free(x); } while(0)
#define FREE free
#define PL_strlen strlen
#define PL_strchr strchr
#define PL_strcmp strcmp
#define PR_ASSERT assert
#define MODULE_PRIVATE
#define PRIVATE static
#define TRUE !0
#define FALSE 0
#include <stdio.h>
#include <string.h>
#include <db.h>
#endif
#ifndef EXT_DB_ROUTINES
#ifndef NSPR20
#include "prosdep.h" /* for IS_LITTLE_ENDIAN / IS_BIG_ENDIAN */
#else
#include "prtypes.h"
#endif
#endif /* EXT_DB_ROUTINES */
#if !defined(IS_LITTLE_ENDIAN) && !defined(IS_BIG_ENDIAN)
ERROR! Must have a byte order
#endif
#ifdef IS_LITTLE_ENDIAN
#define COPY_INT32(_a,_b) memcpy(_a, _b, sizeof(int32));
#else
#define COPY_INT32(_a,_b) /* swap */ \
do { \
((char *)(_a))[0] = ((char *)(_b))[3]; \
((char *)(_a))[1] = ((char *)(_b))[2]; \
((char *)(_a))[2] = ((char *)(_b))[1]; \
((char *)(_a))[3] = ((char *)(_b))[0]; \
} while(0)
#endif
#define EXT_CACHE_NAME_STRING "INT_ExternalCacheNameString"
/* Internal WARNING!! Some slots of this structure
* are shared with URL_Struct and
* History_entry. If you add a slot, decide whether it needs to be shared
* as well.
*/
typedef struct _net_CacheObject {
time_t last_modified;
time_t last_accessed;
time_t expires;
PRBool is_netsite;
uint32 content_length;
char * filename; /* cache file name */
int32 filename_len; /* optimization */
PRBool is_relative_path; /* is the path relative? */
/* Security information */
int32 security_on; /* is security on? */
unsigned char *sec_info;
time_t lock_date; /* the file is locked if this
* is non-zero. The date
* represents the time the
* lock was put in place.
* Locks are only valid for
* one session
*/
int32 method;
char * address;
uint32 post_data_size;
char * post_data;
char * post_headers;
char * content_type;
char * content_encoding;
char * charset;
PRBool incomplete_file; /* means that the whole
* file is not there.
* This can only be true
* if the server supports byteranges
*/
uint32 real_content_length; /* the whole content length
* i.e. the server size of a truncated
* client file
*/
char * page_services_url;
char * etag; /* HTTP/1.1 Etag */
} net_CacheObject;
/* this is the version number of the cache database entry.
* It should be incremented in integer ingrements up
* to MAXINT32
*/
#define CACHE_FORMAT_VERSION 5
/* these defines specify the exact byte position
* of the first 4 elements in the DBT data struct
* Change these if you change the order of entry into
* the DBT
*/
#define LAST_MODIFIED_BYTE_POSITION \
sizeof(int32)+sizeof(int32)
#define LAST_ACCESSED_BYTE_POSITION \
sizeof(int32)+sizeof(int32)+sizeof(time_t)
#define EXPIRES_BYTE_POSITION \
sizeof(int32)+sizeof(int32)+sizeof(time_t)+sizeof(time_t)
#define CONTENT_LENGTH_BYTE_POSITION \
sizeof(int32)+sizeof(int32)+sizeof(time_t)+sizeof(time_t) \
+sizeof(time_t)
#define IS_NETSITE_BYTE_POSITION \
sizeof(int32)+sizeof(int32)+sizeof(time_t)+sizeof(time_t) \
+sizeof(time_t)+sizeof(int32)
#define LOCK_DATE_BYTE_POSITION \
sizeof(int32)+sizeof(int32)+sizeof(time_t)+sizeof(time_t) \
+sizeof(time_t)+sizeof(int32)+sizeof(char)
#define FILENAME_SIZE_BYTE_POSITION \
sizeof(int32)+sizeof(int32)+sizeof(time_t)+sizeof(time_t) \
+sizeof(time_t)+sizeof(uint32)+sizeof(char)+sizeof(time_t)
#define FILENAME_BYTE_POSITION \
sizeof(int32)+sizeof(int32)+sizeof(time_t)+sizeof(time_t) \
+sizeof(time_t)+sizeof(uint32)+sizeof(char)+sizeof(time_t) \
+sizeof(int32)
/* generates a key for use in the cache database
* from a CacheObject struct
*
* Key is based on the address and the post_data
*/
extern DBT *
net_GenCacheDBKey(char *address, char *post_data, int32 post_data_size);
/* returns a static string that contains the
* URL->address of the key
*
* returns NULL on error
*/
extern char *
net_GetAddressFromCacheKey(DBT *key);
/* allocs and copies a new DBT from an existing DBT
*/
extern DBT * net_CacheDBTDup(DBT *obj);
/* free the cache object
*/
extern void net_freeCacheObj (net_CacheObject * cache_obj);
/* takes a cache object and returns a malloc'd
* (void *) suitible for passing in as a database
* data storage object
*/
extern DBT * net_CacheStructToDBData(net_CacheObject * old_obj);
/* takes a database storage object and returns a malloc'd
* cache data object. The cache object needs all of
* it's parts free'd.
*
* returns NULL on parse error
*/
extern net_CacheObject * net_DBDataToCacheStruct(DBT * db_obj);
/* checks a date within a DBT struct so
* that we don't have to convert it into a CacheObject
*
* This works because of the fixed length record format
* of the first part of the specific DBT format I'm
* using
*
* returns 0 on error
*/
extern time_t net_GetTimeInCacheDBT(DBT *data, int byte_position);
/* Sets a date within a DBT struct so
* that we don't have to convert it into a CacheObject
*
* This works because of the fixed length record format
* of the first part of the specific DBT format I'm
* using
*
* returns 0 on error
*/
extern void net_SetTimeInCacheDBT(DBT *data, int byte_position, time_t date);
/* Gets the filename within a cache DBT struct so
* that we don't have to convert it into a CacheObject
*
* This works because of the fixed length record format
* of the first part of the specific DBT format I'm
* using
*
* returns NULL on error
*/
extern char * net_GetFilenameInCacheDBT(DBT *data);
/* Gets a int32 within a DBT struct so
* that we don't have to convert it into a CacheObject
*
* This works because of the fixed length record format
* of the first part of the specific DBT format I'm
* using
*
* returns 0 on error
*/
extern time_t net_GetInt32InCacheDBT(DBT *data, int byte_position);
/* free's a DBT struct
*/
extern void net_FreeCacheDBTdata(DBT *stuff);
/* stores a cache object in the DBM database
*/
extern void net_ExtCacheStore(DB *database, net_CacheObject * obj);
/* takes a database storage object and returns an un-malloc'd
* cache data object. The structure returned has pointers
* directly into the database memory and are only valid
* until the next call to any database function
*
* do not free anything returned by this structure
*/
extern net_CacheObject * net_Fast_DBDataToCacheStruct(DBT *obj);
/* returns true if this DBT looks like a valid
* entry. It looks at the checksum and the
* version number to see if it's valid
*/
extern PRBool net_IsValidCacheDBT(DBT *obj);
#endif /* EXT_CACHE_H */

105
mozilla/network/cache/makefile.win vendored Normal file
View File

@@ -0,0 +1,105 @@
#!gmake
#
# 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.
IGNORE_MANIFEST=1
#
#------------------------------------------------------------------------
#
# Makefile to build the cache LIB
#
#------------------------------------------------------------------------
#!ifdef MOZ_JAVA
#LOCAL_JMC_SUBDIR = .
#!endif
#
# Make sure we have MOZILLA_CLIENT defined so we get the
# proper JS includes
#
LCFLAGS = $(LCFLAGS) -DMOZILLA_CLIENT
!ifdef BUILD_DEBUG_GC
LCFLAGS = $(LCFLAGS) -DDEBUG_GC
!endif
LLIBS= \
$(NULL)
MISCDEP=$(LLIBS)
OBJS= \
.\$(OBJDIR)\extcache.obj \
.\$(OBJDIR)\mkcache.obj \
.\$(OBJDIR)\mkextcac.obj \
.\$(OBJDIR)\mkmemcac.obj \
!ifdef NU_CACHE
.\$(OBJDIR)\nucacheproto.obj \
!endif
$(NULL)
CSRCS = \
cachedump.c \
extcache.c \
mkcache.c \
mkextcac.c \
mkmemcac.c \
!ifdef NU_CACHE
nucacheproto.c \
!endif
$(NULL)
LIBRARY_NAME=netcache
MODULE=netcache
DEPTH=..\..
EXTRA_LIBS=
REQUIRES= network nspr2 cachelib
EXPORTS= netcache.h
C_OBJS = \
$(NULL)
# use LINCS on win32 for now since REQUIRES seems to be broken
#!if "$(MOZ_BITS)" != "16"
LINCS= \
-I$(XPDIST)\public\nspr2 \
-I$(XPDIST)\public\dbm \
-I$(XPDIST)\public\util \
-I$(XPDIST)\public\pref \
-I$(XPDIST)\public\network \
-I$(XPDIST)\public\js \
-I$(XPDIST)\public\java \
-I$(XPDIST)\public\fileurl \
-I$(XPDIST)\public\security \
-I$(XPDIST)\public\cache \
-I$(XPDIST)\public\jtools
#!endif
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
symbols::
@echo "LIBRARY_NAME is $(LIBRARY_NAME)"
@echo "LIBRARY is $(LIBRARY)"

3835
mozilla/network/cache/mkcache.c vendored Normal file

File diff suppressed because it is too large Load Diff

40
mozilla/network/cache/mkcache.h vendored Normal file
View File

@@ -0,0 +1,40 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 MKCACHE_H
#define MKCACHE_H
#include "xp.h"
#ifndef EXT_CACHE_H
#include "extcache.h"
#endif
#ifndef NU_CACHE
/* trace variable for cache testing */
extern PRBool NET_CacheTraceOn;
#endif /* This is handled by CacheTrace_Enable() and CacheTrace_IsEnabled() in the NU world */
PR_BEGIN_EXTERN_C
#ifndef NU_CACHE
/* public accessor function for netcaster */
extern PRBool NET_CacheStore(net_CacheObject *cacheObject, URL_Struct *url_s, PRBool accept_partial_files);
#endif
PR_END_EXTERN_C
#endif /* MKCACHE_H */

1554
mozilla/network/cache/mkextcac.c vendored Normal file

File diff suppressed because it is too large Load Diff

22
mozilla/network/cache/mkextcac.h vendored Normal file
View File

@@ -0,0 +1,22 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 MKEXTCACHE_H
#define MKEXTCACHE_H
#endif /* MKEXTCACHE_H */

2141
mozilla/network/cache/mkmemcac.c vendored Normal file

File diff suppressed because it is too large Load Diff

61
mozilla/network/cache/mkmemcac.h vendored Normal file
View File

@@ -0,0 +1,61 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 MK_MEMORY_CACHE_H
#include "mkgeturl.h"
/* A pointer to this struct is passed as the converter_obj argument to
* NET_MemCacheConverter.
*/
typedef struct net_MemCacheConverterObject {
NET_StreamClass *next_stream;
PRBool dont_hold_URL_s;
} net_MemCacheConverterObject;
extern NET_StreamClass *
NET_MemCacheConverter (FO_Present_Types format_out,
void *converter_obj,
URL_Struct *URL_s,
MWContext *window_id);
/* remove a URL from the memory cache
*/
extern void
NET_RemoveURLFromMemCache(URL_Struct *URL_s);
/* set or unset a lock on a memory cache object
*/
extern void
NET_ChangeMemCacheLock(URL_Struct *URL_s, PRBool set);
/* Create a wysiwyg cache converter to a copy of the current entry for URL_s.
*/
extern NET_StreamClass *
net_CloneWysiwygMemCacheEntry(MWContext *window_id, URL_Struct *URL_s,
uint32 nbytes, const char * wysiwyg_url,
const char * base_href);
/* return the first cache object in memory */
extern net_CacheObject *
NET_FirstMemCacheObject(XP_List* list_ptr);
/* return the next cache object in memory */
extern net_CacheObject *
NET_NextMemCacheObject(XP_List* list_ptr);
#endif /* MK_MEMORY_CACHE_H */

79
mozilla/network/cache/netcache.h vendored Normal file
View File

@@ -0,0 +1,79 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 NETCACHE_H
#define NETCACHE_H
#include "mkgeturl.h"
PR_BEGIN_EXTERN_C
/* Initialization */
extern void NET_CacheInit(void);
/* Shutdown */
extern void NET_CleanupCache(void);
/* create an HTML stream and push a bunch of HTML about
* the cache
*/
extern void NET_DisplayCacheInfoAsHTML(ActiveEntry * cur_entry);
/* create an HTML stream and push a bunch of HTML about
* the memory cache - TODO consolidate these two into one function! - Gagan
*/
extern void NET_DisplayMemCacheInfoAsHTML(ActiveEntry * cur_entry);
extern int NET_FindURLInCache(URL_Struct * URL_s, MWContext *ctxt);
#ifdef NU_CACHE
extern void NET_InitNuCacheProtocol(void);
#else
extern void NET_InitMemCacProtocol(void);
#endif
/* Will go away later */
extern PRBool NET_IsCacheTraceOn(void);
/* return TRUE if the URL is in the cache and
* is a partial cache file - TODO- only used in HTTP- cleanup - Gagan
*/
extern PRBool NET_IsPartialCacheFile(URL_Struct *URL_s);
/* Update cache entry on a 304 return*/
extern void NET_RefreshCacheFileExpiration(URL_Struct * URL_s);
/* remove a URL from the cache */
extern void NET_RemoveURLFromCache(URL_Struct *URL_s);
/* Removed in NU_Cache, SAR should go through new api. - Gagan */
#ifndef NU_CACHE
extern void NET_OpenExtCacheFAT(MWContext *ctxt, char * cache_name, char * instructions);
extern void CACHE_CloseAllOpenSARCache();
extern void CACHE_OpenAllSARCache();
extern int NET_FindURLInMemCache(URL_Struct * URL_s, MWContext *ctxt);
/* lookup routine
*
* builds a key and looks for it in the database. Returns an access
* method and sets a filename in the URL struct if found
*/
extern int NET_FindURLInExtCache(URL_Struct * URL_s, MWContext *ctxt);
#endif
PR_END_EXTERN_C
#endif /* NETCACHE_H */

26
mozilla/network/cache/nu/Makefile vendored Normal file
View File

@@ -0,0 +1,26 @@
#!gmake
#
# 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.
DEPTH = ../../..
DIRS = public src
include $(DEPTH)/config/config.mk
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,24 @@
#!gmake
#
# 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.
DEPTH = ../../../..
MODULE = cache
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,18 @@
#!gmake
#
# 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 $(MOZ_SRC)\ns\config\rules.mak

View File

@@ -0,0 +1,65 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 _nsCacheTrace_H_
#define _nsCacheTrace_H_
/*
* nsCacheTrace
*
* Gagan Saksena
* 02/02/98
*
*/
#ifndef CRLF
# define CRLF "\r\n"
#endif
#include "prtypes.h"
#include "prlog.h"
class nsCacheTrace
{
public:
nsCacheTrace(void);
static void Enable(PRBool bEnable);
static PRBool IsEnabled(void);
static void Trace(const char* msg);
static void Traceln(const char* msg);
static void Use(char* buffer);
static char* m_TraceBuffer;
private:
PRBool m_bEnabled;
};
inline void nsCacheTrace::Trace(const char* msg)
{
PR_ASSERT(msg);
//Do log stuff here TODO
}
inline void nsCacheTrace::Traceln(const char* msg)
{
Trace(msg);
Trace(CRLF);
}
inline void nsCacheTrace::Use(char* buffer)
{
m_TraceBuffer = buffer;
}
#endif

View File

@@ -0,0 +1,132 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 nsFFEntry_h__
#define nsFFEntry_h__
#include "nsFFObject.h"
//#include "nsISupports.h"
/** An FFEntry consists of several objects, all io takes place
* through the FFEntry's read and write functions */
class nsFFEntry//: public nsISupports
{
public:
nsFFEntry();
nsFFEntry(const PRUint32 i_ID);
//Single block entries can use this constructor
nsFFEntry(const PRUint32 i_ID, const PRUint32 i_offset, const PRUint32 i_size);
virtual ~nsFFEntry();
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
PRBool AddObject(const nsFFObject* i_object);
//Appends an entry to the list
PRBool AddEntry(const nsFFEntry* i_pEntry);
nsFFObject* FirstObject(void) const;
void FirstObject(const nsFFObject* i_object);
PRUint32 ID(void) const;
void ID(const PRUint32 i_ID);
nsFFEntry* NextEntry(void) const;
void NextEntry(const nsFFEntry* i_pEntry);
//Returns the number of objects in this entry.
PRUint32 Objects(void) const;
PRBool Remove(void);
PRUint32 Size(void) const;
protected:
private:
nsFFEntry(const nsFFEntry& o);
nsFFEntry& operator=(const nsFFEntry& o);
nsFFObject* m_pFirstObject;
nsFFEntry* m_pNextEntry;
PRUint32 m_ID;
PRUint32 m_Objects;
};
inline
PRBool nsFFEntry::AddEntry(const nsFFEntry* i_Entry)
{
if (!i_Entry)
return PR_FALSE;
if (m_pNextEntry)
return m_pNextEntry->AddEntry(i_Entry);
m_pNextEntry = (nsFFEntry*) i_Entry;
return PR_TRUE;
}
inline
nsFFObject* nsFFEntry::FirstObject(void) const
{
return m_pFirstObject;
}
inline
PRUint32 nsFFEntry::ID(void) const
{
return m_ID;
}
inline
void nsFFEntry::ID(const PRUint32 i_id)
{
m_ID = i_id;
}
inline
nsFFEntry* nsFFEntry::NextEntry(void) const
{
return m_pNextEntry;
}
inline
void nsFFEntry::NextEntry(const nsFFEntry* i_pEntry)
{
m_pNextEntry = (nsFFEntry*) i_pEntry;
}
inline
PRUint32 nsFFEntry::Objects(void) const
{
return m_Objects;
}
inline
PRUint32 nsFFEntry::Size(void) const
{
return m_pFirstObject ? m_pFirstObject->TotalSize() : 0; // Assumption that there is no zero length files //TODO
}
#endif // nsFFEntry_h__

View File

@@ -0,0 +1,125 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 nsFFObject_h__
#define nsFFObject_h__
#include "prtypes.h"
class nsFFObject
{
public:
nsFFObject(
PRUint32 i_ID,
PRUint32 i_Offset,
PRUint32 i_Size = 0);
virtual ~nsFFObject();
PRBool Add(const nsFFObject* i_object);
PRUint32 ID(void) const;
void ID(const PRUint32 i_ID);
nsFFObject* Next(void) const;
void Next(nsFFObject* io_pNext);
PRUint32 Offset(void) const;
void Offset(const PRUint32 i_offset);
PRUint32 Size(void) const;
void Size(const PRUint32 i_Size);
PRUint32 TotalSize(void) const;
protected:
private:
nsFFObject(const nsFFObject& o);
nsFFObject& operator=(const nsFFObject& o);
PRUint32 m_ID;
PRUint32 m_Offset;
PRUint32 m_Size;
nsFFObject* m_pNext;
};
inline
PRUint32 nsFFObject::ID(void) const
{
return m_ID;
}
inline
void nsFFObject::ID(const PRUint32 i_ID)
{
m_ID = i_ID;
}
inline
nsFFObject* nsFFObject::Next(void) const
{
return m_pNext;
}
inline
void nsFFObject::Next(nsFFObject* io_pNext)
{
if (io_pNext)
io_pNext->ID(m_ID);
m_pNext = io_pNext;
// Overlap check! //TODO
//PR_ASSERT(io_pNext->Offset() > m_Offset + m_Size) ||
// (io_pNext->Offset() + io_pNext->Size() < m_Offset)
}
inline
PRUint32 nsFFObject::Offset(void) const
{
return m_Offset;
}
inline
void nsFFObject::Offset(const PRUint32 i_Offset)
{
m_Offset = i_Offset;
//TODO - overlap check.
}
inline
PRUint32 nsFFObject::Size(void) const
{
return m_Size;
}
inline
void nsFFObject::Size(const PRUint32 i_Size)
{
m_Size = i_Size;
//TODO - Overlap check.
}
inline
PRUint32 nsFFObject::TotalSize(void) const
{
return m_Size + (m_pNext ? m_pNext->TotalSize() : 0);
}
#endif // nsFFObject_h__

View File

@@ -0,0 +1,107 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 nsFlatFile_h__
#define nsFlatFile_h__
#include "prtypes.h"
#include "prio.h"
//#include "nsISupports.h"
#ifdef IS_LITTLE_ENDIAN
#ifndef COPY_INT32
#define COPY_INT32(_a,_b) memcpy(_a, _b, sizeof(int32))
#else
#define COPY_INT32(_a,_b) /* swap */ \
do { \
((char *)(_a))[0] = ((char *)(_b))[3]; \
((char *)(_a))[1] = ((char *)(_b))[2]; \
((char *)(_a))[2] = ((char *)(_b))[1]; \
((char *)(_a))[3] = ((char *)(_b))[0]; \
} while(0)
#endif
#endif
/** A class to handle flat file storage mechanism */
static const PRUint32 kPAGE_SIZE =4096;
class nsFlatFile //: public nsISupports
{
public:
nsFlatFile(const char* i_pFilename,
const PRUint32 i_FileSize= 5242880); // 5 meg
// TODO think if we want to substract the toc size from this?
virtual ~nsFlatFile();
const char* Filename(void) const;
PRUint32 HeaderSize(void) const;
void Init(void);
PRBool IsValid(void) const;
PRUint32 Size(void) const;
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
protected:
private:
nsFlatFile(const nsFlatFile& o);
nsFlatFile& operator=(const nsFlatFile& o);
PRBool m_bIsValid;
char* m_pFilename;
PRUint32 m_Size;
PRFileDesc* m_pFD;
PRUint32 m_HeaderSize;
};
inline
const char* nsFlatFile::Filename(void) const
{
return m_pFilename;
}
inline
PRUint32 nsFlatFile::HeaderSize(void) const
{
return m_HeaderSize;
}
inline
PRBool nsFlatFile::IsValid(void) const
{
return m_bIsValid;
}
inline
PRUint32 nsFlatFile::Size(void) const
{
return m_Size;
}
#endif // nsFlatFile_h__

108
mozilla/network/cache/nu/include/nsTOC.h vendored Normal file
View File

@@ -0,0 +1,108 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 nsTOC_h__
#define nsTOC_h__
//#include "nsISupports.h"
#include "nsFlatFile.h"
#include "nsFFEntry.h"
class nsTOC//: public nsISupports
{
public:
nsTOC(const char* i_pFilename, nsFlatFile* i_pFlatFile);
virtual ~nsTOC();
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
nsFFEntry* AddEntry(PRUint32 i_size = kPAGE_SIZE);
PRUint32 Entries(void) const;
const char* Filename(void) const;
nsFFEntry* FirstDataEntry(void) const;
nsFFEntry* FreeEntry(void) const;
void Init(void);
PRBool IsValid(void) const;
protected:
PRUint32 NextID(void) const;
PRBool Serialize(nsFFEntry* io_Entry, PRBool bRead = PR_FALSE);
private:
nsTOC(const nsTOC& o);
nsTOC& operator=(const nsTOC& o);
nsFFEntry* m_pContents; // The first entry is reserved for free space list
PRUint32 m_Entries;
char* m_pFilename;
nsFlatFile* m_pFlatFile;
PRFileDesc* m_pFD;
PRBool m_bIsValid;
};
inline
PRUint32 nsTOC::Entries(void) const
{
return m_Entries;
}
inline
const char* nsTOC::Filename(void) const
{
return m_pFilename;
}
inline
nsFFEntry* nsTOC::FirstDataEntry(void) const
{
return m_pContents ? m_pContents->NextEntry() : 0;
}
inline
nsFFEntry* nsTOC::FreeEntry(void) const
{
return m_pContents;
}
inline
PRBool nsTOC::IsValid(void) const
{
return m_bIsValid;
}
inline
PRUint32 nsTOC::NextID(void) const
{
return m_Entries + 1;
}
#endif // nsTOC_h__

View File

@@ -0,0 +1,25 @@
/* A class to time excursion events */
/* declare an object of this class within the scope to be timed. */
#include "prtypes.h"
#include "prinrval.h"
class nsTimeIt
{
public:
nsTimeIt(PRUint32& tmp);
~nsTimeIt();
private:
PRIntervalTime t;
PRUint32& dest;
};
inline
nsTimeIt::nsTimeIt(PRUint32& tmp):t(PR_IntervalNow()), dest(tmp)
{
}
inline
nsTimeIt::~nsTimeIt()
{
dest = PR_IntervalToMicroseconds(PR_IntervalNow()-t);
}

View File

@@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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
@@ -15,11 +15,13 @@
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
//
// nuCache.Prefix
//
// Global prefix file for the nuCache project.
//
//
#ifndef _REGISTER_CLASS_H_
#define _REGISTER_CLASS_H_
#include "Fundamentals.h"
#include "RegisterTypes.h"
#endif // _REGISTER_CLASS_H_
#include "MacPrefix_debug.h"
#include "nuCacheConfig.h"

Binary file not shown.

View File

@@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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
@@ -15,6 +15,4 @@
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "Fundamentals.h"
#include "HashSet.h"
#define CGLUESUPPORTED 0 // turn off C glue support to avoid conflict on create() in RDF

View File

@@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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
@@ -16,6 +16,12 @@
* Reserved.
*/
#include "Fundamentals.h"
#include "Liveness.h"
//
// RDFDebug.Prefix
//
// Global prefix file for the nuCache project.
//
//
#include "MacPrefix_debug.h"
#include "nuCacheConfig.h"

22
mozilla/network/cache/nu/makefile.win vendored Normal file
View File

@@ -0,0 +1,22 @@
#!gmake
#
# 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.
DEPTH=..\..\..
DIRS=public src
include <$(DEPTH)\config\rules.mak>

50
mozilla/network/cache/nu/nsGeneric.cpp vendored Normal file
View File

@@ -0,0 +1,50 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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.
*
* 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.
*/
#include "nsGeneric.h"
nsGeneric::nsGeneric()
{
}
nsGeneric::~nsGeneric()
{
}
nsrefcnt nsGeneric::AddRef(void)
{
return ++m_RefCnt;
}
nsrefcnt nsGeneric::Release(void)
{
if (--m_RefCnt == 0)
{
delete this;
return 0;
}
return m_RefCnt;
}
nsresult nsGeneric::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
return NS_OK;
}
nsGeneric::

45
mozilla/network/cache/nu/nsGeneric.h vendored Normal file
View File

@@ -0,0 +1,45 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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.
*
* 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.
*/
#ifndef nsGeneric_h__
#define nsGeneric_h__
#include "nsISupports.h"
class nsGeneric: public nsISupports
{
public:
nsGeneric();
virtual ~nsGeneric();
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
protected:
private:
nsGeneric(const nsGeneric& o);
nsGeneric& operator=(const nsGeneric& o);
};
#endif // nsGeneric_h__

View File

@@ -0,0 +1,130 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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.
*
* 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.
*/
/* Design and original implementation by Gagan Saksena '98 */
/* Ideally we should be using the C++ api directly, but since the core of
Netlib is still in C, this file uses the stub functions that call the C++
API internally, allowing C programs to use the new cache architecture.
If you are accessing the cache, see if you can directly use the C++ api. */
#ifndef CacheStubs_h__
#define CacheStubs_h__
#include "prtypes.h"
#include "prinrval.h"
#define MEM_MODULE_ID 0
#define DISK_MODULE_ID 1
PR_BEGIN_EXTERN_C
/* General mapped functions which resolve to a bunch of internal calls. */
extern void Cache_Init(void);
extern void Cache_Shutdown(void);
/* Cache Manager stub functions
Does not include some functions not required in the current
design like AddModule etc... If you need to these functions, try
accessing them directly thru the C++ api or let me know.
Check nsCacheManager.h for details on these functions.*/
extern PRBool CacheManager_Contains(const char* i_url);
extern PRInt16 CacheManager_Entries(void);
extern void* CacheManager_GetObject(const char* i_url);
extern PRBool CacheManager_IsOffline(void);
extern void CacheManager_Offline(PRBool bSet);
extern PRBool CacheManager_Remove(const char* i_url);
extern PRUint32 CacheManager_WorstCaseTime(void);
/* Cache Object- check nsCacheObject.h for details on these functions */
extern void* CacheObject_Create(const char* i_url);
extern void CacheObject_Destroy(void* pThis);
extern const char* CacheObject_GetAddress(const void* pThis);
extern const char* CacheObject_GetCharset(void* pThis);
extern const char* CacheObject_GetContentEncoding(void* pThis);
extern PRUint32 CacheObject_GetContentLength(void* pThis);
extern const char* CacheObject_GetContentType(void* pThis);
extern const char* CacheObject_GetEtag(const void* pThis);
extern PRIntervalTime CacheObject_GetExpires(const void* pThis);
extern const char* CacheObject_GetFilename(const void* pThis);
extern PRIntervalTime CacheObject_GetLastAccessed(const void* pThis);
extern PRIntervalTime CacheObject_GetLastModified(const void* pThis);
extern PRInt16 CacheObject_GetModule(const void* pThis);
extern const char* CacheObject_GetPageServicesURL(void* pThis);
extern const char* CacheObject_GetPostData(const void* pThis);
extern PRUint32 CacheObject_GetPostDataLen(const void* pThis);
extern PRUint32 CacheObject_GetSize(const void* pThis);
extern PRUint32 CacheObject_Hits(const void* pThis);
extern PRBool CacheObject_IsExpired(const void* pThis);
extern PRBool CacheObject_IsPartial(const void* pThis);
extern PRUint32 CacheObject_Read(const void* pThis, char* o_Destination, PRUint32 i_Len);
extern void CacheObject_SetAddress(void* pThis, const char* i_Address);
extern void CacheObject_SetCharset(void* pThis, const char* i_CharSet);
extern void CacheObject_SetContentEncoding(void* pThis, const char* i_Encoding);
extern void CacheObject_SetContentLength(void* pThis, PRUint32 i_Len);
extern void CacheObject_SetContentType(void* pThis, const char* i_Type);
extern void CacheObject_SetEtag(void* pThis, const char* i_Etag);
extern void CacheObject_SetExpires(void *pThis, const PRIntervalTime i_Time);
extern void CacheObject_SetFilename(void *pThis, const char* i_Filename);
extern void CacheObject_SetLastModified(void* pThis, const PRIntervalTime i_Time);
extern void CacheObject_SetModule(void* pThis, const PRInt16 i_Module);
extern void CacheObject_SetPageServicesURL(void* pThis, const char* i_Url);
extern void CacheObject_SetPostData(void* pThis, const char* i_PostData, const PRUint32 i_Len);
extern void CacheObject_SetSize(void* pThis, const PRUint32 i_Size);
extern PRBool CacheObject_Synch(void* pThis);
extern PRUint32 CacheObject_Write(void* pThis, const char* i_buffer, const PRUint32 i_length);
/* Cache Prefs- check nsCachePref.h for details on these functions */
extern PRUint32 CachePref_GetDiskCacheSize(void);
extern PRBool CachePref_GetDiskCacheSSL(void);
extern PRUint32 CachePref_GetMemCacheSize(void);
extern void CachePref_SetDiskCacheSize(const PRUint32 i_Size);
extern void CachePref_SetDiskCacheSSL(PRBool bSet);
extern void CachePref_SetMemCacheSize(const PRUint32 i_Size);
/* Cache Trace- Check nsCacheTrace.h for details on these functions */
extern void CacheTrace_Enable(PRBool bEnable);
extern PRBool CacheTrace_IsEnabled(void);
/* Disk Module- Check nsDiskModule.h for details on these functions */
extern PRBool DiskModule_AddObject(void* pCacheObject);
extern PRBool DiskModule_Contains(const char* i_url);
extern PRUint32 DiskModule_Entries(void);
extern PRUint32 DiskModule_GetSize(void); /* Should be the same as CachePref_DiskCacheSize */
extern PRUint32 DiskModule_GetSizeInUse(void);
extern PRBool DiskModule_IsEnabled(void);
extern PRBool DiskModule_Remove(const char* i_url);
extern PRBool DiskModule_RemoveAll(void);
extern void DiskModule_SetSize(PRUint32 i_Size);
/* Mem Module- Check nsMemModule.h for details on these functions */
extern PRBool MemModule_AddObject(void* pCacheObject);
extern PRBool MemModule_Contains(const char* i_url);
extern PRUint32 MemModule_Entries(void);
extern PRUint32 MemModule_GetSize(void); /* Should be the same as CachePref_MemCacheSize */
extern PRUint32 MemModule_GetSizeInUse(void);
extern PRBool MemModule_IsEnabled(void);
extern PRBool MemModule_Remove(const char* i_url);
extern PRBool MemModule_RemoveAll(void);
extern void MemModule_SetSize(PRUint32 i_Size);
PR_END_EXTERN_C
#endif // CacheStubs_h__

View File

@@ -0,0 +1,35 @@
#!gmake
#
# 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.
DEPTH=../../../..
EXPORTS = \
nsMonitorable.h \
nsMemModule.h \
nsCacheManager.h \
nsDiskModule.h \
nsCacheModule.h \
nsMemCacheObject.h \
nsCacheObject.h \
nsCachePref.h \
$(NULL)
MODULE = cache
include $(DEPTH)/config/config.mk
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,32 @@
#!nmake
#
# 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.
DEPTH=..\..\..\..
IGNORE_MANIFEST=1
MODULE=cache
EXPORTS=nsCacheObject.h nsMemModule.h nsCacheManager.h \
nsDiskModule.h nsCacheModule.h nsMemCacheObject.h \
nsCachePref.h nsCacheBkgThd.h nsBkgThread.h \
CacheStubs.h nsCacheIterator.h nsIterator.h \
nsMonitorable.h nsStream.h nsFileStream.h \
nsMemStream.h \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,64 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 nsBkgThread_h__
#define nsBkgThread_h__
//#include "nsISupports.h"
#include "prthread.h"
#include "prinrval.h"
/*
Creates a background thread that maintains odd
tasks like updating, expiration, validation and
garbage collection.
Note that this is a noop active when the cache
manager is offline.
In PRThread terms, this is a PR_USER_THREAD with
local scope.
*/
class nsBkgThread//: public nsISupports
{
public:
nsBkgThread(PRIntervalTime iSleepTime, PRBool bStart=PR_TRUE);
virtual ~nsBkgThread();
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
void Process(void);
virtual void Run(void) = 0;
void Stop(void);
protected:
PRThread* m_pThread;
PRBool m_bContinue;
PRIntervalTime m_SleepTime;
private:
nsBkgThread(const nsBkgThread& o);
nsBkgThread& operator=(const nsBkgThread& o);
};
#endif // nsBkgThread_h__

View File

@@ -0,0 +1,46 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 nsCacheBkgThd_h__
#define nsCacheBkgThd_h__
#include "nsBkgThread.h"
class nsCacheBkgThd: public nsBkgThread
{
public:
nsCacheBkgThd(PRIntervalTime iSleepTime);
virtual ~nsCacheBkgThd();
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
void Run(void);
protected:
private:
nsCacheBkgThd(const nsCacheBkgThd& o);
nsCacheBkgThd& operator=(const nsCacheBkgThd& o);
};
#endif // nsCacheBkgThd_h__

View File

@@ -0,0 +1,74 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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.
*
* 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.
*/
#ifndef nsCacheIterator_h__
#define nsCacheIterator_h__
#include "nsIterator.h"
#include "prtypes.h"
#include "nsCacheModule.h"
class nsCacheIterator: public nsIterator
{
public:
nsCacheIterator(nsCacheModule* i_pModule);
virtual ~nsCacheIterator();
virtual PRBool IsDone(void) const;
virtual nsCacheObject* Current(void) const;
private:
nsCacheIterator(const nsCacheIterator& o);
nsCacheIterator& operator=(const nsCacheIterator& o);
nsCacheModule* m_pModule;
};
inline
nsCacheIterator::nsCacheIterator(nsCacheModule* i_pModule): m_pModule(i_pModule)
{
}
inline
nsCacheIterator::~nsCacheIterator()
{
}
inline
PRBool nsCacheIterator::IsDone(void) const
{
if (m_pModule)
{
return m_pModule->Entries() <= m_Index;
}
else
return PR_FALSE;
}
inline
nsCacheObject* nsCacheIterator::Current(void) const
{
if (m_pModule)
{
return m_pModule->GetObject(m_Index);
}
return 0;
}
#endif // nsCacheIterator_h__

View File

@@ -0,0 +1,168 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 _CacheManager_H_
#define _CacheManager_H_
/*
* nsCacheManager
* Design and original implementation
* by Gagan Saksena 02/02/98
*
*/
#if 0
# include "nsISupports.h"
#endif
#include "prlog.h"
#include "nsMonitorable.h"
#include "nsCacheModule.h"
#include "nsCacheObject.h"
class nsMemModule;
class nsDiskModule;
class nsCachePref;
class nsCacheBkgThd;
class nsCacheManager : public nsMonitorable //: public nsISupports
{
public:
//Reserved modules
enum modules
{
MEM =0,
DISK=1
};
nsCacheManager();
~nsCacheManager();
PRInt32 AddModule(nsCacheModule* i_cacheModule);
// InsertModule
PRBool Contains(const char* i_url) const;
/* Number of modules in the cache manager */
PRInt16 Entries() const;
/* Singleton */
static nsCacheManager* GetInstance();
nsCacheObject* GetObj(const char* i_url) const;
nsCacheModule* GetModule(PRInt16 i_index) const;
nsMemModule* GetMemModule() const;
nsDiskModule* GetDiskModule() const;
PRBool IsOffline(void) const;
void Offline(PRBool bSet);
PRBool Remove(const char* i_url);
const char* Trace() const;
/* Performance measure- microseconds */
PRUint32 WorstCaseTime(void) const;
protected:
PRBool ContainsExactly(const char* i_url) const;
void Init();
nsCacheModule* LastModule() const;
//PRBool Lock(void);
//void Unlock(void);
/*
class MgrMonitor
{
public:
MgrMonitor() { nsCacheManager::GetInstance()->Lock();}
~MgrMonitor() { nsCacheManager::GetInstance()->Unlock();}
};
friend MgrMonitor;
*/
private:
nsCacheModule* m_pFirstModule;
PRMonitor* m_pMonitor;
nsCacheManager(const nsCacheManager& cm);
nsCacheManager& operator=(const nsCacheManager& cm);
nsCacheBkgThd* m_pBkgThd;
PRBool m_bOffline;
};
inline
nsDiskModule* nsCacheManager::GetDiskModule() const
{
PR_ASSERT(m_pFirstModule && m_pFirstModule->NextModule());
return (m_pFirstModule) ? (nsDiskModule*) m_pFirstModule->NextModule() : NULL;
}
inline
nsMemModule* nsCacheManager::GetMemModule() const
{
PR_ASSERT(m_pFirstModule);
return (nsMemModule*) m_pFirstModule;
}
inline
PRBool nsCacheManager::IsOffline(void) const
{
return m_bOffline;
}
/*
inline
PRBool nsCacheManager::Lock(void)
{
if (!m_pMonitor)
{
m_pMonitor = PR_NewMonitor();
if (!m_pMonitor)
return PR_FALSE;
}
PR_EnterMonitor(m_pMonitor);
return PR_TRUE;
}
*/
inline
void nsCacheManager::Offline(PRBool i_bSet)
{
m_bOffline = i_bSet;
}
/*
inline
void nsCacheManager::Unlock(void)
{
PR_ASSERT(m_pMonitor);
if (m_pMonitor)
PR_ExitMonitor(m_pMonitor);
}
*/
#endif

View File

@@ -0,0 +1,194 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 nsCacheModule_h__
#define nsCacheModule_h__
/*
* nsCacheModule
*
* Gagan Saksena 02/03/98
*
*/
//#include <nsISupports.h>
#include "nsCacheObject.h"
#include "nsEnumeration.h"
#include "nsMonitorable.h"
/* Why in the world is forward decl. not working? */
//class nsCacheObject;
/*
// {5D51B24F-E6C2-11d1-AFE5-006097BFC036}
static const NS_CACHEMODULE_ID =
{ 0x5d51b24f, 0xe6c2, 0x11d1, { 0xaf, 0xe5, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
*/
class nsCacheIterator;
class nsCacheModule : public nsMonitorable /*: public nsISupports */
{
public:
nsCacheModule(const PRUint32 i_size /*= DEFAULT_SIZE */);
virtual
~nsCacheModule();
virtual
PRBool AddObject(nsCacheObject* i_pObject)=0;
virtual
PRBool Contains(const char* i_url) const=0;
virtual
PRBool Contains(nsCacheObject* i_pObject) const=0;
void Enable(PRBool i_Enable);
const PRUint32 Entries(void) const;
nsEnumeration* Enumeration(void) const;
/* Enumerations wiht a function pointer - TODO */
//TODO move to own interface for both Garbage Collection and Revalidation
virtual
void GarbageCollect(void);
virtual
nsCacheObject* GetObject(const char* i_url) const=0;
virtual
nsCacheObject* GetObject(const PRUint32 i_index) const =0;
virtual
nsStream* GetStreamFor(const nsCacheObject* i_pObject)=0;
PRBool IsEnabled(void) const;
/* Cant do additions, deletions, validations, expirations */
PRBool IsReadOnly(void) const;
nsCacheModule* NextModule(void) const;
void NextModule(nsCacheModule*);
virtual
PRBool Remove(const char* i_url) = 0;
virtual
PRBool Remove(const PRUint32 i_index) = 0;
virtual
PRBool RemoveAll(void);
virtual
PRBool Revalidate(void) = 0;
const PRUint32 Size(void) const;
virtual
void SetSize(const PRUint32 i_size);
PRUint32 SizeInUse(void) const;
const char* Trace(void) const;
protected:
virtual
PRBool ReduceSizeTo(const PRUint32 i_NewSize);
PRUint32 m_Entries;
PRUint32 m_Size;
PRUint32 m_SizeInUse;
PRBool m_Enabled;
nsEnumeration* m_pEnumeration;
nsCacheIterator* m_pIterator;
nsCacheModule* m_pNext;
private:
nsCacheModule(const nsCacheModule& cm);
nsCacheModule& operator=(const nsCacheModule& cm);
};
inline void nsCacheModule::Enable(PRBool i_Enable)
{
m_Enabled = i_Enable;
}
inline const PRUint32 nsCacheModule::Entries() const
{
return m_Entries;
}
inline
nsEnumeration* nsCacheModule::Enumeration(void) const
{
MonitorLocker ml((nsMonitorable*)this);
if (!m_pEnumeration)
{
PR_ASSERT(m_pIterator);
((nsCacheModule*)this)->m_pEnumeration = new nsEnumeration((nsIterator*)m_pIterator);
}
else
((nsCacheModule*)this)->m_pEnumeration->Reset();
return m_pEnumeration;
}
inline PRBool nsCacheModule::IsEnabled(void) const
{
return m_Enabled;
}
inline PRBool nsCacheModule::IsReadOnly(void) const
{
return PR_FALSE;
}
inline nsCacheModule* nsCacheModule::NextModule(void) const
{
return m_pNext;
}
inline void nsCacheModule::NextModule(nsCacheModule* pNext)
{
/* No overwriting */
PR_ASSERT(m_pNext == 0);
if (m_pNext)
{
/* ERROR */
delete m_pNext; //Worst case.
}
m_pNext = pNext;
}
inline const PRUint32 nsCacheModule::Size() const
{
return m_Size;
}
inline void nsCacheModule::SetSize(const PRUint32 size)
{
m_Size = size;
}
inline PRUint32 nsCacheModule::SizeInUse(void) const
{
return m_SizeInUse;
}
#endif // nsCacheModule_h__

View File

@@ -0,0 +1,288 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 nsCacheObject_h__
#define nsCacheObject_h__
#if 0
#include "nsISupports.h"
#endif
#include "prtypes.h"
#include "prinrval.h"
static const PRUint32 kCACHE_VERSION = 5;
class nsStream;
class nsCacheObject //: public nsISupports
{
public:
enum state_flags
{
INIT=0x000000,
PARTIAL=0x000001
};
nsCacheObject();
nsCacheObject(const nsCacheObject& another);
nsCacheObject(const char* i_url);
virtual ~nsCacheObject();
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
void Address(const char* i_url);
const char* Address(void) const;
void Charset(const char* i_Charset);
const char* Charset(void) const;
void ContentEncoding(const char* i_Encoding);
const char* ContentEncoding(void) const;
void ContentLength(PRUint32 i_len);
PRUint32 ContentLength(void) const;
void ContentType(const char* i_Type);
const char* ContentType(void) const;
void Etag(const char* i_etag);
const char* Etag(void) const;
void Expires(PRIntervalTime i_Expires);
PRIntervalTime Expires(void) const;
void Filename(const char* i_Filename);
const char* Filename(void) const;
PRUint16 Hits(void) const;
/* Read and write info about this cache object */
void* Info(void) const;
PRBool Info(void* /*, PRUint32 len */);
PRUint32 InfoSize(void) const;
PRBool IsExpired(void) const;
PRBool IsPartial(void) const;
PRIntervalTime LastAccessed(void) const;
PRIntervalTime LastModified(void) const;
void LastModified(const PRIntervalTime i_lastModified);
PRInt16 Module(void) const;
void Module(PRUint16 i_m);
void PageServicesURL(const char* i_Url);
const char* PageServicesURL(void) const;
const char* PostData(void) const;
void PostData(const char* i_data, const PRUint32 i_Len);
PRUint32 PostDataLen(void) const;
PRUint32 Read(char* o_Buffer, PRUint32 len);
PRUint32 Size(void) const;
void Size(PRUint32 i_Size);
const char* Trace() const;
PRUint32 Write(const char* i_Buffer, const PRUint32 len);
protected:
void Init();
char* m_Charset;
char* m_ContentEncoding;
PRUint32 m_ContentLength;
char* m_ContentType;
char* m_Etag;
PRIntervalTime m_Expires;
int m_Flags;
char* m_Filename;
PRUint16 m_Hits;
PRUint32 m_info_size;
PRIntervalTime m_LastAccessed, m_LastModified;
void* m_pInfo;
char* m_PageServicesURL;
char* m_PostData;
PRUint32 m_PostDataLen;
PRInt16 m_Module;
PRUint32 m_Size;
nsStream* m_pStream;
char* m_URL;
private:
nsCacheObject& operator=(const nsCacheObject& x);
};
inline
const char* nsCacheObject::Address(void) const
{
return m_URL;
};
inline
const char* nsCacheObject::Charset(void) const
{
return m_Charset;
}
inline
const char* nsCacheObject::ContentEncoding(void) const
{
return m_ContentEncoding;
}
inline
PRUint32 nsCacheObject::ContentLength(void) const
{
return m_ContentLength;
};
inline
void nsCacheObject::ContentLength(PRUint32 i_Size)
{
m_ContentLength = i_Size;
};
inline
const char* nsCacheObject::ContentType(void) const
{
return m_ContentType;
};
inline
const char* nsCacheObject::Etag(void) const
{
return m_Etag;
};
inline
PRIntervalTime nsCacheObject::Expires(void) const
{
return m_Expires;
};
inline
void nsCacheObject::Expires(PRIntervalTime i_Expires)
{
m_Expires = i_Expires;
};
inline
const char* nsCacheObject::Filename(void) const
{
return m_Filename;
}
inline
PRUint16 nsCacheObject::Hits(void) const
{
return m_Hits;
};
inline
PRBool nsCacheObject::IsExpired(void) const
{
PRIntervalTime now = PR_IntervalNow();
return (m_Expires <= now);
};
inline
PRBool nsCacheObject::IsPartial(void) const
{
return (m_Flags & nsCacheObject::PARTIAL);
};
inline
PRIntervalTime nsCacheObject::LastAccessed(void) const
{
return m_LastAccessed;
};
inline
PRIntervalTime nsCacheObject::LastModified(void) const
{
return m_LastModified;
};
inline
void nsCacheObject::LastModified(const PRIntervalTime i_LastModified)
{
m_LastModified = i_LastModified;
};
inline
PRInt16 nsCacheObject::Module(void) const
{
return m_Module;
};
inline
void nsCacheObject::Module(PRUint16 i_Module)
{
m_Module = i_Module;
};
inline
const char* nsCacheObject::PageServicesURL(void) const
{
return m_PageServicesURL;
}
inline
const char* nsCacheObject::PostData(void) const
{
return m_PostData;
}
inline
PRUint32 nsCacheObject::PostDataLen(void) const
{
return m_PostDataLen;
}
inline
PRUint32 nsCacheObject::Size(void) const
{
return m_Size;
};
inline
void nsCacheObject::Size(PRUint32 i_Size)
{
m_Size = i_Size;
};
#endif // nsCacheObject_h__

View File

@@ -0,0 +1,84 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 nsCachePref_h__
#define nsCachePref_h__
//#include "nsISupports.h"
#include "prtypes.h"
class nsCachePref //: public nsISupports
{
public:
static nsCachePref* GetInstance(void);
nsCachePref(void);
~nsCachePref();
enum Refresh
{
NEVER,
ONCE,
ALWAYS
} r;
const PRUint32 BkgSleepTime(void);
const char* DiskCacheDBFilename(void); /* like Fat.db */
const char* DiskCacheFolder(void); /* Cache dir */
PRBool DiskCacheSSL(void);
void DiskCacheSSL(PRBool bSet);
PRUint32 DiskCacheSize(void);
void DiskCacheSize(const PRUint32 i_Size);
PRUint32 MemCacheSize(void);
void MemCacheSize(const PRUint32 i_Size);
nsCachePref::Refresh
Frequency(void);
/* Revalidating in background, makes IMS calls in the bkg thread to
update cache entries. TODO, this should be at a bigger time period
than the cache cleanup routine */
PRBool RevalidateInBkg(void);
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
private:
nsCachePref(const nsCachePref& o);
nsCachePref& operator=(const nsCachePref& o);
PRBool m_bRevalidateInBkg;
PRBool m_bDiskCacheSSL;
nsCachePref::Refresh m_RefreshFreq;
PRUint32 m_MemCacheSize;
PRUint32 m_DiskCacheSize;
char* m_DiskCacheDBFilename;
char* m_DiskCacheFolder;
PRUint32 m_BkgSleepTime;
};
#endif // nsCachePref_h__

View File

@@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 _nsDiskModule_H_
#define _nsDiskModule_H_
/*
* nsDiskModule
*
* Gagan Saksena 02/03/98
*
*/
#include "nsCacheModule.h"
#include "nsCachePref.h"
#include "mcom_db.h"
class nsDiskModule : public nsCacheModule
{
public:
nsDiskModule(const PRUint32 size = nsCachePref::GetInstance()->DiskCacheSize());
~nsDiskModule();
// Cache module interface
PRBool AddObject(nsCacheObject* io_pObject);
PRBool Contains(nsCacheObject* io_pObject) const;
PRBool Contains(const char* i_url) const;
void GarbageCollect(void);
nsCacheObject* GetObject(const PRUint32 i_index) const;
nsCacheObject* GetObject(const char* i_url) const;
nsStream* GetStreamFor(const nsCacheObject* i_pObject)=0;
PRBool ReduceSizeTo(const PRUint32 i_NewSize);
PRBool Remove(const char* i_url);
PRBool Remove(const PRUint32 i_index);
// To do cleanup set size to zero. Else initialize disk cache
void SetSize(const PRUint32 i_size);
PRBool Revalidate(void);
private:
enum sync_frequency
{
EVERYTIME,
IDLE,
NEVER
} m_Sync;
PRBool InitDB(void);
nsDiskModule(const nsDiskModule& dm);
nsDiskModule& operator=(const nsDiskModule& dm);
DB* m_pDB;
};
#endif

View File

@@ -0,0 +1,93 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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.
*
* 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.
*/
#ifndef nsEnumeration_h__
#define nsEnumeration_h__
//#include "nsISupports.h"
#include "nsIterator.h"
#include "prlog.h"
class nsEnumeration //: public nsISupports
{
public:
nsEnumeration(nsIterator* iter);
virtual ~nsEnumeration();
PRBool HasMoreElements(void);
void* NextElement(void);
void Reset(void);
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
protected:
nsIterator* m_pIter;
private:
nsEnumeration(const nsEnumeration& o);
nsEnumeration& operator=(const nsEnumeration& o);
};
inline
nsEnumeration::nsEnumeration(nsIterator* iter):m_pIter(iter)
{
PR_ASSERT(iter);
if (m_pIter)
m_pIter->First();
}
inline
nsEnumeration::~nsEnumeration()
{
}
inline
PRBool nsEnumeration::HasMoreElements(void)
{
if (m_pIter) //remove this check for optimization?
return m_pIter->IsDone() ? PR_FALSE : PR_TRUE;
return PR_FALSE;
}
inline
void* nsEnumeration::NextElement(void)
{
if (m_pIter)
{
void* pTemp = m_pIter->CurrentItem();
m_pIter->Next();
return pTemp;
}
return 0;
}
inline
void nsEnumeration::Reset(void)
{
if (m_pIter)
{
m_pIter->First();
}
}
#endif // nsEnumeration_h__

View File

@@ -0,0 +1,52 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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.
*
* 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.
*/
#ifndef nsFileStream_h__
#define nsFileStream_h__
//#include "nsISupports.h"
#include "nsStream.h"
#include "xp.h" // Reqd. for xp_file.h
#include "xp_file.h" // Cuz we don't have a better choice, as yet
class nsFileStream: public nsStream
{
public:
nsFileStream(XP_File* i_pFile);
virtual ~nsFileStream();
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
PRInt32 Read(void* o_Buffer, PRUint32 i_Len);
PRInt32 Write(const void* i_Buffer, PRUint32 i_Len);
protected:
private:
nsFileStream(const nsFileStream& o);
nsFileStream& operator=(const nsFileStream& o);
XP_File* m_pFile;
};
#endif // nsFileStream_h__

View File

@@ -0,0 +1,53 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* 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 nsHash_h__
#define nsHash_h__
#include "plhash.h"
class nsHashKey {
protected:
nsHashKey(void);
public:
virtual ~nsHashKey(void);
virtual PRUint32 HashValue(void) const = 0;
virtual PRBool Equals(const nsHashKey *aKey) const = 0;
virtual nsHashKey *Clone(void) const = 0;
};
// Enumerator callback function. Use
typedef PRBool (*nsHashEnumFunc)(nsHashKey *aKey, void *aData);
class nsHash {
private:
// members
PLHashTable *hashtable;
public:
nsHash(PRUint32 aSize = 256);
~nsHash();
void *Put(nsHashKey *aKey, void *aData);
void *Get(nsHashKey *aKey);
void *Remove(nsHashKey *aKey);
void Enumerate(nsHashEnumFunc aEnumFunc);
};
#endif

View File

@@ -0,0 +1,67 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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.
*
* 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.
*/
#ifndef nsIterator_h__
#define nsIterator_h__
//#include "nsISupports.h"
#include "prtypes.h"
class nsIterator //:public nsISupports
{
public:
virtual void First(void);
virtual PRBool IsDone(void) const = 0;
virtual void Next(void);
virtual void* CurrentItem(void) const;
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
protected:
nsIterator() {m_Index = 0;};
PRUint32 m_Index;
};
inline
void nsIterator::First(void)
{
m_Index = 0;
}
inline
void nsIterator::Next(void)
{
++m_Index;
}
inline
void* nsIterator::CurrentItem(void) const
{
return 0;
}
#endif // nsIterator_h__

View File

@@ -0,0 +1,101 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 _nsMemCacheObject_h_
#define _nsMemCacheObject_h_
#include "prtypes.h"
#include "nsCacheObject.h"
class nsMemCacheObject
{
public:
nsMemCacheObject(void);
nsMemCacheObject(nsCacheObject* io_pObject);
nsMemCacheObject(const char* i_url);
~nsMemCacheObject();
void* Data(void) const;
void Next(nsMemCacheObject* pObject);
void Next(nsCacheObject* io_pObject);
nsMemCacheObject* Next(void) const;
nsCacheObject* ThisObject(void) const;
private:
nsMemCacheObject* m_pNextObject;
nsCacheObject* m_pObject;
void* m_pData;
nsMemCacheObject& operator=(const nsMemCacheObject& mco);
nsMemCacheObject(const nsMemCacheObject&);
};
inline nsMemCacheObject::nsMemCacheObject(void):
m_pObject(new nsCacheObject()),
m_pNextObject(0),
m_pData(0)
{
}
inline nsMemCacheObject::nsMemCacheObject(nsCacheObject* io_pObject):
m_pObject(io_pObject),
m_pNextObject(0),
m_pData(0)
{
}
inline nsMemCacheObject::nsMemCacheObject(const char* i_url):
m_pObject(new nsCacheObject(i_url)),
m_pNextObject(0),
m_pData(0)
{
}
inline void* nsMemCacheObject::Data(void) const
{
// PR_ASSERT(m_pData);
return m_pData;
}
inline nsMemCacheObject* nsMemCacheObject::Next(void) const
{
return m_pNextObject;
}
inline void nsMemCacheObject::Next(nsMemCacheObject* pObject)
{
m_pNextObject = pObject;
}
inline void nsMemCacheObject::Next(nsCacheObject* pObject)
{
m_pNextObject = new nsMemCacheObject(pObject);
}
inline nsCacheObject* nsMemCacheObject::ThisObject(void) const
{
return m_pObject;
}
#endif //_nsMemCacheObject_h_

View File

@@ -0,0 +1,112 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 _nsMemModule_H_
#define _nsMemModule_H_
/*
* nsMemModule
*
* Gagan Saksena
* 02/03/98
*
*/
#include "nsCacheModule.h"
#include "nsMemCacheObject.h"
#include "nsCachePref.h"
//#include "nsHash.h" // TODO - replace with nsHashtable when the XPCOM_BRANCH merges
//#include "nsHashtable.h"
/*
// {5D51B250-E6C2-11d1-AFE5-006097BFC036}
static const NS_MEMMODULE_IID =
{ 0x5d51b250, 0xe6c2, 0x11d1, { 0xaf, 0xe5, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
*/
class nsMemModule : public nsCacheModule
{
public:
nsMemModule(const PRUint32 size=nsCachePref::GetInstance()->MemCacheSize());
~nsMemModule();
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
PRBool AddObject(nsCacheObject* io_pObject);
PRBool Contains(nsCacheObject* io_pObject) const;
PRBool Contains(const char* i_url) const;
void GarbageCollect(void);
nsCacheObject* GetObject(const PRUint32 i_index) const;
nsCacheObject* GetObject(const char* i_url) const;
nsStream* GetStreamFor(const nsCacheObject* i_pObject);
PRBool ReduceSizeTo(const PRUint32 i_NewSize);
PRBool Remove(const char* i_url);
PRBool Remove(const PRUint32 i_index);
// PRBool RemoveAll(void);
PRBool Revalidate(void);
// Start of nsMemModule specific stuff...
// Here is a sample implementation using linked list
protected:
nsMemCacheObject* LastObject(void) const;
private:
nsMemCacheObject* m_pFirstObject;
//nsHash m_ht; //TODO replace with nsHashtable
//Optimization
nsMemCacheObject* m_pLastObject;
nsMemModule(const nsMemModule& mm);
nsMemModule& operator=(const nsMemModule& mm);
/*
class nsMemKey : public nsHashKey
{
public:
nsMemKey();
~nsMemKey();
PRUint32 HashValue();
PRBool Equals(nsHashKey *aKey);
nsHashKey* Clone();
};
*/
};
inline
PRBool nsMemModule::Revalidate(void)
{
/* Mem module elements are never revalidated */
return PR_FALSE;
}
#endif

View File

@@ -0,0 +1,52 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this Mem are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this Mem 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.
*
* 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.
*/
#ifndef nsMemStream_h__
#define nsMemStream_h__
//#include "nsISupports.h"
#include "nsStream.h"
class nsMemStream: public nsStream
{
public:
nsMemStream();
virtual ~nsMemStream();
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
PRInt32 Read(void* o_Buffer, PRUint32 i_Len);
PRInt32 Write(const void* i_Buffer, PRUint32 i_Len);
protected:
private:
nsMemStream(const nsMemStream& o);
nsMemStream& operator=(const nsMemStream& o);
void* m_pCurrent;
void* m_pStart;
PRUint32 m_Size;
};
#endif // nsMemStream_h__

View File

@@ -0,0 +1,106 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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.
*
* 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.
*/
#ifndef nsMonitorable_h__
#define nsMonitorable_h__
//#include "nsISupports.h"
#include "prmon.h"
class nsMonitorable//: public nsISupports
{
public:
nsMonitorable();
virtual ~nsMonitorable();
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
PRBool Lock(void);
void Unlock(void);
protected:
class MonitorLocker
{
public:
MonitorLocker(nsMonitorable* i_pThis):
m_pMonitorable(i_pThis)
{
if (m_pMonitorable) m_pMonitorable->Lock();
}
~MonitorLocker()
{
if (m_pMonitorable) m_pMonitorable->Unlock();
}
private:
nsMonitorable* m_pMonitorable;
};
PRMonitor* m_pMonitor;
private:
nsMonitorable(const nsMonitorable& o);
nsMonitorable& operator=(const nsMonitorable& o);
};
inline
nsMonitorable::nsMonitorable(void):m_pMonitor(PR_NewMonitor())
{
}
inline
nsMonitorable::~nsMonitorable()
{
if (m_pMonitor)
{
PR_DestroyMonitor(m_pMonitor);
m_pMonitor = 0;
}
}
inline
PRBool nsMonitorable::Lock(void)
{
if (!m_pMonitor)
{
m_pMonitor = PR_NewMonitor();
if (!m_pMonitor)
return PR_FALSE;
}
PR_EnterMonitor(m_pMonitor);
return PR_TRUE;
}
inline
void nsMonitorable::Unlock(void)
{
PR_ASSERT(m_pMonitor);
if (m_pMonitor)
PR_ExitMonitor(m_pMonitor);
}
#endif // nsMonitorable_h__

View File

@@ -0,0 +1,51 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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.
*
* 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.
*/
#ifndef nsStream_h__
#define nsStream_h__
//#include "nsISupports.h"
#include "prtypes.h"
class nsStream//: public nsISupports
{
public:
nsStream();
virtual ~nsStream();
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
virtual
PRInt32 Read(void* o_Buffer, PRUint32 i_Len) = 0;
virtual
PRInt32 Write(const void* i_Buffer, PRUint32 i_Len) = 0;
protected:
private:
nsStream(const nsStream& o);
nsStream& operator=(const nsStream& o);
};
#endif // nsStream_h__

View File

@@ -0,0 +1,493 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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.
*
* 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.
*/
/* Design and original implementation by Gagan Saksena '98 */
#include "CacheStubs.h"
#include "nsCacheManager.h"
#include "nsDiskModule.h"
#include "nsMemModule.h"
#include "nsCacheTrace.h"
#include "prlog.h"
#define CACHEMGR nsCacheManager::GetInstance()
void
Cache_Init(void)
{
/* Most of the initilization gets done in the constructor for the
* nsCacheManager class. */
}
void
Cache_Shutdown(void)
{
/* todo- Should the destructor for nsCacheManager object be forced here?*/
}
/* CacheManager functions */
PRBool
CacheManager_Contains(const char* i_url)
{
return CACHEMGR->Contains(i_url);
}
PRInt16
CacheManager_Entries()
{
return CACHEMGR->Entries();
}
void*
CacheManager_GetObject(const char* i_url)
{
return CACHEMGR->GetObj(i_url);
}
PRBool
CacheManager_IsOffline(void)
{
return CACHEMGR->IsOffline();
}
void
CacheManager_Offline(PRBool bSet)
{
CACHEMGR->Offline(bSet);
}
PRBool
CacheManager_Remove(const char* i_url)
{
return CACHEMGR->Remove(i_url);
}
PRUint32
CacheManager_WorstCaseTime(void)
{
return CACHEMGR->WorstCaseTime();
}
/* CacheObject functions */
void*
CacheObject_Create(const char* i_url)
{
return new nsCacheObject(i_url);
}
const char*
CacheObject_GetAddress(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->Address() : 0;
}
const char*
CacheObject_GetCharset(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->Charset() : 0;
}
const char*
CacheObject_GetContentEncoding(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->ContentEncoding() : 0;
}
PRUint32
CacheObject_GetContentLength(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->ContentLength() : 0;
}
const char*
CacheObject_GetContentType(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->ContentType() : 0;
}
const char*
CacheObject_GetEtag(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->Etag() : 0;
}
PRIntervalTime
CacheObject_GetExpires(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->Expires() : 0;
}
const char*
CacheObject_GetFilename(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->Filename() : 0;
}
PRIntervalTime
CacheObject_GetLastAccessed(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->LastAccessed() : 0;
}
PRIntervalTime
CacheObject_GetLastModified(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->LastModified() : 0;
}
PRInt16
CacheObject_GetModule(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->Module() : -1;
}
const char*
CacheObject_GetPageServicesURL(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->PageServicesURL() : 0;
}
const char*
CacheObject_GetPostData(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->PostData() : 0;
}
PRUint32
CacheObject_GetPostDataLen(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->PostDataLen() : 0;
}
PRUint32
CacheObject_GetSize(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->Size() : 0;
}
PRUint32
CacheObject_Hits(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->Hits() : 0;
}
PRBool
CacheObject_IsExpired(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->IsExpired() : PR_FALSE;
}
PRBool
CacheObject_IsPartial(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->IsPartial() : PR_FALSE;
}
PRUint32
CacheObject_Read(const void* pThis, char* o_Buffer, PRUint32 i_Len)
{
return pThis ? ((nsCacheObject*)pThis)->Read(o_Buffer, i_Len) : 0;
}
void
CacheObject_SetAddress(void* pThis, const char* i_Address)
{
if (pThis)
((nsCacheObject*)pThis)->Address(i_Address);
}
void
CacheObject_SetCharset(void* pThis, const char* i_Charset)
{
if (pThis)
((nsCacheObject*)pThis)->Charset(i_Charset);
}
void
CacheObject_SetContentEncoding(void* pThis, const char* i_Encoding)
{
if (pThis)
((nsCacheObject*)pThis)->ContentEncoding(i_Encoding);
}
void
CacheObject_SetContentLength(void* pThis, PRUint32 i_ContentLen)
{
if (pThis)
((nsCacheObject*)pThis)->ContentLength(i_ContentLen);
}
void
CacheObject_SetContentType(void* pThis, const char* i_ContentType)
{
if (pThis)
((nsCacheObject*)pThis)->ContentType(i_ContentType);
}
void
CacheObject_SetEtag(void* pThis, const char* i_Etag)
{
if (pThis)
((nsCacheObject*)pThis)->Etag(i_Etag);
}
void
CacheObject_SetExpires(void *pThis, const PRIntervalTime i_Time)
{
if (pThis)
((nsCacheObject*)pThis)->Expires(i_Time);
}
void
CacheObject_SetFilename(void* pThis, const char* i_Filename)
{
if (pThis)
((nsCacheObject*)pThis)->Filename(i_Filename);
}
void
CacheObject_SetLastModified(void* pThis, const PRIntervalTime i_Time)
{
if (pThis)
((nsCacheObject*)pThis)->LastModified(i_Time);
}
void
CacheObject_SetModule(void* pThis, const PRInt16 i_Module)
{
if (pThis)
((nsCacheObject*)pThis)->Module(i_Module);
}
void
CacheObject_SetPageServicesURL(void* pThis, const char* i_Url)
{
if (pThis)
((nsCacheObject*)pThis)->PageServicesURL(i_Url);
}
void
CacheObject_SetPostData(void* pThis, const char* i_PostData, const PRUint32 i_Len)
{
if (pThis)
((nsCacheObject*)pThis)->PostData(i_PostData, i_Len);
}
void
CacheObject_SetSize(void* pThis, const PRUint32 i_Size)
{
if (pThis)
((nsCacheObject*)pThis)->Size(i_Size);
}
PRBool
CacheObject_Synch(void* pThis)
{
if (pThis)
{
nsCacheObject* pObj = (nsCacheObject*) pThis;
PRBool bStatus = CACHEMGR->GetModule(pObj->Module())->AddObject(pObj);
return bStatus;
}
return PR_FALSE;
}
PRUint32
CacheObject_Write(void* pThis, const char* i_buffer, const PRUint32 i_length)
{
return i_length;
}
void
CacheObject_Destroy(void* pThis)
{
if (pThis)
{
((nsCacheObject*)pThis)->~nsCacheObject();
pThis = 0;
}
}
/* CachePref functions */
PRUint32
CachePref_GetDiskCacheSize(void)
{
return nsCachePref::GetInstance()->DiskCacheSize();
}
PRBool
CachePref_GetDiskCacheSSL(void)
{
return nsCachePref::GetInstance()->DiskCacheSSL();
}
PRUint32
CachePref_GetMemCacheSize(void)
{
return nsCachePref::GetInstance()->MemCacheSize();
}
void
CachePref_SetDiskCacheSize(const PRUint32 i_Size)
{
nsCachePref::GetInstance()->DiskCacheSize(i_Size);
}
void
CachePref_SetDiskCacheSSL(PRBool bSet)
{
nsCachePref::GetInstance()->DiskCacheSSL(bSet);
}
void
CachePref_SetMemCacheSize(const PRUint32 i_Size)
{
nsCachePref::GetInstance()->MemCacheSize(i_Size);
}
/* CacheTrace functions */
void
CacheTrace_Enable(PRBool bEnable)
{
nsCacheTrace::Enable(bEnable);
}
PRBool
CacheTrace_IsEnabled(void)
{
return nsCacheTrace::IsEnabled();
}
/* DiskModule functions */
#define DISKMOD nsCacheManager::GetInstance()->GetDiskModule()
PRBool
DiskModule_AddObject(void* pObject)
{
return DISKMOD->AddObject((nsCacheObject*)pObject);
}
PRBool
DiskModule_Contains(const char* i_url)
{
return DISKMOD->Contains(i_url);
}
PRUint32
DiskModule_Entries(void)
{
return DISKMOD->Entries();
}
PRUint32
DiskModule_GetSize(void)
{
return DISKMOD->Size();
}
PRUint32
DiskModule_GetSizeInUse(void)
{
return DISKMOD->SizeInUse();
}
PRBool
DiskModule_IsEnabled(void)
{
return DISKMOD->IsEnabled();
}
PRBool
DiskModule_Remove(const char* i_url)
{
return DISKMOD->Remove(i_url);
}
PRBool
DiskModule_RemoveAll(void)
{
return DISKMOD->RemoveAll();
}
void
DiskModule_SetSize(PRUint32 i_Size)
{
DISKMOD->SetSize(i_Size);
}
/* MemModule functions */
#define MEMMOD nsCacheManager::GetInstance()->GetMemModule()
PRBool
MemModule_AddObject(void* pObject)
{
return MEMMOD->AddObject((nsCacheObject*)pObject);
}
PRBool
MemModule_Contains(const char* i_url)
{
return MEMMOD->Contains(i_url);
}
PRUint32
MemModule_Entries(void)
{
return MEMMOD->Entries();
}
PRUint32
MemModule_GetSize(void)
{
return MEMMOD->Size();
}
PRUint32
MemModule_GetSizeInUse(void)
{
return MEMMOD->SizeInUse() ;
}
PRBool
MemModule_IsEnabled(void)
{
return MEMMOD->IsEnabled();
}
PRBool
MemModule_Remove(const char* i_url)
{
return MEMMOD->Remove(i_url);
}
PRBool
MemModule_RemoveAll(void)
{
return MEMMOD->RemoveAll();
}
void
MemModule_SetSize(PRUint32 i_Size)
{
MEMMOD->SetSize(i_Size);
}
#undef MEMMOD
#undef DISKMOD
#undef CACHEMGR

62
mozilla/network/cache/nu/src/Makefile vendored Normal file
View File

@@ -0,0 +1,62 @@
#!gmake
#
# 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.
DEPTH=../../../..
TARGET = $(LIBRARY)
LIBRARY_NAME=cachelib
MISCDEP = \
$(LIBNSPR) \
$(DIST)/lib/dbm32.lib \
$(DIST)/lib/libplc21.lib \
$(DIST)/lib/xpcom32.lib \
$(NULL)
MODULE = cache
CPPSRCS = nsCacheObject.cpp \
nsCacheModule.cpp \
nsCacheManager.cpp \
nsMemModule.cpp \
nsDiskModule.cpp \
nsCacheTrace.cpp \
nsCachePref.cpp \
nsMemCacheObject.cpp \
nsBkgThread.cpp \
nsCacheBkgThd.cpp \
CacheStubs.cpp \
nsFileStream.cpp \
nsMemStream.cpp \
$(NULL)
REQUIRES = dbm nspr pref xpcom
LLIBS = \
$(DIST)/lib/dbm32.lib \
$(DIST)/lib/libplc21.lib \
$(DIST)/lib/xpcom32.lib \
$(LIBNSPR) \
$(NULL)
include $(DEPTH)/config/rules.mk
INCLUDES += -I../include \
-I../public \
$(NULL)

View File

@@ -0,0 +1,81 @@
#!gmake
#
# 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.
IGNORE_MANIFEST = 1
DEPTH=..\..\..\..
MAKE_OBJ_TYPE = EXE
DLLNAME = cachelib
#DLL = .\$(OBJDIR)\$(DLLNAME).dll
LIBRARY_NAME=cachelib
#
# Remember to change libplc21 to $whatever it is...
#
LLIBS = \
$(LIBNSPR) \
$(DIST)\lib\libplc21.lib \
$(DIST)\lib\dbm32.lib \
$(DIST)\lib\xpcom32.lib \
$(NULL)
MISCDEP = $(LLIBS)
MODULE = cache
OBJS = \
.\$(OBJDIR)\nsCacheObject.obj \
.\$(OBJDIR)\nsCacheModule.obj \
.\$(OBJDIR)\nsMemModule.obj \
.\$(OBJDIR)\nsDiskModule.obj \
.\$(OBJDIR)\nsCacheTrace.obj \
.\$(OBJDIR)\nsCacheManager.obj \
.\$(OBJDIR)\nsCachePref.obj \
.\$(OBJDIR)\nsMemCacheObject.obj \
.\$(OBJDIR)\nsBkgThread.obj \
.\$(OBJDIR)\nsCacheBkgThd.obj \
.\$(OBJDIR)\CacheStubs.obj \
.\$(OBJDIR)\nsFileStream.obj \
.\$(OBJDIR)\nsMemStream.obj \
$(NULL)
# .\$(OBJDIR)\nsHash.obj \
LINCS = \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\dbm \
-I$(PUBLIC)\pref \
-I..\public \
-I..\include \
$(NULL)
LCFLAGS = \
$(LCFLAGS) \
$(NULL)
#-DNS_DLLNAME=$(DLLNAME).dll \
include <$(DEPTH)\config\rules.mak>
install:: $(EXE)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).$(LIB_SUFFIX) $(DIST)\lib
# $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).$(DLL_SUFFIX) $(DIST)\bin
clobber::
rm -f $(DIST)\lib\$(DLLNAME).$(LIB_SUFFIX)

View File

@@ -0,0 +1,92 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 "nsBkgThread.h"
#include "prlog.h"
static void PR_CALLBACK RunFunction(void* arg);
static void PR_CALLBACK RunFunction(void* arg)
{
nsBkgThread* pBT = (nsBkgThread*) arg;
if (pBT)
{
pBT->Process();
}
}
nsBkgThread::nsBkgThread(PRIntervalTime iSleepTime, PRBool bStart /* =PR_TRUE */)
{
m_SleepTime = iSleepTime;
m_bContinue = bStart;
m_pThread = PR_CreateThread(
PR_USER_THREAD,
RunFunction,
this,
PR_PRIORITY_NORMAL,
PR_LOCAL_THREAD,
PR_JOINABLE_THREAD,
0);
PR_ASSERT(NULL != m_pThread);
}
nsBkgThread::~nsBkgThread()
{
m_bContinue = PR_FALSE;
if (m_pThread != NULL)
{
Stop();
}
}
/*
nsrefcnt nsBkgThread::AddRef(void)
{
return ++m_RefCnt;
}
nsrefcnt nsBkgThread::Release(void)
{
if (--m_RefCnt == 0)
{
delete this;
return 0;
}
return m_RefCnt;
}
nsresult nsBkgThread::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
return NS_OK;
}
*/
void nsBkgThread::Process(void)
{
while (m_bContinue)
{
PR_Sleep(m_SleepTime);
Run();
}
}
void nsBkgThread::Stop(void)
{
m_bContinue = PR_FALSE;
PRStatus status = PR_Interrupt(m_pThread);
PR_ASSERT(PR_SUCCESS == status);
}

View File

@@ -0,0 +1,78 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 "prlog.h"
#include "nsCacheBkgThd.h"
#include "nsCacheManager.h"
#include "nsCacheModule.h"
#include "nsCachePref.h"
nsCacheBkgThd::nsCacheBkgThd(PRIntervalTime iSleepTime):
nsBkgThread(iSleepTime)
{
}
nsCacheBkgThd::~nsCacheBkgThd()
{
}
/*
nsrefcnt nsCacheBkgThd::AddRef(void)
{
return ++m_RefCnt;
}
nsrefcnt nsCacheBkgThd::Release(void)
{
if (--m_RefCnt == 0)
{
delete this;
return 0;
}
return m_RefCnt;
}
nsresult nsCacheBkgThd::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
return NS_OK;
}
*/
void nsCacheBkgThd::Run(void)
{
/* Step thru all the modules and call cleanup on each */
nsCacheManager* pCM = nsCacheManager::GetInstance();
PR_ASSERT(pCM);
if (pCM->IsOffline())
return; /* Dont update entries if offline */
PRInt16 i = pCM->Entries();
while (i>0)
{
nsCacheModule* pModule = pCM->GetModule(--i);
PR_ASSERT(pModule);
/* TODO change this based on if it supports garbage cleaning */
if (!pModule->IsReadOnly())
{
pModule->GarbageCollect();
if (nsCachePref::GetInstance()->RevalidateInBkg())
{
pModule->Revalidate();
}
}
}
}

View File

@@ -0,0 +1,249 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
/*
* Gagan Saksena 02/02/98
*
*/
#include "prtypes.h"
#include "prinrval.h"
#include "nsCacheManager.h"
#include "nsCacheTrace.h"
#include "nsCachePref.h"
#include "nsCacheModule.h"
#include "nsMemModule.h"
#include "nsDiskModule.h"
#include "nsCacheBkgThd.h"
/* TODO move this to InitNetLib */
static nsCacheManager TheManager;
nsCacheManager::nsCacheManager(): m_pFirstModule(0), m_bOffline(PR_FALSE)
{
Init();
}
nsCacheManager::~nsCacheManager()
{
if (m_pBkgThd)
{
m_pBkgThd->Stop();
delete m_pBkgThd;
m_pBkgThd = 0;
}
if (m_pFirstModule)
{
delete m_pFirstModule;
m_pFirstModule = 0;
}
}
nsCacheManager*
nsCacheManager::GetInstance()
{
return &TheManager;
}
#if 0
/* Caller must free returned char* */
const char*
nsCacheManager::Trace() const
{
char linebuffer[128];
char* total;
sprintf(linebuffer, "nsCacheManager: Modules = %d\n", Entries());
total = new char[strlen(linebuffer) + 1];
strcpy(total, linebuffer);
return total;
}
#endif
PRInt32
nsCacheManager::AddModule(nsCacheModule* pModule)
{
MonitorLocker ml(this);
if (pModule)
{
if (m_pFirstModule)
LastModule()->NextModule(pModule);
else
m_pFirstModule = pModule;
return Entries()-1;
}
else
return -1;
}
PRBool
nsCacheManager::Contains(const char* i_url) const
{
MonitorLocker ml((nsMonitorable*)this);
// Add logic to check for IMAP type URLs, byteranges, and search with / appended as well...
// TODO
PRBool bStatus = ContainsExactly(i_url);
if (!bStatus)
{
// try alternate stuff
/*
char* extraBytes;
char extraBytesSeparator;
*/
}
return bStatus;
}
PRBool
nsCacheManager::ContainsExactly(const char* i_url) const
{
if (m_pFirstModule)
{
nsCacheModule* pModule = m_pFirstModule;
while (pModule)
{
if (pModule->Contains(i_url))
{
return PR_TRUE;
}
pModule = pModule->NextModule();
}
}
return PR_FALSE;
}
nsCacheObject*
nsCacheManager::GetObj(const char* i_url) const
{
MonitorLocker ml((nsMonitorable*)this);
if (m_pFirstModule)
{
nsCacheModule* pModule = m_pFirstModule;
nsCacheObject* obj = 0;
while (pModule)
{
obj = pModule->GetObject(i_url);
if (obj)
return obj;
pModule = pModule->NextModule();
}
}
return 0;
}
PRInt16
nsCacheManager::Entries() const
{
MonitorLocker ml((nsMonitorable*)this);
if (m_pFirstModule)
{
PRInt16 count=1;
nsCacheModule* pModule = m_pFirstModule;
while (pModule = pModule->NextModule())
{
count++;
}
return count;
}
return 0;
}
nsCacheModule*
nsCacheManager::GetModule(PRInt16 i_index) const
{
MonitorLocker ml((nsMonitorable*)this);
if ((i_index < 0) || (i_index >= Entries()))
return 0;
nsCacheModule* pModule = m_pFirstModule;
PR_ASSERT(pModule);
for (PRInt16 i=0; i<i_index; pModule = pModule->NextModule())
{
i++;
PR_ASSERT(pModule);
}
return pModule;
}
void
nsCacheManager::Init()
{
MonitorLocker ml(this);
if (m_pFirstModule)
delete m_pFirstModule;
m_pFirstModule = new nsMemModule(nsCachePref::GetInstance()->MemCacheSize());
PR_ASSERT(m_pFirstModule);
if (m_pFirstModule)
{
nsDiskModule* pTemp = new nsDiskModule(nsCachePref::GetInstance()->DiskCacheSize());
PR_ASSERT(pTemp);
m_pFirstModule->NextModule(pTemp);
m_pBkgThd = new nsCacheBkgThd(PR_SecondsToInterval(nsCachePref::GetInstance()->BkgSleepTime()));
PR_ASSERT(m_pBkgThd);
}
}
nsCacheModule*
nsCacheManager::LastModule() const
{
MonitorLocker ml((nsMonitorable*)this);
if (m_pFirstModule)
{
nsCacheModule* pModule = m_pFirstModule;
while(pModule->NextModule()) {
pModule = pModule->NextModule();
}
return pModule;
}
return 0;
}
PRBool
nsCacheManager::Remove(const char* i_url)
{
MonitorLocker ml(this);
PRBool bStatus = PR_FALSE;
if (m_pFirstModule)
{
nsCacheModule* pModule = m_pFirstModule;
bStatus |= pModule->Remove(i_url);
if (bStatus)
return bStatus;
while(pModule->NextModule()) {
pModule = pModule->NextModule();
if (bStatus)
return bStatus;
}
}
return bStatus;
}
PRUint32
nsCacheManager::WorstCaseTime(void) const
{
PRIntervalTime start = PR_IntervalNow();
if (this->Contains("a vague string that should not be in any of the modules"))
{
PR_ASSERT(0);
}
return PR_IntervalToMicroseconds(PR_IntervalNow() - start);
}

View File

@@ -0,0 +1,97 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 "nsCacheModule.h"
#include "nsCacheTrace.h"
#include "nsCacheIterator.h"
/*
* nsCacheModule
*
* Gagan Saksena 02/02/98
*
*/
#define DEFAULT_SIZE 10*0x100000L
nsCacheModule::nsCacheModule(const PRUint32 i_size=DEFAULT_SIZE):
m_Size(i_size),
m_pEnumeration(0),
m_pNext(0),
m_Entries(0)
{
m_pIterator = new nsCacheIterator(this);
}
nsCacheModule::~nsCacheModule()
{
if (m_pNext)
{
delete m_pNext;
m_pNext = 0;
}
if (m_pIterator)
{
delete m_pIterator;
m_pIterator = 0;
}
if (m_pEnumeration)
{
delete m_pEnumeration;
m_pEnumeration = 0;
}
}
void nsCacheModule::GarbageCollect(void)
{
}
PRBool nsCacheModule::ReduceSizeTo(const PRUint32 i_NewSize)
{
MonitorLocker ml(this);
//TODO
return PR_TRUE;
}
PRBool nsCacheModule::RemoveAll(void)
{
MonitorLocker ml(this);
PRBool status = PR_TRUE;
while (m_Entries > 0)
{
status &= Remove(--m_Entries);
}
return status;
}
#if 0
// Caller must free this
const char* nsCacheModule::Trace() const
{
char linebuffer[128];
char* total;
PR_sprintf(linebuffer, "nsCacheModule: Objects = %d\n", Entries());
total = new char[PR_strlen(linebuffer) + 1];
strcpy(total, linebuffer);
return total;
}
#endif

View File

@@ -0,0 +1,580 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 <memory.h>
#include "prmem.h"
#include "prprf.h"
#include "plstr.h"
#include "nsCacheObject.h"
#include "nsCacheTrace.h"
#include "nsCacheModule.h"
#include "nsCacheManager.h"
#include "nsStream.h"
/*
* nsCacheObject
*
* Gagan Saksena 02/02/98
*
*/
static const PRIntervalTime DEFAULT_EXPIRES = PR_SecondsToInterval(86400);
#if !defined(IS_LITTLE_ENDIAN) && !defined(IS_BIG_ENDIAN)
ERROR! Must have a byte order
#endif
#ifdef IS_LITTLE_ENDIAN
#define COPY_INT32(_a,_b) memcpy(_a, _b, sizeof(int32))
#else
#define COPY_INT32(_a,_b) /* swap */ \
do { \
((char *)(_a))[0] = ((char *)(_b))[3]; \
((char *)(_a))[1] = ((char *)(_b))[2]; \
((char *)(_a))[2] = ((char *)(_b))[1]; \
((char *)(_a))[3] = ((char *)(_b))[0]; \
} while(0)
#endif
/* Convenient macros used in stuffing and reading back cache object to a void * */
/* TODO: Change these to file scope functions */
#define STUFF_STRING(string) \
{ \
len = (string ? PL_strlen(string)+1 : 0); \
COPY_INT32((void *)cur_ptr, &len); \
cur_ptr = cur_ptr + sizeof(int32); \
if(len) \
memcpy((void *)cur_ptr, string, len); \
cur_ptr += len; \
}
#define STUFF_NUMBER(number) \
{ \
COPY_INT32((void *)cur_ptr, &number); \
cur_ptr = cur_ptr + sizeof(PRUint32); \
}
#define STUFF_TIME(number) \
{ \
COPY_INT32((void *)cur_ptr, &number); \
cur_ptr = cur_ptr + sizeof(PRIntervalTime); \
}
#define STUFF_BOOL(bool_val) \
{ \
if(bool_val) \
((char *)(cur_ptr))[0] = 1; \
else \
((char *)(cur_ptr))[0] = 0; \
cur_ptr = cur_ptr + sizeof(char); \
}
/* if any strings are larger than this then
* there was a serious database error
*/
#define MAX_HUGE_STRING_SIZE 10000
#define RETRIEVE_STRING(string) \
{ \
if(cur_ptr > max_ptr) \
{ \
return PR_TRUE; \
} \
COPY_INT32(&len, cur_ptr); \
cur_ptr += sizeof(int32); \
if(len) \
{ \
if(len > MAX_HUGE_STRING_SIZE) \
{ \
return PR_FALSE; \
} \
string = new char[len]; \
if(!string) \
{ \
return PR_FALSE; \
} \
memcpy(string, cur_ptr, len); \
cur_ptr += len; \
} \
}
#define RETRIEVE_NUMBER(number) \
{ \
if(cur_ptr > max_ptr) \
return PR_TRUE; \
COPY_INT32(&number, cur_ptr); \
cur_ptr += sizeof(int32); \
}
#define RETRIEVE_TIME(number) \
{ \
if(cur_ptr > max_ptr) \
return PR_TRUE; \
COPY_INT32(&number, cur_ptr); \
cur_ptr += sizeof(PRIntervalTime); \
}
#define RETRIEVE_BOOL(bool) \
{ \
if(cur_ptr > max_ptr) \
return PR_TRUE; \
if(((char *)(cur_ptr))[0]) \
bool = TRUE; \
else \
bool = FALSE; \
cur_ptr += sizeof(char); \
}
/* TODO- Further optimization, initialize these to null,
but that will add more work on copy constructor which is ok */
nsCacheObject::nsCacheObject():
m_Charset(new char[1]),
m_ContentEncoding(new char[1]),
m_ContentType(new char[1]),
m_Etag(new char[1]),
m_Filename(new char[1]),
m_Flags(INIT),
m_Module(-1),
m_pInfo(0),
m_PageServicesURL(new char[1]),
m_PostData(new char[1]),
m_PostDataLen(0),
m_pStream(0),
m_URL(new char[1])
{
Init();
*m_Charset = '\0';
*m_ContentEncoding = '\0';
*m_ContentType = '\0';
*m_Etag = '\0';
*m_Filename = '\0';
*m_PageServicesURL = '\0';
*m_PostData = '\0';
*m_URL = '\0';
}
nsCacheObject::~nsCacheObject()
{
if (m_Charset)
delete[] m_Charset;
if (m_ContentEncoding)
delete[] m_ContentEncoding;
if (m_ContentType)
delete[] m_ContentType;
if (m_Etag)
delete[] m_Etag;
if (m_Filename)
delete[] m_Filename;
if (m_PageServicesURL)
delete[] m_PageServicesURL;
if (m_PostData)
delete[] m_PostData;
if (m_URL)
delete[] m_URL;
if (m_pStream)
delete m_pStream;
}
nsCacheObject::nsCacheObject(const nsCacheObject& another):
m_Charset(new char[PL_strlen(another.m_Charset)+1]),
m_ContentEncoding(new char[PL_strlen(another.m_ContentEncoding)+1]),
m_ContentType(new char[PL_strlen(another.m_ContentType)+1]),
m_Etag(new char[PL_strlen(another.m_Etag)+1]),
m_Filename(new char[PL_strlen(another.m_Filename)+1]),
m_Flags(another.m_Flags),
m_PageServicesURL(new char[PL_strlen(another.m_PageServicesURL)+1]),
m_PostDataLen(another.m_PostDataLen),
m_PostData(new char[another.m_PostDataLen+1]),
m_URL(new char[PL_strlen(another.m_URL)+1]),
m_pStream(0),
m_pInfo(0) /* Should this be copied as well? */
{
PL_strncpy(m_Charset, another.m_Charset, PL_strlen(another.m_Charset));
PL_strncpy(m_ContentEncoding, another.m_ContentEncoding, PL_strlen(another.m_ContentEncoding));
PL_strncpy(m_ContentType, another.m_ContentType, PL_strlen(another.m_ContentType));
PL_strncpy(m_Etag, another.m_Etag, PL_strlen(another.m_Etag));
PL_strncpy(m_Filename, another.m_Filename, PL_strlen(another.m_Filename));
PL_strncpy(m_PageServicesURL, another.m_PageServicesURL, PL_strlen(another.m_PageServicesURL));
PL_strncpy(m_PostData, another.m_PostData, another.m_PostDataLen);
PL_strncpy(m_URL, another.m_URL, PL_strlen(another.m_URL));
m_Hits = another.m_Hits;
m_LastAccessed = another.m_LastAccessed;
m_LastModified = another.m_LastModified;
m_Size = another.m_Size;
m_Module = another.m_Module;
}
nsCacheObject::nsCacheObject(const char* i_url):
m_Charset(new char[1]),
m_ContentEncoding(new char[1]),
m_ContentType(new char[1]),
m_Etag(new char[1]),
m_Filename(new char[1]),
m_Flags(INIT),
m_PageServicesURL(new char[1]),
m_PostData(new char[1]),
m_PostDataLen(0),
m_URL(new char[PL_strlen(i_url)+1]),
m_Module(-1),
m_pStream(0),
m_pInfo(0)
{
Init();
PR_ASSERT(i_url);
PL_strncpy(m_URL, i_url, PL_strlen(i_url));
*m_Charset = '\0';
*m_ContentEncoding = '\0';
*m_ContentType = '\0';
*m_Etag = '\0';
*m_Filename = '\0';
*m_PageServicesURL = '\0';
*m_PostData = '\0';
}
void nsCacheObject::Address(const char* i_url)
{
PR_ASSERT(i_url && *i_url);
if (!i_url)
return;
if (m_URL)
delete[] m_URL;
m_URL = new char[PL_strlen(i_url) + 1];
PL_strncpy(m_URL, i_url, PL_strlen(i_url));
}
void nsCacheObject::Charset(const char* i_Charset)
{
// PR_ASSERT(i_Charset && *i_Charset);
if (!i_Charset)
return;
if (m_Charset)
delete[] m_Charset;
m_URL = new char[PL_strlen(i_Charset) + 1];
PL_strncpy(m_Charset, i_Charset, PL_strlen(i_Charset));
}
void nsCacheObject::ContentEncoding(const char* i_Encoding)
{
// PR_ASSERT(i_Encoding && *i_Encoding);
if (!i_Encoding)
return;
if (m_ContentEncoding)
delete[] m_ContentEncoding;
m_ContentEncoding = new char[PL_strlen(i_Encoding) + 1];
PL_strncpy(m_ContentEncoding, i_Encoding, PL_strlen(i_Encoding));
}
void nsCacheObject::ContentType(const char* i_Type)
{
// PR_ASSERT(i_Type && *i_Type);
if (!i_Type)
{
/* Reset to empty */ // TODO ??
return;
}
if (m_ContentType)
delete[] m_ContentType;
m_ContentType = new char[PL_strlen(i_Type) + 1];
PL_strncpy(m_ContentType, i_Type, PL_strlen(i_Type));
}
void nsCacheObject::Etag(const char* i_etag)
{
// PR_ASSERT(i_etag && *i_etag);
if (!i_etag)
return;
if (m_Etag)
delete[] m_Etag;
m_Etag = new char[PL_strlen(i_etag) + 1];
PL_strncpy(m_Etag, i_etag, PL_strlen(i_etag));
}
void nsCacheObject::Filename(const char* i_Filename)
{
// PR_ASSERT(i_Filename && *i_Filename);
if (!i_Filename)
return;
if (m_Filename)
delete[] m_Filename;
m_Filename = new char[PL_strlen(i_Filename) +1];
PL_strncpy(m_Filename, i_Filename, PL_strlen(i_Filename));
}
void* nsCacheObject::Info(void) const
{
if (m_pInfo)
return m_pInfo;
nsCacheObject* pThis = (nsCacheObject*) this;
if (m_URL){
pThis->m_info_size = sizeof(nsCacheObject);
pThis->m_info_size -= sizeof(void*); // m_info itself is not being serialized
pThis->m_info_size -= sizeof(char*); // And neither is PostData
//Add the strings sizes
pThis->m_info_size += PL_strlen(m_Charset)+1;
pThis->m_info_size += PL_strlen(m_ContentEncoding)+1;
pThis->m_info_size += PL_strlen(m_ContentType)+1;
pThis->m_info_size += PL_strlen(m_Etag)+1;
pThis->m_info_size += PL_strlen(m_Filename)+1;
pThis->m_info_size += PL_strlen(m_PageServicesURL)+1;
pThis->m_info_size += PL_strlen(m_URL)+1;
//Add the Postdata len
pThis->m_info_size += m_PostDataLen+1;
void* new_obj = PR_Calloc(1, m_info_size * sizeof(char));
if (!new_obj)
{
PR_Free(new_obj);
return 0;
}
PRUint32 len;
char* cur_ptr = (char*) new_obj;
/* put the total size of the struct into
* the first field so that we have
* a cross check against corruption
*/
COPY_INT32((void *)cur_ptr, &m_info_size);
cur_ptr += sizeof(PRUint32);
/* put the version number of the structure
* format that we are using. By using a version
* string when writting we can support
* backwards compatibility in our reading code
*/
COPY_INT32((void *)cur_ptr, &kCACHE_VERSION);
cur_ptr += sizeof(PRUint32);
STUFF_STRING(m_Charset);
STUFF_STRING(m_ContentEncoding);
STUFF_NUMBER(m_ContentLength);
STUFF_STRING(m_ContentType);
STUFF_STRING(m_Etag);
STUFF_TIME(m_Expires);
STUFF_STRING(m_Filename);
STUFF_NUMBER(m_Flags);
STUFF_NUMBER(m_Hits);
STUFF_TIME(m_LastAccessed);
STUFF_TIME(m_LastModified);
STUFF_NUMBER(m_Module);
STUFF_STRING(m_PageServicesURL);
STUFF_NUMBER(m_PostDataLen);
/* There is a possibility of it not being a string! */
if (m_PostData)
{
memcpy(cur_ptr, m_PostData, m_PostDataLen+1);
cur_ptr += m_PostDataLen+1;
}
STUFF_NUMBER(m_Size);
STUFF_STRING(m_URL);
// Important Assertion. Dont remove!
// If this fails then you or somebody has added a variable to the
// nsCacheObject class and a decision on its "cacheability" has
// not yet been made.
PR_ASSERT(cur_ptr == (char*) new_obj + m_info_size);
pThis->m_pInfo = new_obj;
}
return m_pInfo;
}
PRBool nsCacheObject::Info(void* i_data)
{
if (!i_data)
return PR_FALSE;
char* cur_ptr = (char*) i_data;
//Reset the m_pInfo;
PR_FREEIF(m_pInfo);
//Reset all strings
if (m_Charset)
delete[] m_Charset;
if (m_ContentEncoding)
delete[] m_ContentEncoding;
if (m_ContentType)
delete[] m_ContentType;
if (m_Etag)
delete[] m_Etag;
if (m_Filename)
delete[] m_Filename;
if (m_PageServicesURL)
delete[] m_PageServicesURL;
if (m_URL)
delete[] m_URL;
if (m_PostData)
delete[] m_PostData;
m_PostDataLen = 0;
COPY_INT32(&m_info_size, cur_ptr);
char* max_ptr = cur_ptr + m_info_size;
cur_ptr += sizeof(PRUint32);
PRUint32 version;
COPY_INT32(&version, cur_ptr);
cur_ptr += sizeof(PRUint32);
PR_ASSERT(version == kCACHE_VERSION);
if (version != kCACHE_VERSION)
{
//TODO Bad cache version
return PR_FALSE;
}
PRUint32 len;
RETRIEVE_STRING(m_Charset);
RETRIEVE_STRING(m_ContentEncoding);
RETRIEVE_NUMBER(m_ContentLength);
RETRIEVE_STRING(m_ContentType);
RETRIEVE_STRING(m_Etag);
RETRIEVE_TIME(m_Expires);
RETRIEVE_STRING(m_Filename);
RETRIEVE_NUMBER(m_Flags);
RETRIEVE_NUMBER(m_Hits);
RETRIEVE_TIME(m_LastAccessed);
RETRIEVE_TIME(m_LastModified);
RETRIEVE_NUMBER(m_Module);
RETRIEVE_STRING(m_PageServicesURL);
RETRIEVE_NUMBER(m_PostDataLen);
// Special case-
m_PostData = new char[m_PostDataLen + 1];
if (m_PostData)
{
memcpy(m_PostData, cur_ptr, m_PostDataLen+1);
}
cur_ptr += m_PostDataLen +1;
RETRIEVE_NUMBER(m_Size);
RETRIEVE_STRING(m_URL);
// Most important assertion! Don't ever remove!
PR_ASSERT(cur_ptr == max_ptr);
return PR_TRUE;
}
PRUint32 nsCacheObject::InfoSize(void) const
{
if (!m_pInfo)
{
((nsCacheObject*) this)->Info();
}
return m_info_size;
}
void nsCacheObject::Init()
{
m_Expires = PR_IntervalNow() + DEFAULT_EXPIRES;
m_Hits = 0;
}
void nsCacheObject::PageServicesURL(const char* i_Url)
{
// PR_ASSERT(i_Url && *i_Url);
if (!i_Url)
return;
if (m_PageServicesURL)
delete[] m_PageServicesURL;
m_PageServicesURL = new char[PL_strlen(i_Url) + 1];
PL_strncpy(m_PageServicesURL, i_Url, PL_strlen(i_Url));
}
void nsCacheObject::PostData(const char* i_data, const PRUint32 i_Len)
{
if (!i_data || (0 ==i_Len))
return;
if (m_PostData)
delete[] m_PostData;
m_PostData = new char[i_Len+1];
PL_strncpy(m_PostData, i_data, i_Len);
m_PostDataLen = i_Len;
}
PRUint32 nsCacheObject::Read(char* o_Buffer, PRUint32 len)
{
if (!m_pStream)
{
PR_ASSERT(m_Module >=0);
if (0 <= m_Module)
{
nsCacheModule* pModule = nsCacheManager::GetInstance()->GetModule(m_Module);
if (pModule)
{
m_pStream = pModule->GetStreamFor(this);
if (m_pStream)
return m_pStream->Read(o_Buffer, len);
}
}
return 0;
}
return m_pStream->Read(o_Buffer, len);
}
#if 0
/* Caller must free returned string */
// TODO change to use PR_stuff...
const char* nsCacheObject::Trace() const
{
char linebuffer[256];
char* total;
PR_Sprintf(linebuffer, "nsCacheObject:URL=%s,SIZE=%d,ET=%s,\n\tLM=%d,LA=%d,EXP=%d,HITS=%d\n",
m_URL,
m_Size,
m_Etag,
m_LastModified,
m_LastAccessed,
m_Expires,
m_Hits);
total = new char[PL_strlen(linebuffer) +1];
PL_strcpy(total, linebuffer);
return total;
}
#endif
PRUint32 nsCacheObject::Write(const char* i_Buffer, const PRUint32 len)
{
if (!m_pStream)
{
PR_ASSERT(m_Module >=0);
if (0 <= m_Module)
{
nsCacheModule* pModule = nsCacheManager::GetInstance()->GetModule(m_Module);
if (pModule)
{
m_pStream = pModule->GetStreamFor(this);
if (m_pStream)
return m_pStream->Write(i_Buffer, len);
}
}
return 0;
}
return m_pStream->Write(i_Buffer, len);
}

View File

@@ -0,0 +1,128 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 "nsCachePref.h"
//#include "prefapi.h"
static const PRUint32 MEM_CACHE_SIZE_DEFAULT = 1024*1024;
static const PRUint32 DISK_CACHE_SIZE_DEFAULT = 5*MEM_CACHE_SIZE_DEFAULT;
static const PRUint32 BKG_THREAD_SLEEP = 15*60; /*in seconds, 15 minutes */
static const PRUint16 BUGS_FOUND_SO_FAR = 0;
/* Find a bug in NU_CACHE, get these many chocolates */
static const PRUint16 CHOCOLATES_PER_BUG_FOUND = 2^BUGS_FOUND_SO_FAR;
/* TODO move this to InitNetLib */
static nsCachePref ThePrefs;
nsCachePref::nsCachePref(void):
m_BkgSleepTime(BKG_THREAD_SLEEP),
m_DiskCacheDBFilename(new char[6+1]),
m_DiskCacheFolder(0),
m_DiskCacheSize(DISK_CACHE_SIZE_DEFAULT),
m_MemCacheSize(MEM_CACHE_SIZE_DEFAULT),
m_RefreshFreq(ONCE)
{
//Read all the stuff from pref here.
//If this changes to nsPref, here is all that needs to be changed.
//PRUint32 nTemp;
//PREF_GetIntPref("browser.cache.memory_cache_size",&nTemp);
//*1024
}
nsCachePref::~nsCachePref()
{
}
const PRUint32
nsCachePref::BkgSleepTime(void)
{
return BKG_THREAD_SLEEP;
}
PRUint32 nsCachePref::DiskCacheSize()
{
return m_DiskCacheSize;
}
void nsCachePref::DiskCacheSize(const PRUint32 i_Size)
{
m_DiskCacheSize = i_Size;
}
PRBool nsCachePref::DiskCacheSSL(void)
{
return m_bDiskCacheSSL;
}
void nsCachePref::DiskCacheSSL(PRBool bSet)
{
m_bDiskCacheSSL = bSet;
}
const char* nsCachePref::DiskCacheDBFilename(void)
{
return "fat.db";
}
const char* nsCachePref::DiskCacheFolder(void)
{
return 0;
}
nsCachePref* nsCachePref::GetInstance()
{
return &ThePrefs;
}
PRUint32 nsCachePref::MemCacheSize()
{
return m_MemCacheSize;
}
void nsCachePref::MemCacheSize(const PRUint32 i_Size)
{
m_MemCacheSize = i_Size;
}
PRBool nsCachePref::RevalidateInBkg(void)
{
return m_bRevalidateInBkg;
}
/*
nsrefcnt nsCachePref::AddRef(void)
{
return ++m_RefCnt;
}
nsrefcnt nsCachePref::Release(void)
{
if (--m_RefCnt == 0)
{
delete this;
return 0;
}
return m_RefCnt;
}
nsresult nsCachePref::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
return NS_OK;
}
*/

View File

@@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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
@@ -16,22 +16,29 @@
* Reserved.
*/
#ifndef _REGISTER_PRESSURE_H_
#define _REGISTER_PRESSURE_H_
/*
* nsCacheTrace
*
* Gagan Saksena 02/02/98
*
*/
#include "BitSet.h"
#include "HashSet.h"
#include "nsCacheTrace.h"
struct LowRegisterPressure
static nsCacheTrace TheTrace;
nsCacheTrace::nsCacheTrace():m_bEnabled(PR_FALSE)
{
typedef BitSet Set;
static const bool setIsOrdered = true;
};
struct HighRegisterPressure
}
void nsCacheTrace::Enable(PRBool bEnable)
{
typedef HashSet Set;
static const bool setIsOrdered = false;
};
TheTrace.m_bEnabled = bEnable;
}
PRBool nsCacheTrace::IsEnabled(void)
{
return TheTrace.m_bEnabled;
}
#endif // _REGISTER_PRESSURE_H_

View File

@@ -0,0 +1,271 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
/*
* nsDiskModule
*
* Gagan Saksena 02/02/98
*
*/
#include "prtypes.h"
#include "prmem.h"
#include "plstr.h"
#include "prlog.h"
#include "nsDiskModule.h"
#include "nsCacheObject.h"
#include "nsCacheManager.h"
#include "mcom_db.h"
#define ENSURE_INIT \
if (!m_pDB) \
{ \
nsDiskModule* pThis = (nsDiskModule*) this; \
PRBool res = pThis->InitDB(); \
PR_ASSERT(res); \
}
//
// Constructor: nsDiskModule
//
nsDiskModule::nsDiskModule(const PRUint32 size):
nsCacheModule(size),
m_pDB(0)
{
}
nsDiskModule::~nsDiskModule()
{
if (m_pDB)
{
(*m_pDB->sync)(m_pDB, 0);
(*m_pDB->close)(m_pDB);
m_pDB = 0;
}
}
PRBool nsDiskModule::AddObject(nsCacheObject* io_pObject)
{
ENSURE_INIT;
if (!m_pDB || !io_pObject)
{
// Set some error state TODO
return PR_FALSE;
}
if (io_pObject->Address())
{
MonitorLocker ml(this);
// TODO optimize these further- make static - Gagan
DBT* key = PR_NEW(DBT);
DBT* data = PR_NEW(DBT);
io_pObject->Module(nsCacheManager::DISK);
key->data = (void*)io_pObject->Address();
/* Later on change this to include post data- io_pObject->KeyData() */
key->size = PL_strlen(io_pObject->Address());
data->data = io_pObject->Info();
data->size = io_pObject->InfoSize();
int status = (*m_pDB->put)(m_pDB, key, data, 0);
if (status == 0)
{
// if (m_Sync == EVERYTIME)
status = (*m_pDB->sync)(m_pDB, 0);
}
PR_Free(key);
PR_Free(data);
return (status == 0);
}
return PR_FALSE;
}
PRBool nsDiskModule::Contains(nsCacheObject* io_pObject) const
{
//return Contains(io_oObject->Address());
ENSURE_INIT;
if (!m_pDB || !io_pObject)
return PR_FALSE;
nsCacheObject* pTemp = GetObject(io_pObject->Address());
if (pTemp)
{
io_pObject = pTemp; /*bug */
return PR_TRUE;
}
return PR_FALSE;
}
PRBool nsDiskModule::Contains(const char* i_url) const
{
ENSURE_INIT;
if (!m_pDB || !i_url || !*i_url)
return PR_FALSE;
DBT key, data;
key.data = (void*) i_url;
key.size = PL_strlen(i_url);
int status = (*m_pDB->get)(m_pDB, &key, &data, 0);
return (status == 0);
}
void nsDiskModule::GarbageCollect(void)
{
MonitorLocker ml(this);
}
nsCacheObject* nsDiskModule::GetObject(const PRUint32 i_index) const
{
ENSURE_INIT;
if (!m_pDB)
return 0;
//todo
return 0;
}
nsCacheObject* nsDiskModule::GetObject(const char* i_url) const
{
ENSURE_INIT;
if (!m_pDB || !i_url || !*i_url)
return 0;
DBT key, data;
key.data = (void*) i_url;
key.size = PL_strlen(i_url);
if (0 == (*m_pDB->get)(m_pDB, &key, &data, 0))
{
nsCacheObject* pTemp = new nsCacheObject();
pTemp->Info(data.data);
return pTemp;
}
return 0;
}
nsStream* nsDiskModule::GetStreamFor(const nsCacheObject* i_pObject)
{
ENSURE_INIT;
return 0;
}
PRBool nsDiskModule::InitDB(void)
{
MonitorLocker ml(this);
if (m_pDB)
return PR_TRUE;
HASHINFO hash_info = {
16*1024, /* bucket size */
0, /* fill factor */
0, /* number of elements */
0, /* bytes to cache */
0, /* hash function */
0}; /* byte order */
m_pDB = dbopen(
nsCachePref::GetInstance()->DiskCacheDBFilename(),
O_RDWR | O_CREAT,
0600,
DB_HASH,
&hash_info);
if (!m_pDB)
return PR_FALSE;
/* Open and read in the number of existing entries */
m_Entries = 0;
int status;
DBT key, data;
if(!(status = (*m_pDB->seq)(m_pDB, &key, &data, R_FIRST)))
{
while(!(status = (*m_pDB->seq) (m_pDB, &key, &data, R_NEXT)))
{
/* Also validate the corresponding file here */
//TODO
m_Entries++;
}
}
if (status < 0)
return PR_FALSE;
return PR_TRUE;
}
PRBool nsDiskModule::ReduceSizeTo(const PRUint32 i_NewSize)
{
//TODO
return PR_TRUE;
}
PRBool nsDiskModule::Remove(const char* i_url)
{
ENSURE_INIT;
//TODO
// Also remove the file corresponding to this item.
return PR_FALSE;
}
PRBool nsDiskModule::Remove(const PRUint32 i_index)
{
ENSURE_INIT;
//TODO
// Also remove the file corresponding to this item.
return PR_FALSE;
}
PRBool nsDiskModule::Revalidate(void)
{
ENSURE_INIT;
//TODO - This will add a dependency on HTTP lib
return PR_FALSE;
}
void nsDiskModule::SetSize(const PRUint32 i_Size)
{
MonitorLocker ml(this);
m_Size = i_Size;
if (m_Size >0)
{
ReduceSizeTo(m_Size);
}
else
{
RemoveAll();
}
}
#undef ENSURE_INIT

View File

@@ -0,0 +1,91 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 "nsFFEntry.h"
#include "prmem.h"
#include "prlog.h"
nsFFEntry::nsFFEntry():
m_ID(0),
m_pFirstObject(0),
m_pNextEntry(0),
m_Objects(0)
{
}
nsFFEntry::nsFFEntry(const PRUint32 i_ID):
m_ID(i_ID),
m_pFirstObject(0),
m_pNextEntry(0),
m_Objects(0)
{
}
nsFFEntry::nsFFEntry(const PRUint32 i_ID, const PRUint32 i_offset, const PRUint32 i_size):
m_ID(i_ID),
m_pFirstObject(new nsFFObject(i_ID, i_offset, i_size)),
m_pNextEntry(0),
m_Objects(1)
{
//PR_ASSERT(i_offset > nsFlatFile::HeaderSize());
}
nsFFEntry::~nsFFEntry()
{
PR_FREEIF(m_pFirstObject);
PR_FREEIF(m_pNextEntry);
}
/*
nsrefcnt nsFFEntry::AddRef(void)
{
return ++m_RefCnt;
}
nsrefcnt nsFFEntry::Release(void)
{
if (--m_RefCnt == 0)
{
delete this;
return 0;
}
return m_RefCnt;
}
nsresult nsFFEntry::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
return NS_OK;
}
nsFFEntry::
*/
PRBool nsFFEntry::AddObject(const nsFFObject* i_object)
{
PR_ASSERT(i_object);
if (!i_object)
return PR_FALSE;
if (!m_pFirstObject)
{
m_pFirstObject = (nsFFObject*) i_object;
m_Objects++;
}
return m_pFirstObject->Add(i_object);
return PR_FALSE;
}

View File

@@ -0,0 +1,44 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 "nsFFObject.h"
#include "prlog.h"
nsFFObject::nsFFObject(PRUint32 i_ID, PRUint32 i_Offset, PRUint32 i_Size):
m_ID(i_ID),
m_Offset(i_Offset),
m_Size(i_Size),
m_pNext(0)
{
}
nsFFObject::~nsFFObject()
{
}
PRBool nsFFObject::Add(const nsFFObject* i_object)
{
PR_ASSERT(i_object);
if (!i_object)
return PR_FALSE;
if (m_pNext)
return m_pNext->Add(i_object);
m_pNext = (nsFFObject*) i_object;
return PR_TRUE;
}

View File

@@ -0,0 +1,71 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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.
*
* 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.
*/
#include "nsFileStream.h"
nsFileStream::nsFileStream(XP_File* i_pFile):m_pFile(i_pFile)
{
PR_ASSERT(m_pFile);
}
nsFileStream::~nsFileStream()
{
}
/*
nsrefcnt nsFileStream::AddRef(void)
{
return ++m_RefCnt;
}
nsrefcnt nsFileStream::Release(void)
{
if (--m_RefCnt == 0)
{
delete this;
return 0;
}
return m_RefCnt;
}
nsresult nsFileStream::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
return NS_OK;
}
*/
PRInt32 nsFileStream::Read(void* o_Buffer, PRUint32 i_Len)
{
if (m_pFile)
{
int status = XP_FileRead(o_Buffer, i_Len, *m_pFile);
return status;
}
return 0;
}
PRInt32 nsFileStream::Write(const void* i_Buffer, PRUint32 i_Len)
{
if (m_pFile)
{
int status = XP_FileWrite(i_Buffer, i_Len, *m_pFile);
return status;
}
return 0;
}

View File

@@ -0,0 +1,153 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 "nsFlatFile.h"
#include "plstr.h"
#include "prmem.h"
#include "memory.h"
static const PRUint32 kFLAT_FILE_VERSION = 1;
static const PRUint32 kMAGIC_NUMBER = 3739142906; // Facede de //TODO
static const char kFILL_CHAR = 'G';
nsFlatFile::nsFlatFile(const char* i_pFilename, const PRUint32 i_Size):
m_bIsValid(PR_FALSE),
m_pFD(0),
m_Size(i_Size),
m_HeaderSize(2*sizeof(PRUint32)),
m_pFilename(new char[PL_strlen(i_pFilename) + 1])
{
PL_strcpy(m_pFilename, i_pFilename);
Init();
}
nsFlatFile::~nsFlatFile()
{
delete[] m_pFilename;
if (m_pFD)
{
PR_Close(m_pFD);
m_pFD = 0;
}
}
void nsFlatFile::Init(void)
{
if (m_pFilename)
{
m_pFD = PR_Open(m_pFilename, PR_CREATE_FILE | PR_RDWR, 0600);
if (!m_pFD)
{
return;
}
PRFileInfo info;
// if the file is just being created then write magic number
// and flat file version, else verify
if (PR_SUCCESS == PR_GetOpenFileInfo(m_pFD, &info))
{
PRInt32 status;
if (info.size > 0)
{
char* buf = new char[m_HeaderSize];
//verify
status = PR_Read(m_pFD, buf, m_HeaderSize);
if (status > 0)
{
char* cur_ptr = buf;
PRUint32 test;
COPY_INT32(&test, cur_ptr);
if (test != kMAGIC_NUMBER)
{
PR_Close(m_pFD);
m_pFD = 0;
//PR_ASSERT(!"Bad flat file!");
return;
}
cur_ptr += sizeof(PRUint32);
COPY_INT32(&test, cur_ptr);
if (test != kFLAT_FILE_VERSION)
{
PR_Close(m_pFD);
m_pFD = 0;
//PR_ASSERT(!"Bad version of flat file format!");
return;
}
//Everything was as expected so
m_bIsValid = PR_TRUE;
}
delete[] buf;
}
else
{
//write out
char* buf = new char[m_HeaderSize];
PRUint32 test = m_HeaderSize;
char* cur_ptr = buf;
COPY_INT32((void*) cur_ptr, &kMAGIC_NUMBER);
cur_ptr += sizeof(PRUint32);
COPY_INT32((void*) cur_ptr, &kFLAT_FILE_VERSION);
status = PR_Write(m_pFD, buf, m_HeaderSize);
delete[] buf;
PRBool bFillChar = PR_FALSE;
if (bFillChar)
{
buf = new char[kPAGE_SIZE];
for (int i = 0; i< kPAGE_SIZE; ++i)
buf[i] = kFILL_CHAR;
int j = (int)((m_Size - m_HeaderSize) / kPAGE_SIZE);
int k;
for (k = j; k > 0; --k)
{
status = PR_Write(m_pFD, (void*) buf, kPAGE_SIZE);
}
delete[] buf;
int remaining = (m_Size-m_HeaderSize) % kPAGE_SIZE;
for (k = remaining; k>0; --k)
{
status = PR_Write(m_pFD, (void*) &kFILL_CHAR, 1);
}
}
}
}
}
}
/*
nsrefcnt nsFlatFile::AddRef(void)
{
return ++m_RefCnt;
}
nsrefcnt nsFlatFile::Release(void)
{
if (--m_RefCnt == 0)
{
delete this;
return 0;
}
return m_RefCnt;
}
nsresult nsFlatFile::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
return NS_OK;
}
*/

142
mozilla/network/cache/nu/src/nsHash.cpp vendored Normal file
View File

@@ -0,0 +1,142 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* 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 "prmem.h"
#include "nsHash.h"
//
// Key operations
//
static PR_CALLBACK PLHashNumber _hashValue(const void *key)
{
return ((const nsHashKey *) key)->HashValue();
}
static PR_CALLBACK PRIntn _hashKeyCompare(const void *key1, const void *key2) {
return ((const nsHashKey *) key1)->Equals((const nsHashKey *) key2);
}
static PR_CALLBACK PRIntn _hashValueCompare(const void *value1,
const void *value2) {
// We're not going to make any assumptions about value equality
return 0;
}
//
// Memory callbacks
//
static PR_CALLBACK void *_hashAllocTable(void *pool, PRSize size) {
return PR_MALLOC(size);
}
static PR_CALLBACK void _hashFreeTable(void *pool, void *item) {
PR_DELETE(item);
}
static PR_CALLBACK PLHashEntry *_hashAllocEntry(void *pool, const void *key) {
return PR_NEW(PLHashEntry);
}
static PR_CALLBACK void _hashFreeEntry(void *pool, PLHashEntry *entry,
PRUintn flag) {
if (flag == HT_FREE_ENTRY) {
delete (nsHashKey *) (entry->key);
PR_DELETE(entry);
}
}
static PLHashAllocOps _hashAllocOps = {
_hashAllocTable, _hashFreeTable,
_hashAllocEntry, _hashFreeEntry
};
//
// Enumerator callback
//
static PR_CALLBACK PRIntn _hashEnumerate(PLHashEntry *he, PRIntn i, void *arg)
{
return ((nsHashEnumFunc) arg)((nsHashKey *) he->key, he->value) ?
HT_ENUMERATE_NEXT :
HT_ENUMERATE_STOP;
}
//
// HashKey
//
nsHashKey::nsHashKey(void)
{
}
nsHashKey::~nsHashKey(void)
{
}
nsHash::nsHash(PRUint32 aInitSize) {
hashtable = PL_NewHashTable(aInitSize,
_hashValue,
_hashKeyCompare,
_hashValueCompare,
&_hashAllocOps,
NULL);
}
nsHash::~nsHash() {
PL_HashTableDestroy(hashtable);
}
void *nsHash::Put(nsHashKey *aKey, void *aData) {
void *res = NULL;
PLHashNumber hash = aKey->HashValue();
PLHashEntry *he;
PLHashEntry **hep = PL_HashTableRawLookup(hashtable, hash, (void *) aKey);
if ((he = *hep) != NULL) {
res = he->value;
he->value = aData;
} else {
PL_HashTableRawAdd(hashtable, hep, hash,
(void *) aKey->Clone(), aData);
}
return res;
}
void *nsHash::Get(nsHashKey *aKey) {
return PL_HashTableLookup(hashtable, (void *) aKey);
}
void *nsHash::Remove(nsHashKey *aKey) {
PLHashNumber hash = aKey->HashValue();
PLHashEntry *he;
PLHashEntry **hep = PL_HashTableRawLookup(hashtable, hash, (void *) aKey);
void *res = NULL;
if ((he = *hep) != NULL) {
res = he->value;
PL_HashTableRawRemove(hashtable, hep, he);
}
return res;
}
void nsHash::Enumerate(nsHashEnumFunc aEnumFunc) {
PL_HashTableEnumerateEntries(hashtable, _hashEnumerate, aEnumFunc);
}

View File

@@ -0,0 +1,44 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
/*
* nsMemCacheObject
*
* Gagan Saksena 04/22/98
*
*/
#include "prtypes.h"
#include "nsMemCacheObject.h"
nsMemCacheObject::~nsMemCacheObject()
{
if (m_pNextObject)
{
delete m_pNextObject;
m_pNextObject = 0;
}
if (m_pObject)
{
delete m_pObject;
m_pObject = 0;
}
// Free the void* if allocated - TODO
}

Some files were not shown because too many files have changed in this diff Show More