mirror of
https://github.com/openjdk/jdk.git
synced 2026-07-28 20:03:39 +00:00
8246478: Remove src/utils/reorder
Reviewed-by: iklam
This commit is contained in:
parent
4365c2b745
commit
e1b8e91e80
@ -1,252 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation. Oracle designates this
|
||||
# particular file as subject to the "Classpath" exception as provided
|
||||
# by Oracle in the LICENSE file that accompanied this code.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
# This Makefile is intended to produce new reordering files for the
|
||||
# reordering of jar files and shared libraries. This is not part of the
|
||||
# standard build. The objects produced by this Makefile must be copied
|
||||
# into their standard locations and checked in.
|
||||
|
||||
BUILDDIR = ../..
|
||||
PACKAGE = tools.reorder
|
||||
PRODUCT = tools
|
||||
include $(BUILDDIR)/common/Defs.gmk
|
||||
|
||||
OUTDIR = $(OUTPUTDIR)/reorder
|
||||
PRELOAD_DIR = $(ABS_OUTPUTDIR)/reorder/$(ARCH)
|
||||
|
||||
ifeq ($(PLATFORM), windows)
|
||||
SEP = \\
|
||||
else
|
||||
SEP = /
|
||||
endif
|
||||
|
||||
CLASSDIR = $(OUTDIR)/classes
|
||||
OBJDIR = $(OUTDIR)/$(ARCH)
|
||||
TESTS = Null Exit Hello Sleep IntToString \
|
||||
LoadToolkit LoadFrame LoadJFrame JHello
|
||||
TEST_CLASSES = $(TESTS:%=$(CLASSDIR)/%.class)
|
||||
SWINGSET2 = $(OUTPUTDIR)/demo/jfc/SwingSet2/SwingSet2.jar
|
||||
|
||||
# Run java from the JRE image because using rt.jar requires a
|
||||
# larger list of classes, and these should appear in the list.
|
||||
# FIXUP: adding rt.jar into bootclasspath?
|
||||
JRE_LIB = $(JRE_IMAGE_DIR)/lib
|
||||
BOOTPATH = -Xbootclasspath:$(JRE_LIB)/rt.jar:$(JRE_LIB)/charsets.jar
|
||||
JRE_JAVA = $(JRE_IMAGE_DIR)/bin/java
|
||||
|
||||
JAVA_BIN = $(BINDIR)/java
|
||||
|
||||
all : jars.reorder
|
||||
|
||||
tools : $(OBJDIR) $(OBJDIR)/libmcount.so $(OBJDIR)/remove_mcount
|
||||
|
||||
copy : jars.copy
|
||||
|
||||
clean :
|
||||
$(RM) $(REORDER_JAR)
|
||||
|
||||
clobber : clean
|
||||
$(RM) -r $(OUTDIR)
|
||||
|
||||
|
||||
jars.reorder :
|
||||
$(MAKE) JARFILE=rt.jar reorder.jar
|
||||
$(MAKE) JARFILE=charsets.jar reorder.jar
|
||||
|
||||
jars.copy:
|
||||
$(CP) $(OUTDIR)/reorder_rt_jar-$(PLATFORM) reorder_rt_jar-$(PLATFORM)
|
||||
$(CP) $(OUTDIR)/reorder_charsets_jar-$(PLATFORM) reorder_charsets_jar-$(PLATFORM)
|
||||
|
||||
REORDER_JAR = $(OUTDIR)/reorder_$(subst .,_,$(JARFILE))-$(PLATFORM)
|
||||
reorder.jar : $(REORDER_JAR)
|
||||
|
||||
REORDER_LIB = $(OUTDIR)/reorder_$(subst /,_,$(LIBBLDDIR))-$(ARCH)
|
||||
reorder.lib : $(OBJDIR) $(REORDER_LIB)
|
||||
|
||||
|
||||
# This target 'test_classes' also used by hotspot reordering.
|
||||
test_classes : $(TEST_CLASSES)
|
||||
|
||||
# This target 'tool_classes' also used by hotspot reordering.
|
||||
tool_classes : $(CLASSDIR) $(CLASSDIR)/Combine.class $(CLASSDIR)/MaxTime.class
|
||||
|
||||
$(REORDER_JAR) : $(CLASSDIR) test_classes tool_classes
|
||||
$(RM) $(REORDER_JAR)
|
||||
|
||||
@$(ECHO) "# Ordered list of files to include in $(JARFILE)." > $(REORDER_JAR)
|
||||
@$(ECHO) "# This is a generated file - do not edit." >> $(REORDER_JAR)
|
||||
@$(ECHO) "#" >> $(REORDER_JAR)
|
||||
|
||||
@# Run each of a set of tests, extract the classes required and
|
||||
@# append the new classes to the ClassList.
|
||||
|
||||
@for f in $(TESTS) ; do \
|
||||
$(ECHO) Running test $$f.; \
|
||||
$(RM) $(REORDER_JAR)_tmp1; \
|
||||
echo "# Test $$f" >> $(REORDER_JAR); \
|
||||
$(JRE_JAVA) -verbose -classpath $(CLASSDIR) $$f | \
|
||||
$(SED) -n -e 's=\[Loaded \(.*\) from .*$(SEP)lib$(SEP)$(JARFILE)]=\1=p' | \
|
||||
$(SED) -e 's=\.=/=g' -e 's=$$=.class=' \
|
||||
> $(REORDER_JAR)_tmp1; \
|
||||
$(JRE_JAVA) -classpath $(CLASSDIR) Combine \
|
||||
$(REORDER_JAR) $(REORDER_JAR)_tmp1 \
|
||||
> $(REORDER_JAR)_tmp2; \
|
||||
$(MV) $(REORDER_JAR)_tmp2 $(REORDER_JAR); \
|
||||
$(RM) $(REORDER_JAR)_tmp1; \
|
||||
done
|
||||
|
||||
@# Run SwingSet2, extract the classes required and
|
||||
@# append the new classes to the ClassList.
|
||||
|
||||
@$(RM) $(REORDER_JAR)_tmp1
|
||||
@$(RM) $(REORDER_JAR)_tmp2
|
||||
@$(ECHO) "# SwingSet2" >> $(REORDER_JAR)
|
||||
|
||||
@$(ECHO) ""
|
||||
@$(ECHO) ""
|
||||
@$(ECHO) "When SwingSet2 has finished drawing, " \
|
||||
"you may terminate it (with your mouse)."
|
||||
@$(ECHO) "Otherwise, it should be automatically terminated in 2 minutes."
|
||||
@$(ECHO) ""
|
||||
@$(ECHO) ""
|
||||
|
||||
$(JRE_JAVA) -verbose -classpath $(CLASSDIR) MaxTime $(SWINGSET2) 120 \
|
||||
> $(REORDER_JAR)_tmp2
|
||||
|
||||
$(SED) -n -e 's=\[Loaded \(.*\) from .*$(SEP)lib$(SEP)$(JARFILE)]=\1=p' \
|
||||
< $(REORDER_JAR)_tmp2 | \
|
||||
$(SED) -e 's=\.=/=g' -e 's=$$=.class=' > $(REORDER_JAR)_tmp1
|
||||
|
||||
$(RM) $(REORDER_JAR)_tmp2
|
||||
$(JRE_JAVA) -classpath $(CLASSDIR) Combine \
|
||||
$(REORDER_JAR) $(REORDER_JAR)_tmp1 > $(REORDER_JAR)_tmp2
|
||||
$(MV) $(REORDER_JAR)_tmp2 $(REORDER_JAR)
|
||||
$(RM) $(REORDER_JAR)_tmp1
|
||||
|
||||
$(CLASSDIR) :
|
||||
$(MKDIR) -p $(CLASSDIR)
|
||||
|
||||
$(CLASSDIR)/%.class : tools/%.java
|
||||
$(JAVAC_CMD) -d $(CLASSDIR) $<
|
||||
$(CLASSDIR)/%.class : tests/%.java
|
||||
$(JAVAC_CMD) -d $(CLASSDIR) $<
|
||||
|
||||
$(OBJDIR) :
|
||||
$(MKDIR) -p $(OBJDIR)
|
||||
|
||||
|
||||
MCOUNT_SRC = mcount.c
|
||||
MCOUNT_OBJ = $(MCOUNT_SRC:%.c=$(OBJDIR)/%.o)
|
||||
vpath %.c tools
|
||||
|
||||
$(OBJDIR)/%.o : %.c tools/util-$(ARCH).il
|
||||
$(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $^
|
||||
|
||||
# This library 'libmcount.so' also used by hotspot reordering.
|
||||
$(OBJDIR)/libmcount.so : $(MCOUNT_OBJ)
|
||||
$(CC) -G -mt -zdefs -o $@ $^ $(LIBDL) -lelf $(EXTRA_LIBS)
|
||||
|
||||
# This library 'libmcount.so' also used by hotspot reordering.
|
||||
$(OBJDIR)/remove_mcount : remove_mcount.c
|
||||
$(CC) -g -o $@ $^ $(LIBDL) -lelf $(EXTRA_LIBS)
|
||||
|
||||
|
||||
# Reorder libraries.
|
||||
# + Delete all of the library's object files, and recompile them for profiling.
|
||||
# + Run the test sequence using libmcount to produce the mapfile.
|
||||
# + Delete all of the library's object files, and recompile them normally.
|
||||
|
||||
$(REORDER_LIB): $(OBJDIR)/libmcount.so $(OBJDIR)/remove_mcount \
|
||||
test_classes tool_classes
|
||||
|
||||
ifeq ($(ARCH), i586)
|
||||
@# On Solaris-i586 we need to remove the symbol _mcount from the command
|
||||
$(OBJDIR)/remove_mcount $(BINDIR)/java
|
||||
endif
|
||||
|
||||
$(RM) $(OUTPUTDIR)/tmp/$(LIBTMPDIR)/$(OBJDIRNAME)/*.o
|
||||
$(CD) $(BUILDDIR)/$(LIBBLDDIR) ; \
|
||||
$(MAKE) PARTIAL_GPROF=true LDNOMAP=true NO_ROBOT=true all
|
||||
|
||||
$(RM) $(REORDER_LIB)
|
||||
@$(ECHO) "data = R0x2000;" > $(REORDER_LIB)
|
||||
@$(ECHO) "text = LOAD ?RXO;" >> $(REORDER_LIB)
|
||||
|
||||
@# Run each of a set of tests, extract the classes required and
|
||||
@# append the new classes to the ClassList.
|
||||
|
||||
for f in $(TESTS) ; do \
|
||||
$(ECHO) Running test $$f.; \
|
||||
$(RM) $(REORDER_LIB)_tmp1; \
|
||||
$(ECHO) "# Test $$f" >> $(REORDER_LIB); \
|
||||
LD_PRELOAD=$(PRELOAD_DIR)/libmcount.so \
|
||||
$(SETENV) \
|
||||
$(JAVA_BIN) $(BOOTPATH) -classpath $(CLASSDIR) $$f \
|
||||
2> $(REORDER_LIB)_tmp1; \
|
||||
$(SED) -n -e 's=[./]*$(OUTPUTDIR)=OUTPUTDIR=' -e '/^text:/p' \
|
||||
$(REORDER_LIB)_tmp1 > $(REORDER_LIB)_tmp2; \
|
||||
$(SED) -e '/^text:/d' $(REORDER_LIB)_tmp1; \
|
||||
$(JRE_JAVA) -classpath $(CLASSDIR) Combine \
|
||||
$(REORDER_LIB) $(REORDER_LIB)_tmp2 \
|
||||
> $(REORDER_LIB)_tmp3; \
|
||||
$(MV) $(REORDER_LIB)_tmp3 $(REORDER_LIB); \
|
||||
$(RM) $(REORDER_LIB)_tmp2; \
|
||||
$(RM) $(REORDER_LIB)_tmp1; \
|
||||
done
|
||||
|
||||
@# Run SwingSet2, extract the classes required and
|
||||
@# append the new classes to the ClassList.
|
||||
|
||||
@$(RM) $(REORDER_LIB)_tmp1
|
||||
@$(RM) $(REORDER_JAR)_tmp2
|
||||
@$(ECHO) "# SwingSet2" >> $(REORDER_LIB)
|
||||
|
||||
@$(ECHO) ""
|
||||
@$(ECHO) ""
|
||||
@$(ECHO) "When SwingSet2 has finished drawing, " \
|
||||
"you may terminate it (with your mouse)."
|
||||
@$(ECHO) "Otherwise, it should be automatically terminated in 2 minutes."
|
||||
@$(ECHO) ""
|
||||
@$(ECHO) ""
|
||||
|
||||
LD_PRELOAD=$(PRELOAD_DIR)/libmcount.so \
|
||||
$(SETENV) \
|
||||
$(JAVA_BIN) $(BOOTPATH) -classpath $(CLASSDIR) MaxTime \
|
||||
$(SWINGSET2) 120 2> $(REORDER_LIB)_tmp1
|
||||
|
||||
$(SED) -n -e 's=[./]*$(OUTPUTDIR)=OUTPUTDIR=' -e '/^text:/p' \
|
||||
$(REORDER_LIB)_tmp1 > $(REORDER_LIB)_tmp2
|
||||
$(SED) -e '/^text:/d' $(REORDER_LIB)_tmp1
|
||||
$(JRE_JAVA) -classpath $(CLASSDIR) Combine \
|
||||
$(REORDER_LIB) $(REORDER_LIB)_tmp2 \
|
||||
> $(REORDER_LIB)_tmp3
|
||||
$(MV) $(REORDER_LIB)_tmp3 $(REORDER_LIB)
|
||||
$(RM) $(REORDER_LIB)_tmp2
|
||||
$(RM) $(REORDER_LIB)_tmp1
|
||||
|
||||
$(RM) $(OUTPUTDIR)/tmp/$(LIBTMPDIR)/$(OBJDIRNAME)/*.o
|
||||
$(CD) $(BUILDDIR)/$(LIBBLDDIR) ; $(MAKE) all
|
||||
|
||||
.PHONY: test_classes tool_classes
|
||||
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
public class Exit {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public class Hello {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.err.println("Hello");
|
||||
}
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public class IntToString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String n = "10000";
|
||||
System.err.println("Hello");
|
||||
|
||||
if (args.length == 0) {
|
||||
try {
|
||||
Thread.currentThread().sleep(Integer.parseInt(n));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.PrintStream;
|
||||
import javax.swing.*;
|
||||
|
||||
public class JHello extends JFrame {
|
||||
|
||||
JHello() {
|
||||
JLabel jlabel = new JLabel("Hello");
|
||||
jlabel.setFont(new Font("Monospaced", 0, 144));
|
||||
getContentPane().add(jlabel);
|
||||
pack();
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
new JHello().show();
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
import java.awt.Frame;
|
||||
|
||||
public class LoadFrame {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Frame().show();
|
||||
// This starts a thread which never exits - so we suicide.
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class LoadJFrame {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new JFrame().show();
|
||||
// This starts a thread which never exits - so we suicide.
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
public class LoadToolkit {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Toolkit kit = Toolkit.getDefaultToolkit();
|
||||
// This starts a thread which never exits - so we suicide.
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public class Null {
|
||||
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
public class Sleep {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// What is loaded on a sleep?
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
// Append files to one another without duplicating any lines.
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Combine {
|
||||
|
||||
private static HashMap map = new HashMap(10007);
|
||||
|
||||
private static void appendFile(String fileName, boolean keep) {
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new FileReader(fileName));
|
||||
|
||||
// Read a line at a time. If the line does not appear in the
|
||||
// hashmap, print it and add it to the hashmap, so that it will
|
||||
// not be repeated.
|
||||
|
||||
lineLoop:
|
||||
while (true) {
|
||||
String line = br.readLine();
|
||||
if (line == null)
|
||||
break;
|
||||
if (keep || !map.containsKey(line)) {
|
||||
System.out.println(line);
|
||||
map.put(line,line);
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
if (args.length < 2) {
|
||||
System.err.println("Usage: java Combine file1 file2 ...");
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
for (int i = 0; i < args.length; ++i)
|
||||
appendFile(args[i], i == 0);
|
||||
}
|
||||
}
|
||||
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/** Run an application (from a jar file) and terminate it after a given
|
||||
* number of seconds.
|
||||
*/
|
||||
|
||||
public class MaxTime {
|
||||
|
||||
private static boolean debugFlag = false;
|
||||
|
||||
|
||||
private static void debug(String s) {
|
||||
if (debugFlag) {
|
||||
System.err.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void usage() {
|
||||
System.err.println(
|
||||
"Usage:\n" +
|
||||
" java MaxTime <jarfile> <timeout>\n" +
|
||||
"\n" +
|
||||
" <jarfile> is a jar file specifying an application to run\n" +
|
||||
" <timeout> is an integer number of seconds to allow the app to run." );
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
int timeoutPeriod = 0;
|
||||
String mainClass = null;
|
||||
|
||||
if (args.length != 2)
|
||||
usage();
|
||||
|
||||
// Identify the timeout value.
|
||||
try {
|
||||
timeoutPeriod = Integer.parseInt(args[1]);
|
||||
} catch (Exception e) {
|
||||
usage();
|
||||
}
|
||||
|
||||
// Identify the application's main class.
|
||||
try {
|
||||
mainClass = new JarFile(args[0]).getManifest()
|
||||
.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println("Can't find " + args[0]);
|
||||
System.exit(1);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
// Set the exit timer.
|
||||
final int timeout = timeoutPeriod * 1000;
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
debug("Before timeout!");
|
||||
Thread.sleep(timeout);
|
||||
debug("After timeout!");
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
debug("Exit caused by timeout!");
|
||||
System.exit(0);
|
||||
}
|
||||
}.start();
|
||||
|
||||
|
||||
// Start up the app.
|
||||
try {
|
||||
ClassLoader cl = new URLClassLoader(
|
||||
new URL[] {new URL("file:"+args[0])});
|
||||
Class clazz = cl.loadClass(mainClass);
|
||||
String[] objs = new String[0];
|
||||
Method mainMethod = clazz.getMethod("main", new Class[]{objs.getClass()});
|
||||
mainMethod.invoke(null, new Object[]{objs});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,621 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <dlfcn.h>
|
||||
#include <libelf.h>
|
||||
#include <strings.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/param.h>
|
||||
#include <stdlib.h>
|
||||
#include <thread.h>
|
||||
#include <synch.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
/* 32/64 bit build issues. */
|
||||
|
||||
#ifdef _LP64
|
||||
#define ElfXX_Sym Elf64_Sym
|
||||
#define ElfXX_Ehdr Elf64_Ehdr
|
||||
#define ElfXX_Shdr Elf64_Shdr
|
||||
#define elfXX_getehdr elf64_getehdr
|
||||
#define ElfXX_Addr Elf64_Addr
|
||||
#define ELFXX_ST_TYPE ELF64_ST_TYPE
|
||||
#define ELFXX_ST_BIND ELF64_ST_BIND
|
||||
#define elfXX_getshdr elf64_getshdr
|
||||
#else
|
||||
#define ElfXX_Sym Elf32_Sym
|
||||
#define ElfXX_Ehdr Elf32_Ehdr
|
||||
#define ElfXX_Shdr Elf32_Shdr
|
||||
#define elfXX_getehdr elf32_getehdr
|
||||
#define ElfXX_Addr Elf32_Addr
|
||||
#define ELFXX_ST_TYPE ELF32_ST_TYPE
|
||||
#define ELFXX_ST_BIND ELF32_ST_BIND
|
||||
#define elfXX_getshdr elf32_getshdr
|
||||
#endif
|
||||
|
||||
extern void *_getReturnAddr(void);
|
||||
|
||||
|
||||
|
||||
typedef struct StabEntry {
|
||||
unsigned n_strx;
|
||||
unsigned char n_type;
|
||||
char n_other;
|
||||
short n_desc;
|
||||
unsigned n_value;
|
||||
} StabEntry;
|
||||
|
||||
|
||||
typedef struct SymChain {
|
||||
struct SymChain *next;
|
||||
ElfXX_Sym *sym;
|
||||
} SymChain;
|
||||
|
||||
|
||||
typedef struct ObjFileList {
|
||||
struct ObjFileList *next;
|
||||
const char *objFileName;
|
||||
int nameLen;
|
||||
} ObjFileList;
|
||||
|
||||
|
||||
typedef struct ElfInfo {
|
||||
const char *fullName;
|
||||
const char *baseName;
|
||||
FILE *outFile;
|
||||
int fd;
|
||||
Elf *elf;
|
||||
Elf_Data *sectionStringData;
|
||||
Elf_Data *symData;
|
||||
Elf_Data *symStringData;
|
||||
int symCount;
|
||||
SymChain *symChainHead;
|
||||
Elf_Data *stabData;
|
||||
Elf_Data *stabStringData;
|
||||
int stabCount;
|
||||
ObjFileList *objFileList;
|
||||
} ElfInfo;
|
||||
|
||||
|
||||
|
||||
#define COUNT_BUF_SIZE (16*1024*1024)
|
||||
|
||||
#define ENTRY_CHAIN_BUCKETS 4999
|
||||
|
||||
static int *countBuf;
|
||||
static void *textOffset;
|
||||
static const char *libFileName;
|
||||
|
||||
|
||||
|
||||
static void fail(const char *err, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, err);
|
||||
vfprintf(stderr, err, ap);
|
||||
fflush(stderr);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const char *getSymString(ElfInfo *elfInfo, int index)
|
||||
{
|
||||
return (const char *)elfInfo->symStringData->d_buf + index;
|
||||
}
|
||||
|
||||
|
||||
static const char *getStabString(ElfInfo *elfInfo, int index)
|
||||
{
|
||||
return (const char *)elfInfo->stabStringData->d_buf + index;
|
||||
}
|
||||
|
||||
|
||||
static const char *getSectionString(ElfInfo *elfInfo, int index)
|
||||
{
|
||||
return (const char *)elfInfo->sectionStringData->d_buf + index;
|
||||
}
|
||||
|
||||
|
||||
static const char *makeObjFileList(ElfInfo *elfInfo)
|
||||
{
|
||||
int i;
|
||||
const char *file;
|
||||
unsigned offset, lastOffset;
|
||||
ObjFileList *objFileList;
|
||||
|
||||
file = NULL;
|
||||
offset = lastOffset = 0;
|
||||
for (i = 0; i < elfInfo->stabCount; ++i) {
|
||||
StabEntry *stab = ((StabEntry *)elfInfo->stabData->d_buf) + i;
|
||||
|
||||
if (stab->n_type == 0 /* N_UNDEF */) {
|
||||
offset = lastOffset;
|
||||
lastOffset += stab-> n_value;
|
||||
}
|
||||
else if (stab->n_type == 0x38 /* N_OBJ */) {
|
||||
file = getStabString(elfInfo, stab->n_strx + offset);
|
||||
objFileList = (ObjFileList *)malloc(sizeof (ObjFileList));
|
||||
objFileList->objFileName = file;
|
||||
/*fprintf(stderr,"new obj file %s.\n", file);*/
|
||||
objFileList->nameLen = strlen(file);
|
||||
objFileList->next = elfInfo->objFileList;
|
||||
elfInfo->objFileList = objFileList;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static ElfInfo *createElfInfo(const char *fullName)
|
||||
{
|
||||
ElfInfo *elfInfo;
|
||||
ElfXX_Ehdr *ehdr;
|
||||
Elf_Scn *sectionStringSection;
|
||||
Elf_Scn *stringSection;
|
||||
Elf_Scn *symSection;
|
||||
ElfXX_Shdr *symHeader;
|
||||
Elf_Scn *stabSection;
|
||||
ElfXX_Shdr *stabHeader;
|
||||
ElfXX_Shdr *stringHeader;
|
||||
Elf *elf;
|
||||
const char *p;
|
||||
|
||||
/*fprintf(stderr, "# mapfile info for %s.\n", fullName);*/
|
||||
elfInfo = (ElfInfo *)malloc(sizeof (ElfInfo));
|
||||
memset(elfInfo, 0, sizeof (ElfInfo));
|
||||
elfInfo->fullName = strdup(fullName);
|
||||
p = rindex(elfInfo->fullName, '/');
|
||||
elfInfo->baseName = (p == NULL) ? elfInfo->fullName : p + 1;
|
||||
|
||||
/* Open the ELF file. Get section headers. */
|
||||
|
||||
elf_version(EV_CURRENT);
|
||||
elfInfo->fd = open(fullName, O_RDONLY);
|
||||
if (elfInfo->fd < 0)
|
||||
fail("Unable to open ELF file %s.\n", fullName);
|
||||
elf = elf_begin(elfInfo->fd, ELF_C_READ, (Elf *)0);
|
||||
if (elf == NULL)
|
||||
fail("elf_begin failed.\n");
|
||||
ehdr = elfXX_getehdr(elf);
|
||||
sectionStringSection = elf_getscn(elf, ehdr->e_shstrndx);
|
||||
elfInfo->sectionStringData = elf_getdata(sectionStringSection, NULL);
|
||||
|
||||
/* Find the symbol table section. */
|
||||
|
||||
symSection = NULL;
|
||||
while ((symSection = elf_nextscn(elf, symSection)) != NULL) {
|
||||
symHeader = elfXX_getshdr(symSection);
|
||||
p = getSectionString(elfInfo, symHeader->sh_name);
|
||||
if (strcmp(p, ".symtab") == 0)
|
||||
break;
|
||||
}
|
||||
if (symSection == NULL)
|
||||
fail("Unable to find symbol table.\n");
|
||||
|
||||
elfInfo->symData = elf_getdata(symSection, NULL);
|
||||
elfInfo->symCount = elfInfo->symData->d_size / sizeof (ElfXX_Sym);
|
||||
|
||||
/* Find the string section. */
|
||||
|
||||
stringSection = NULL;
|
||||
while ((stringSection = elf_nextscn(elf, stringSection)) != NULL) {
|
||||
stringHeader = elfXX_getshdr(stringSection);
|
||||
p = getSectionString(elfInfo, stringHeader->sh_name);
|
||||
if (strcmp(p, ".strtab") == 0)
|
||||
break;
|
||||
}
|
||||
if (stringSection == NULL)
|
||||
fail("Unable to find string table.\n");
|
||||
|
||||
elfInfo->symStringData = elf_getdata(stringSection, NULL);
|
||||
elfInfo->symChainHead = NULL;
|
||||
|
||||
/* Find the stab section. */
|
||||
|
||||
stabSection = NULL;
|
||||
while ((stabSection = elf_nextscn(elf, stabSection)) != NULL) {
|
||||
stabHeader = elfXX_getshdr(stabSection);
|
||||
p = getSectionString(elfInfo, stabHeader->sh_name);
|
||||
if (strcmp(p, ".stab.index") == 0)
|
||||
break;
|
||||
}
|
||||
if (stabSection == NULL)
|
||||
fail("Unable to find .stab.index.\n");
|
||||
|
||||
elfInfo->stabData = elf_getdata(stabSection, NULL);
|
||||
elfInfo->stabCount = elfInfo->stabData->d_size / sizeof (StabEntry);
|
||||
|
||||
/* Find the string section. */
|
||||
|
||||
stringSection = NULL;
|
||||
while ((stringSection = elf_nextscn(elf, stringSection)) != NULL) {
|
||||
stringHeader = elfXX_getshdr(stringSection);
|
||||
p = getSectionString(elfInfo, stringHeader->sh_name);
|
||||
if (strcmp(p, ".stab.indexstr") == 0)
|
||||
break;
|
||||
}
|
||||
if (stringSection == NULL)
|
||||
fail("Unable to find .stab.indexstr table.\n");
|
||||
|
||||
elfInfo->stabStringData = elf_getdata(stringSection, NULL);
|
||||
makeObjFileList(elfInfo);
|
||||
|
||||
return elfInfo;
|
||||
}
|
||||
|
||||
|
||||
static const char *identifyFile(ElfInfo *elfInfo, const char *name)
|
||||
{
|
||||
int i;
|
||||
const char *file;
|
||||
const char *sourceFile;
|
||||
unsigned offset, lastOffset;
|
||||
const char *lastOptions;
|
||||
char *buf;
|
||||
|
||||
file = NULL;
|
||||
lastOptions = NULL;
|
||||
offset = lastOffset = 0;
|
||||
for (i = 0; i < elfInfo->stabCount; ++i) {
|
||||
StabEntry *stab = ((StabEntry *)elfInfo->stabData->d_buf) + i;
|
||||
|
||||
if (stab->n_type == 0 /* N_UNDEF */) {
|
||||
offset = lastOffset;
|
||||
lastOffset += stab-> n_value;
|
||||
file = NULL; /* C++ output files seem not to have N_OBJ fields.*/
|
||||
lastOptions = NULL;
|
||||
sourceFile = getStabString(elfInfo, stab->n_strx + offset);
|
||||
}
|
||||
else if (stab->n_type == 0x24 /* N_FUN */) {
|
||||
const char *stabName;
|
||||
char *p1, *p2;
|
||||
|
||||
stabName = getStabString(elfInfo, stab->n_strx + offset);
|
||||
if (strcmp (stabName, name) == 0) {
|
||||
|
||||
if (file != NULL)
|
||||
return file;
|
||||
|
||||
if (lastOptions == NULL)
|
||||
return NULL;
|
||||
|
||||
p1 = strstr(lastOptions, ";ptr");
|
||||
if (p1 == NULL)
|
||||
return NULL;
|
||||
p1 += 4;
|
||||
p2 = index(p1, ';');
|
||||
if (p2 == NULL)
|
||||
return NULL;
|
||||
|
||||
buf = (char *)malloc(p2 - p1 + strlen(sourceFile) + 10);
|
||||
strncpy(buf, p1, p2 - p1);
|
||||
buf[p2-p1] = '/';
|
||||
strcpy(buf + (p2 - p1) + 1, sourceFile);
|
||||
p1 = rindex(buf, '.');
|
||||
if (p1 == NULL)
|
||||
return NULL;
|
||||
p1[1] = 'o';
|
||||
p1[2] = '\0';
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
else if (stab->n_type == 0x3c /* N_OPT */) {
|
||||
lastOptions = getStabString(elfInfo, stab->n_strx + offset);
|
||||
}
|
||||
else if (stab->n_type == 0x38 /* N_OBJ */) {
|
||||
file = getStabString(elfInfo, stab->n_strx + offset);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static const char *checkObjFileList(ElfInfo *elfInfo, const char *file) {
|
||||
ObjFileList *objFileList;
|
||||
int len = strlen(file);
|
||||
int nameLen;
|
||||
const char *objFileName;
|
||||
|
||||
/*fprintf(stderr, "checkObjFileList(%s).\n", file);*/
|
||||
for (objFileList = elfInfo->objFileList; objFileList != NULL;
|
||||
objFileList = objFileList->next) {
|
||||
|
||||
objFileName = objFileList->objFileName;
|
||||
nameLen = objFileList->nameLen;
|
||||
if (strcmp(objFileName +nameLen - len, file) != 0)
|
||||
continue;
|
||||
|
||||
if (len == nameLen)
|
||||
return file;
|
||||
|
||||
if (len > nameLen)
|
||||
continue;
|
||||
|
||||
if (*(objFileName + nameLen - len - 1) == '/')
|
||||
return objFileName;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
static void identifySymbol(ElfInfo *elfInfo, ElfXX_Addr value, int count)
|
||||
{
|
||||
int i;
|
||||
ElfXX_Sym *bestFunc = NULL;
|
||||
ElfXX_Sym *bestFile = NULL;
|
||||
ElfXX_Sym *lastFile = NULL;
|
||||
char fileName[MAXPATHLEN];
|
||||
char buf[4096];
|
||||
const char *file;
|
||||
SymChain *chain;
|
||||
const char *format;
|
||||
|
||||
for (i = 0; i < elfInfo->symCount; ++i) {
|
||||
ElfXX_Sym *sym = ((ElfXX_Sym *)elfInfo->symData->d_buf) + i;
|
||||
if (ELFXX_ST_TYPE(sym->st_info) == STT_FUNC) {
|
||||
|
||||
if (sym->st_shndx == SHN_UNDEF)
|
||||
continue;
|
||||
|
||||
if (sym->st_value > value)
|
||||
continue;
|
||||
|
||||
if (bestFunc != NULL) {
|
||||
|
||||
if (sym->st_value < bestFunc->st_value)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* If we have two symbols of equal value, we have a problem -
|
||||
* we must pick the "right" one, which is the one the compiler
|
||||
* used to generate the section name with -xF.
|
||||
*
|
||||
* The compiler has the nasty habit of generating two
|
||||
* mangled names for some C++ functions.
|
||||
*
|
||||
* Try - picking the shortest name.
|
||||
*/
|
||||
|
||||
if (sym->st_value == bestFunc->st_value) {
|
||||
if (strlen(getSymString(elfInfo, bestFunc->st_name)) <
|
||||
strlen(getSymString(elfInfo, sym->st_name)))
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
bestFunc = sym;
|
||||
bestFile = lastFile;
|
||||
}
|
||||
else if (ELFXX_ST_TYPE(sym->st_info) == STT_FILE) {
|
||||
lastFile = sym;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestFunc == NULL)
|
||||
fail("Unable to find symbol for address 0x%x.\n", value);
|
||||
|
||||
for (chain = elfInfo->symChainHead; chain != NULL; chain = chain->next) {
|
||||
if (chain->sym == bestFunc)
|
||||
return;
|
||||
}
|
||||
chain = (SymChain *)malloc(sizeof (SymChain));
|
||||
chain->sym = bestFunc;
|
||||
chain->next = elfInfo->symChainHead;
|
||||
elfInfo->symChainHead = chain;
|
||||
|
||||
|
||||
if (ELFXX_ST_BIND(bestFunc->st_info) == STB_GLOBAL)
|
||||
file = "";
|
||||
else {
|
||||
const char *name = getSymString(elfInfo, bestFunc->st_name);
|
||||
file = identifyFile(elfInfo, name);
|
||||
if (file == NULL) {
|
||||
if (bestFile == NULL) {
|
||||
file = "notFound";
|
||||
fail("Failed to identify %s.\n", name);
|
||||
} else {
|
||||
char *suffix;
|
||||
fileName[0] = ':';
|
||||
fileName[1] = ' ';
|
||||
file = getSymString(elfInfo, bestFile->st_name);
|
||||
strncpy(fileName+2, file, MAXPATHLEN-3);
|
||||
suffix = rindex(fileName, '.');
|
||||
if (suffix == NULL)
|
||||
fail("no file name suffix?");
|
||||
suffix[1] = 'o';
|
||||
suffix[2] = '\0';
|
||||
|
||||
file = checkObjFileList(elfInfo, fileName+2);
|
||||
if (file != fileName+2)
|
||||
strncpy(fileName+2, file, MAXPATHLEN-3);
|
||||
|
||||
file = fileName;
|
||||
}
|
||||
} else {
|
||||
fileName[0] = ':';
|
||||
fileName[1] = ' ';
|
||||
strncpy(fileName + 2, file, MAXPATHLEN-3);
|
||||
file = fileName;
|
||||
}
|
||||
}
|
||||
format = "text: .text%%%s%s;\n";
|
||||
i = snprintf(buf, sizeof buf, format,
|
||||
bestFunc ? getSymString(elfInfo, bestFunc->st_name) : "notFound",
|
||||
file);
|
||||
write(2, buf, i);
|
||||
}
|
||||
|
||||
|
||||
static mutex_t mutex;
|
||||
static int orderByCount = FALSE;
|
||||
|
||||
|
||||
static void init_mcount(void)
|
||||
{
|
||||
mutex_init(&mutex, USYNC_THREAD, NULL);
|
||||
}
|
||||
|
||||
#pragma init(init_mcount)
|
||||
|
||||
|
||||
typedef struct CountAddrPair {
|
||||
int count;
|
||||
unsigned int addr;
|
||||
} CountAddrPair;
|
||||
|
||||
|
||||
static int compareCounts(const void *a, const void *b) {
|
||||
return ((CountAddrPair *)b)->count - ((CountAddrPair *)a)->count;
|
||||
}
|
||||
|
||||
static int compareCountsReverse(const void *a, const void *b) {
|
||||
return ((CountAddrPair *)a)->count - ((CountAddrPair *)b)->count;
|
||||
}
|
||||
|
||||
|
||||
static void doCounts(void) {
|
||||
unsigned int i;
|
||||
int n;
|
||||
int nMethods;
|
||||
int nMethods2;
|
||||
CountAddrPair *pairs;
|
||||
ElfInfo *elfInfo;
|
||||
|
||||
elfInfo = createElfInfo(libFileName);
|
||||
|
||||
nMethods = 0;
|
||||
for (i = 0; i < COUNT_BUF_SIZE >> 2; ++i) {
|
||||
n = countBuf[i];
|
||||
if (n > 0)
|
||||
++nMethods;
|
||||
}
|
||||
pairs = (CountAddrPair *)malloc(sizeof(CountAddrPair) * nMethods);
|
||||
nMethods2 = 0;
|
||||
for (i = 0; i < COUNT_BUF_SIZE >> 2; ++i) {
|
||||
n = countBuf[i];
|
||||
if (n > 0) {
|
||||
pairs[nMethods2].count = n;
|
||||
pairs[nMethods2].addr = i << 2;
|
||||
++nMethods2;
|
||||
if (nMethods2 > nMethods) {
|
||||
fprintf(stderr, "Number of methods detected increased after"
|
||||
" the atexit call.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (orderByCount) {
|
||||
qsort(pairs, nMethods, sizeof pairs[0], &compareCounts);
|
||||
for (i = 0; i < nMethods; ++i) {
|
||||
identifySymbol(elfInfo, pairs[i].addr, pairs[i].count);
|
||||
}
|
||||
}
|
||||
else {
|
||||
qsort(pairs, nMethods, sizeof pairs[0], &compareCountsReverse);
|
||||
for (i = 0; i < nMethods; ++i) {
|
||||
identifySymbol(elfInfo, pairs[i].addr, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void __mcount(void *i0)
|
||||
{
|
||||
Dl_info info;
|
||||
unsigned int offset;
|
||||
int *p;
|
||||
static int callsCounted = 0;
|
||||
static int initialized = FALSE;
|
||||
|
||||
if (!initialized) {
|
||||
dladdr(i0, &info);
|
||||
libFileName = info.dli_fname;
|
||||
#if 0
|
||||
fprintf(stderr, "Profiling %s\n", libFileName);
|
||||
#endif
|
||||
textOffset = info.dli_fbase;
|
||||
if (getenv("MCOUNT_ORDER_BY_COUNT") != NULL) {
|
||||
orderByCount = TRUE;
|
||||
}
|
||||
countBuf = (int *)malloc(COUNT_BUF_SIZE);
|
||||
memset(countBuf, 0, COUNT_BUF_SIZE);
|
||||
atexit(&doCounts);
|
||||
initialized = TRUE;
|
||||
}
|
||||
|
||||
if ((uintptr_t)i0 < (uintptr_t)textOffset) {
|
||||
fprintf(stderr, "mcount: function being profiled out of range????\n");
|
||||
fprintf(stderr, " profiling more than one library at once????\n");
|
||||
#if 0
|
||||
dladdr(i0, &info);
|
||||
fprintf(stderr, "Problem with %s in %s ???\n",
|
||||
info.dli_sname, info.dli_fname);
|
||||
#endif
|
||||
fflush(stderr);
|
||||
exit(666);
|
||||
}
|
||||
offset = ((uintptr_t)i0) - ((uintptr_t)textOffset);
|
||||
if (offset > COUNT_BUF_SIZE) {
|
||||
fprintf(stderr, "mcount: internal buffer too small for test.\n");
|
||||
fprintf(stderr, " or function being profiled out of range????\n");
|
||||
fprintf(stderr, " or profiling more than one library at once????\n");
|
||||
#if 0
|
||||
dladdr(i0, &info);
|
||||
fprintf(stderr, "Problem with %s in %s ???\n",
|
||||
info.dli_sname, info.dli_fname);
|
||||
#endif
|
||||
fflush(stderr);
|
||||
exit(666);
|
||||
}
|
||||
|
||||
p = &countBuf[offset >>2];
|
||||
if (orderByCount) {
|
||||
++*p;
|
||||
}
|
||||
else {
|
||||
if (*p == 0) {
|
||||
*p = ++callsCounted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void _mcount(void)
|
||||
{
|
||||
__mcount(_getReturnAddr());
|
||||
}
|
||||
|
||||
|
||||
void mcount(void)
|
||||
{
|
||||
__mcount(_getReturnAddr());
|
||||
}
|
||||
@ -1,184 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <dlfcn.h>
|
||||
#include <libelf.h>
|
||||
#include <strings.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/param.h>
|
||||
#include <stdlib.h>
|
||||
#include <thread.h>
|
||||
#include <synch.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
|
||||
static void fail(const char *err, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, err);
|
||||
vfprintf(stderr, err, ap);
|
||||
fflush(stderr);
|
||||
va_end(ap);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
|
||||
static Elf_Scn *find_section(Elf *elf, Elf_Data *sectionStringData,
|
||||
const char *name)
|
||||
{
|
||||
Elf_Scn *result = NULL;
|
||||
Elf32_Shdr *symHeader;
|
||||
const char *p;
|
||||
|
||||
while ((result = elf_nextscn(elf, result)) != NULL) {
|
||||
symHeader = elf32_getshdr(result);
|
||||
p = (const char *)(sectionStringData->d_buf) + symHeader->sh_name;
|
||||
if (strcmp(p, name) == 0)
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static void trash_mcount(int count, Elf_Data *data, Elf_Data *stringData)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
Elf32_Sym *sym = ((Elf32_Sym *)data->d_buf) + i;
|
||||
char *name = (char *)stringData->d_buf + sym->st_name;
|
||||
|
||||
if (strcmp(name, "_mcount") == 0) {
|
||||
name[6] = 'T';
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i < count)
|
||||
printf("Symbol _mcount found and changed.\n");
|
||||
else
|
||||
printf("Symbol _mcount not found.\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* In the executable program named as the sole command line argument, find
|
||||
* the symbol _mcount, if present, and change its name to something
|
||||
* different. The symbol _mcount is included in Solaris/x86 programs by
|
||||
* the compilers, and its presence prevents preloaded modules from
|
||||
* supplying a custom implementation of that method.
|
||||
*/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Elf32_Ehdr *ehdr;
|
||||
Elf_Scn *sectionStringSection;
|
||||
Elf_Scn *stringSection;
|
||||
Elf_Scn *dynStringSection;
|
||||
Elf_Scn *symSection;
|
||||
Elf_Scn *dynSymSection;
|
||||
Elf32_Shdr *symHeader;
|
||||
Elf32_Shdr *dynSymHeader;
|
||||
Elf32_Shdr *dynStringHeader;
|
||||
Elf32_Shdr *stringHeader;
|
||||
Elf *elf;
|
||||
const char *p;
|
||||
int i;
|
||||
const char *fullName;
|
||||
int fd;
|
||||
Elf_Data *sectionStringData;
|
||||
Elf_Data *symData;
|
||||
Elf_Data *dynSymData;
|
||||
Elf_Data *symStringData;
|
||||
Elf_Data *dynSymStringData;
|
||||
int symCount;
|
||||
int dynSymCount;
|
||||
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage:\n"
|
||||
"\t%s <file>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fullName = argv[1];
|
||||
|
||||
/* Open the ELF file. Get section headers. */
|
||||
|
||||
elf_version(EV_CURRENT);
|
||||
fd = open(fullName, O_RDWR);
|
||||
if (fd < 0)
|
||||
fail("Unable to open ELF file %s.\n", fullName);
|
||||
elf = elf_begin(fd, ELF_C_RDWR, (Elf *)0);
|
||||
if (elf == NULL)
|
||||
fail("elf_begin failed.\n");
|
||||
ehdr = elf32_getehdr(elf);
|
||||
sectionStringSection = elf_getscn(elf, ehdr->e_shstrndx);
|
||||
sectionStringData = elf_getdata(sectionStringSection, NULL);
|
||||
|
||||
/* Find the symbol table section. */
|
||||
|
||||
symSection = find_section(elf, sectionStringData, ".symtab");
|
||||
if (symSection != NULL) {
|
||||
symData = elf_getdata(symSection, NULL);
|
||||
symCount = symData->d_size / sizeof (Elf32_Sym);
|
||||
|
||||
/* Find the string section, trash the _mcount symbol. */
|
||||
|
||||
stringSection = find_section(elf, sectionStringData, ".strtab");
|
||||
if (stringSection == NULL)
|
||||
fail("Unable to find string table.\n");
|
||||
symStringData = elf_getdata(stringSection, NULL);
|
||||
trash_mcount(symCount, symData, symStringData);
|
||||
} else {
|
||||
fprintf(stderr, "Unable to find symbol table.\n");
|
||||
}
|
||||
|
||||
/* Find the dynamic symbol table section. */
|
||||
|
||||
dynSymSection = find_section(elf, sectionStringData, ".dynsym");
|
||||
if (dynSymSection != NULL) {
|
||||
dynSymData = elf_getdata(dynSymSection, NULL);
|
||||
dynSymCount = dynSymData->d_size / sizeof (Elf32_Sym);
|
||||
|
||||
/* Find the dynamic string section, trash the _mcount symbol. */
|
||||
|
||||
dynStringSection = find_section(elf, sectionStringData, ".dynstr");
|
||||
if (dynStringSection == NULL)
|
||||
fail("Unable to find dynamic string table.\n");
|
||||
dynSymStringData = elf_getdata(dynStringSection, NULL);
|
||||
trash_mcount(dynSymCount, dynSymData, dynSymStringData);
|
||||
} else {
|
||||
fail("Unable to find dynamic symbol table.\n");
|
||||
}
|
||||
|
||||
elf_update(elf, ELF_C_WRITE);
|
||||
elf_end(elf);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
|
||||
.inline _getReturnAddr,0
|
||||
movl 4(%ebp), %eax
|
||||
.end
|
||||
Loading…
x
Reference in New Issue
Block a user