Compile most of Lucene's core code with a single call to gcj. This

permits more cross-class inlining.  In particular, the final method
PriorityQueue.size() can inline, which speeds things 7.5% in my
benchmarks.  Note that 'final' declarations *do* sometimes make things
faster in GCJ.  So let's not remove them all!


git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150534 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Doug Cutting 2004-09-23 16:59:10 +00:00
parent a71929fe4e
commit 5a3cfc5372
1 changed files with 44 additions and 20 deletions

View File

@ -2,23 +2,29 @@
#
# Usually invoked by Ant. Requires that core classes & jars are already built.
BUILD=../../build
LUCENE_OBJ=$(subst .jar,.a,$(wildcard $(BUILD)/lucene-*.jar))
ROOT=../..
BUILD=$(ROOT)/build
DEST=$(BUILD)/gcj
CORE=$(BUILD)/classes/java
SRC=.
CORE_OBJ:=$(subst .jar,.a,$(wildcard $(BUILD)/lucene-[0-9]*.jar))
CORE_JAVA:=$(shell find $(ROOT)/src/java -name '*.java')
CORE_HEADERS=\
$(CORE)/org/apache/lucene/store/IndexInput.h \
$(CORE)/org/apache/lucene/util/BitVector.h \
$(CORE)/org/apache/lucene/index/SegmentTermDocs.h
JAVA=$(wildcard $(SRC)/org/apache/lucene/*/*.java)
JAVA_HEADERS=$(subst $(SRC)/,$(DEST)/,$(subst .java,.h,$(JAVA)))
JAVA_OBJ=$(DEST)/lucene-gcj.a
DEMO_JAR:=$(wildcard $(BUILD)/lucene-demo*.jar)
DEMO_OBJ:=$(subst .jar,.a,$(DEMO_JAR))
CNI=$(wildcard $(SRC)/org/apache/lucene/*/*.cc)
CNI_OBJ=$(subst $(SRC)/,$(DEST)/,$(subst .cc,.o,$(CNI)))
JAVA:=$(wildcard $(SRC)/org/apache/lucene/*/*.java)
JAVA_HEADERS:=$(subst $(SRC)/,$(DEST)/,$(subst .java,.h,$(JAVA)))
JAVA_OBJ:=$(DEST)/lucene-gcj.a
CNI:=$(wildcard $(SRC)/org/apache/lucene/*/*.cc)
CNI_OBJ:=$(subst $(SRC)/,$(DEST)/,$(subst .cc,.o,$(CNI)))
CFLAGS ?= -O3 -ffast-math
GCJFLAGS ?= $(CFLAGS) -fno-bounds-check -fno-store-check
@ -33,43 +39,61 @@ endif
LIBS = -lstdc++
# default rule build's command line executables
# default rule builds command line executables
all: $(BUILD)/indexFiles $(BUILD)/searchFiles
# pattern rules to generate various things
# Compile Lucene Core code specially
# GCJ can do more inlining when it compiles .java files than .class
# files, but not all of Lucene's core .java files are yet compilable
# by GCJ. (In particular, GCJ has problems with anonymous ctors that
# throw exceptions used in the Span and Sort code.) So we compile
# those that GCJ accepts from .java files, and those that GCJ does not
# yet accept from .class files.
$(CORE_OBJ) : $(CORE_JAVA)
gcj $(GCJFLAGS) -c -I $(CORE) -o $@ `find $(ROOT)/src/java -name '*.java' -not -name '*Sort*' -not -name 'Span*'` `find $(CORE) -name '*.class' -name '*Sort*' -or -name 'Span*'`
# generate object code from jar files using gcj
%.a : %.jar
gcj $(GCJFLAGS) -c -I $(CORE) -o $@ $<
$(DEST)/%.class : $(SRC)/%.java
mkdir -p $(dir $@)
gcj -C -I $(CORE) -d $(DEST) $<
# don't delete generated headers -- they're handy for debugging
.PRECIOUS : $(CORE)/%.h $(DEST)/%.h
# generate headers from .class files using gcjh
$(CORE)/%.h : $(CORE)/%.class
gcjh --classpath=$(CORE) -d $(CORE) \
$(subst /,.,$(subst .class,,$(subst $(CORE)/,,$<)))
# generate headers from .class files using gcjh
$(DEST)/%.h : $(DEST)/%.class
gcjh --classpath=$(DEST) -d $(DEST) \
$(subst /,.,$(subst .class,,$(subst $(DEST)/,,$<)))
$(DEST)/%.cc : $(DEST)/%.class
gcjh -stubs --classpath=$(DEST) -d $(DEST) \
$(subst /,.,$(subst .class,,$(subst $(DEST)/,,$<)))
# generate object code for c++ code using g++
$(DEST)/%.o : $(SRC)/%.cc $(DEST)/%.h $(CORE_HEADERS) $(JAVA_HEADERS)
g++ $(CFLAGS) -c -I $(CORE) -I $(DEST) -o $@ $<
$(DEST)/%.s : $(SRC)/%.cc $(DEST)/%.h $(CORE_HEADERS) $(JAVA_HEADERS)
g++ $(CFLAGS) -S -I $(CORE) -I $(DEST) -o $@ $<
# generate class from java using gcj
$(DEST)/%.class : $(SRC)/%.java
mkdir -p $(dir $@)
gcj -C -I $(CORE) -d $(DEST) $<
# generate object code for .java files using gcj
$(JAVA_OBJ) : $(JAVA)
mkdir -p $(dir $@)
gcj $(GCJFLAGS) -c -I $(CORE) -I $(DEST) -o $@ $^
# generate c++ stubs for a class using gcjh
$(DEST)/%.cc : $(DEST)/%.class
gcjh -stubs --classpath=$(DEST) -d $(DEST) \
$(subst /,.,$(subst .class,,$(subst $(DEST)/,,$<)))
# generate assembly code from c++ code for perusal
$(DEST)/%.s : $(SRC)/%.cc $(DEST)/%.h $(CORE_HEADERS) $(JAVA_HEADERS)
g++ $(CFLAGS) -S -I $(CORE) -I $(DEST) -o $@ $<
# list of all object code to be linked
OBJ = $(LUCENE_OBJ) $(JAVA_OBJ) $(CNI_OBJ)
OBJ = $(CORE_OBJ) $(DEMO_OBJ) $(JAVA_OBJ) $(CNI_OBJ)
USE_GCJ_DIRECTORY =\
-Dorg.apache.lucene.FSDirectory.class=org.apache.lucene.store.GCJDirectory