1 #
   2 # Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 # This Makefile is intended to produce new reordering files for the
  27 # reordering of jar files and shared libraries.  This is not part of the
  28 # standard build.  The objects produced by this Makefile must be copied
  29 # into their standard locations and checked in.
  30 
  31 BUILDDIR = ../..
  32 PACKAGE = tools.reorder
  33 PRODUCT = tools
  34 include $(BUILDDIR)/common/Defs.gmk
  35 
  36 OUTDIR = $(OUTPUTDIR)/reorder
  37 PRELOAD_DIR = $(ABS_OUTPUTDIR)/reorder/$(ARCH)
  38 
  39 ifeq ($(PLATFORM), windows)
  40 SEP = \\
  41 else
  42 SEP = /
  43 endif
  44 
  45 CLASSDIR = $(OUTDIR)/classes
  46 OBJDIR = $(OUTDIR)/$(ARCH)
  47 TESTS = Null Exit Hello Sleep IntToString \
  48         LoadToolkit LoadFrame LoadJFrame JHello
  49 TEST_CLASSES = $(TESTS:%=$(CLASSDIR)/%.class)
  50 SWINGSET2 = $(OUTPUTDIR)/demo/jfc/SwingSet2/SwingSet2.jar
  51 
  52 # Run java from the JRE image because using rt.jar requires a
  53 # larger list of classes, and these should appear in the list.
  54 #   FIXUP: adding rt.jar into bootclasspath?
  55 JRE_LIB = $(JRE_IMAGE_DIR)/lib
  56 BOOTPATH = -Xbootclasspath:$(JRE_LIB)/rt.jar:$(JRE_LIB)/charsets.jar
  57 JRE_JAVA = $(JRE_IMAGE_DIR)/bin/java
  58 
  59 JAVA_BIN = $(BINDIR)/java
  60 
  61 all : jars.reorder
  62 
  63 tools : $(OBJDIR) $(OBJDIR)/libmcount.so $(OBJDIR)/remove_mcount
  64 
  65 copy : jars.copy
  66 
  67 clean : 
  68         $(RM) $(REORDER_JAR)
  69 
  70 clobber : clean
  71         $(RM) -r $(OUTDIR)
  72 
  73 
  74 jars.reorder :
  75         $(MAKE) JARFILE=rt.jar   reorder.jar
  76         $(MAKE) JARFILE=charsets.jar reorder.jar
  77 
  78 jars.copy:
  79         $(CP) $(OUTDIR)/reorder_rt_jar-$(PLATFORM)    reorder_rt_jar-$(PLATFORM)
  80         $(CP) $(OUTDIR)/reorder_charsets_jar-$(PLATFORM)  reorder_charsets_jar-$(PLATFORM)
  81 
  82 REORDER_JAR = $(OUTDIR)/reorder_$(subst .,_,$(JARFILE))-$(PLATFORM)
  83 reorder.jar : $(REORDER_JAR)
  84 
  85 REORDER_LIB = $(OUTDIR)/reorder_$(subst /,_,$(LIBBLDDIR))-$(ARCH)
  86 reorder.lib : $(OBJDIR) $(REORDER_LIB)
  87 
  88 
  89 # This target 'test_classes' also used by hotspot reordering.
  90 test_classes : $(TEST_CLASSES)
  91 
  92 # This target 'tool_classes' also used by hotspot reordering.
  93 tool_classes : $(CLASSDIR) $(CLASSDIR)/Combine.class $(CLASSDIR)/MaxTime.class
  94 
  95 $(REORDER_JAR) : $(CLASSDIR) test_classes tool_classes
  96         $(RM) $(REORDER_JAR)
  97 
  98         @$(ECHO) "# Ordered list of files to include in $(JARFILE)." > $(REORDER_JAR)
  99         @$(ECHO) "# This is a generated file - do not edit."        >> $(REORDER_JAR)
 100         @$(ECHO) "#"                                                >> $(REORDER_JAR)
 101 
 102         @# Run each of a set of tests, extract the classes required and
 103         @# append the new classes to the ClassList.
 104 
 105         @for f in $(TESTS) ; do                                           \
 106             $(ECHO) Running test $$f.;                                    \
 107             $(RM) $(REORDER_JAR)_tmp1;                                    \
 108             echo "# Test $$f" >> $(REORDER_JAR);                    \
 109             $(JRE_JAVA) -verbose -classpath $(CLASSDIR) $$f |             \
 110               $(SED) -n -e 's=\[Loaded \(.*\) from .*$(SEP)lib$(SEP)$(JARFILE)]=\1=p' | \
 111               $(SED) -e 's=\.=/=g' -e 's=$$=.class='                      \
 112                  > $(REORDER_JAR)_tmp1;                                        \
 113             $(JRE_JAVA) -classpath $(CLASSDIR) Combine                    \
 114                 $(REORDER_JAR) $(REORDER_JAR)_tmp1                        \
 115                  > $(REORDER_JAR)_tmp2;                                        \
 116             $(MV) $(REORDER_JAR)_tmp2 $(REORDER_JAR);                     \
 117             $(RM) $(REORDER_JAR)_tmp1;                                    \
 118         done
 119 
 120         @# Run SwingSet2, extract the classes required and
 121         @# append the new classes to the ClassList.
 122 
 123         @$(RM) $(REORDER_JAR)_tmp1
 124         @$(RM) $(REORDER_JAR)_tmp2
 125         @$(ECHO) "# SwingSet2" >> $(REORDER_JAR)
 126 
 127         @$(ECHO) ""
 128         @$(ECHO) ""
 129         @$(ECHO) "When SwingSet2 has finished drawing, " \
 130                  "you may terminate it (with your mouse)."
 131         @$(ECHO) "Otherwise, it should be automatically terminated in 2 minutes."
 132         @$(ECHO) ""
 133         @$(ECHO) ""
 134 
 135         $(JRE_JAVA) -verbose -classpath $(CLASSDIR) MaxTime $(SWINGSET2) 120 \
 136                  > $(REORDER_JAR)_tmp2 
 137 
 138         $(SED) -n -e 's=\[Loaded \(.*\) from .*$(SEP)lib$(SEP)$(JARFILE)]=\1=p'    \
 139             < $(REORDER_JAR)_tmp2 |                                     \
 140         $(SED) -e 's=\.=/=g' -e 's=$$=.class=' > $(REORDER_JAR)_tmp1
 141 
 142         $(RM) $(REORDER_JAR)_tmp2
 143         $(JRE_JAVA) -classpath $(CLASSDIR) Combine                        \
 144             $(REORDER_JAR) $(REORDER_JAR)_tmp1 > $(REORDER_JAR)_tmp2
 145         $(MV) $(REORDER_JAR)_tmp2 $(REORDER_JAR)
 146         $(RM) $(REORDER_JAR)_tmp1
 147 
 148 $(CLASSDIR) :
 149         $(MKDIR) -p $(CLASSDIR)
 150 
 151 $(CLASSDIR)/%.class : tools/%.java
 152         $(JAVAC_CMD) -d $(CLASSDIR) $<
 153 $(CLASSDIR)/%.class : tests/%.java
 154         $(JAVAC_CMD) -d $(CLASSDIR) $<
 155 
 156 $(OBJDIR) :
 157         $(MKDIR) -p $(OBJDIR)
 158 
 159 
 160 MCOUNT_SRC = mcount.c
 161 MCOUNT_OBJ = $(MCOUNT_SRC:%.c=$(OBJDIR)/%.o)
 162 vpath %.c tools
 163 
 164 $(OBJDIR)/%.o : %.c tools/util-$(ARCH).il
 165         $(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $^
 166 
 167 # This library 'libmcount.so' also used by hotspot reordering.
 168 $(OBJDIR)/libmcount.so : $(MCOUNT_OBJ)
 169         $(CC) -G -mt -zdefs -o $@ $^ $(LIBDL) -lelf $(EXTRA_LIBS)
 170 
 171 # This library 'libmcount.so' also used by hotspot reordering.
 172 $(OBJDIR)/remove_mcount : remove_mcount.c
 173         $(CC) -g -o $@ $^ $(LIBDL) -lelf $(EXTRA_LIBS)
 174 
 175 
 176 # Reorder libraries.
 177 # + Delete all of the library's object files, and recompile them for profiling.
 178 # + Run the test sequence using libmcount to produce the mapfile.
 179 # + Delete all of the library's object files, and recompile them normally.
 180 
 181 $(REORDER_LIB): $(OBJDIR)/libmcount.so $(OBJDIR)/remove_mcount \
 182                 test_classes tool_classes
 183 
 184 ifeq ($(ARCH), i586)
 185         @# On Solaris-i586 we need to remove the symbol _mcount from the command
 186         $(OBJDIR)/remove_mcount $(BINDIR)/java
 187 endif
 188 
 189         $(RM) $(OUTPUTDIR)/tmp/$(LIBTMPDIR)/$(OBJDIRNAME)/*.o
 190         $(CD) $(BUILDDIR)/$(LIBBLDDIR) ; \
 191           $(MAKE) PARTIAL_GPROF=true LDNOMAP=true NO_ROBOT=true all
 192 
 193         $(RM) $(REORDER_LIB)
 194         @$(ECHO) "data = R0x2000;" > $(REORDER_LIB)
 195         @$(ECHO) "text = LOAD ?RXO;" >> $(REORDER_LIB)
 196 
 197         @# Run each of a set of tests, extract the classes required and
 198         @# append the new classes to the ClassList.
 199 
 200         for f in $(TESTS) ; do                                            \
 201             $(ECHO) Running test $$f.;                                    \
 202             $(RM) $(REORDER_LIB)_tmp1;                                    \
 203             $(ECHO) "# Test $$f" >> $(REORDER_LIB);                         \
 204             LD_PRELOAD=$(PRELOAD_DIR)/libmcount.so                        \
 205               $(SETENV)                                                   \
 206               $(JAVA_BIN) $(BOOTPATH) -classpath $(CLASSDIR) $$f          \
 207                  2> $(REORDER_LIB)_tmp1;                               \
 208             $(SED) -n -e 's=[./]*$(OUTPUTDIR)=OUTPUTDIR=' -e '/^text:/p'  \
 209                  $(REORDER_LIB)_tmp1 > $(REORDER_LIB)_tmp2;            \
 210             $(SED) -e '/^text:/d' $(REORDER_LIB)_tmp1;                    \
 211             $(JRE_JAVA) -classpath $(CLASSDIR) Combine                    \
 212                 $(REORDER_LIB) $(REORDER_LIB)_tmp2                        \
 213                  > $(REORDER_LIB)_tmp3;                                        \
 214             $(MV) $(REORDER_LIB)_tmp3 $(REORDER_LIB);                     \
 215             $(RM) $(REORDER_LIB)_tmp2;                                    \
 216             $(RM) $(REORDER_LIB)_tmp1;                                    \
 217         done
 218 
 219         @# Run SwingSet2, extract the classes required and
 220         @# append the new classes to the ClassList.
 221 
 222         @$(RM) $(REORDER_LIB)_tmp1
 223         @$(RM) $(REORDER_JAR)_tmp2
 224         @$(ECHO) "# SwingSet2" >> $(REORDER_LIB)
 225 
 226         @$(ECHO) ""
 227         @$(ECHO) ""
 228         @$(ECHO) "When SwingSet2 has finished drawing, " \
 229                  "you may terminate it (with your mouse)."
 230         @$(ECHO) "Otherwise, it should be automatically terminated in 2 minutes."
 231         @$(ECHO) ""
 232         @$(ECHO) ""
 233 
 234         LD_PRELOAD=$(PRELOAD_DIR)/libmcount.so                             \
 235           $(SETENV)                                                        \
 236           $(JAVA_BIN) $(BOOTPATH) -classpath $(CLASSDIR) MaxTime           \
 237                 $(SWINGSET2) 120  2> $(REORDER_LIB)_tmp1
 238 
 239         $(SED) -n -e 's=[./]*$(OUTPUTDIR)=OUTPUTDIR=' -e '/^text:/p'      \
 240             $(REORDER_LIB)_tmp1 > $(REORDER_LIB)_tmp2
 241         $(SED) -e '/^text:/d' $(REORDER_LIB)_tmp1
 242         $(JRE_JAVA) -classpath $(CLASSDIR) Combine                        \
 243             $(REORDER_LIB) $(REORDER_LIB)_tmp2                            \
 244              > $(REORDER_LIB)_tmp3
 245         $(MV) $(REORDER_LIB)_tmp3 $(REORDER_LIB)
 246         $(RM) $(REORDER_LIB)_tmp2
 247         $(RM) $(REORDER_LIB)_tmp1
 248 
 249         $(RM) $(OUTPUTDIR)/tmp/$(LIBTMPDIR)/$(OBJDIRNAME)/*.o
 250         $(CD) $(BUILDDIR)/$(LIBBLDDIR) ; $(MAKE) all
 251 
 252 .PHONY: test_classes tool_classes