cd6d4007aa
libjava/ChangeLog: 2008-10-21 Andrew John Hughes <gnu_andrew@member.fsf.org> * sources.am, Makfile.in: Regenerate. 2008-10-17 Matthias Klose <doko@ubuntu.com> * configure.ac: Fix bashisms. * configure: Regenerate. 2008-10-15 Matthias Klose <doko@ubuntu.com> * configure.ac: Disable build of gjdoc, if configured without --with-antlr-jar or if no antlr.jar found. * configure: Regenerate. 2008-10-09 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/configure.ac, * classpath/m4/ac_prog_antlr.m4, * classpath/m4/ac_prog_java.m4, * classpath/tools/Makefile.am: Ported --regen-gjdoc-parser patch and cantlr support from GNU Classpath. 2008-10-06 Andrew Haley <aph@redhat.com> * java/lang/Thread.java (Thread): Always create the ThreadLocalMap when creating a thread. (getThreadLocals) Don't lazily create the ThreadLocalMap. 2008-09-28 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/java/lang/ThreadLocalMap.java, * java/lang/ThreadLocalMap$Entry.h, * java/lang/ThreadLocalMap.h, * lib/java/lang/ThreadLocalMap.class, * lib/java/lang/ThreadLocalMap$Entry.class: Add the new files for the ThreadLocal patch. 2008-09-28 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/ChangeLog, * classpath/java/lang/InheritableThreadLocal.java, * classpath/java/lang/Thread.java, * classpath/java/lang/ThreadLocal.java: Merge Daniel Frampton's ThreadLocal patch. * gcj/javaprims.h: Updated. * java/lang/Thread.h: Regenerated. * java/lang/Thread.java: Replace WeakIdentityHashMap with ThreadLocalMap. (getThreadLocals()): Likewise. * java/lang/ThreadLocal.h: Regenerated. * java/lang/ThreadLocal.java: (computeNextHash()): New method. (ThreadLocal()): Initialise fastHash. (internalGet()): Updated to match Classpath's get(). (internalSet(Object)): Likewise for set(Object). (internalRemove()): Likewise for remove(). 2008-09-25 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/configure, * classpath/configure.ac: Resynchronise with Classpath's configure. * classpath/examples/Makefile.in: Add equivalent support for building as in tools/Makefile.in. * classpath/java/nio/Buffer.java, * classpath/java/nio/ByteBuffer.java, * classpath/java/nio/ByteBufferImpl.java, * classpath/java/nio/CharBuffer.java, * classpath/java/nio/CharBufferImpl.java, * classpath/java/nio/CharSequenceBuffer.java, * classpath/java/nio/CharViewBufferImpl.java, * classpath/java/nio/DirectByteBufferImpl.java, * classpath/java/nio/DoubleBuffer.java, * classpath/java/nio/DoubleBufferImpl.java, * classpath/java/nio/DoubleViewBufferImpl.java, * classpath/java/nio/FloatBuffer.java, * classpath/java/nio/FloatBufferImpl.java, * classpath/java/nio/FloatViewBufferImpl.java, * classpath/java/nio/IntBuffer.java, * classpath/java/nio/IntBufferImpl.java, * classpath/java/nio/IntViewBufferImpl.java, * classpath/java/nio/LongBuffer.java, * classpath/java/nio/LongBufferImpl.java, * classpath/java/nio/LongViewBufferImpl.java, * classpath/java/nio/MappedByteBuffer.java, * classpath/java/nio/MappedByteBufferImpl.java, * classpath/java/nio/ShortBuffer.java, * classpath/java/nio/ShortBufferImpl.java, * classpath/java/nio/ShortViewBufferImpl.java: Replace use of gnu.classpath.Pointer with gnu.gcj.RawData, and fix some formatting issues. * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaLexer.java, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaLexer.smap, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaRecognizer.java, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaRecognizer.smap, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaTokenTypes.java, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaTokenTypes.txt: Regenerated (later version of antlr). * java/nio/Buffer.h: Regenerated. * java/nio/Buffer.java: Ported changes from Classpath. * java/nio/ByteBuffer.h, * java/nio/CharBuffer.h: Regenerated. * java/nio/DirectByteBufferImpl.java: Ported changes from Classpath. * java/nio/DoubleBuffer.h, * java/nio/FloatBuffer.h, * java/nio/IntBuffer.h, * java/nio/LongBuffer.h, * java/nio/MappedByteBuffer.h, * java/nio/MappedByteBufferImpl.h: Regenerated. * java/nio/MappedByteBufferImpl.java: Ported changes from Classpath. * java/nio/ShortBuffer.h: Regenerated. 2008-09-24 Matthias Klose <doko@ubuntu.com> * configure.ac: Search for antlr.jar, if not configured. * configure: Regenerate. 2008-09-24 Matthias Klose <doko@ubuntu.com> * Makefile.am: Build a gjdoc binary, if enabled. * configure.ac: Add options --disable-gjdoc, --with-antlr-jar=file. * Makefile.in, */Makefile.in, configure: Regenerate. 2008-09-22 Andrew Haley <aph@redhat.com> * java/lang/String.java (toString(char[], int, int)): New method. 2008-09-14 Matthias Klose <doko@ubuntu.com> Import GNU Classpath (libgcj-import-20080914). * Regenerate class and header files. * Regenerate auto* files. * configure.ac: Don't pass --disable-gjdoc to classpath. * sources.am: Regenerated. * HACKING: Mention to build gjdoc in maintainer builds. * gnu/classpath/Configuration.java: Update classpath version. * gcj/javaprims.h: Update. 2008-09-08 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.am: Replace natStringBuffer.cc and natStringBuilder.cc with natAbstractStringBuffer.cc. * Makefile.in: Regenerated. * java/lang/AbstractStringBuffer.java: (append(int)): Made native. (regionMatches(int,String)): Likewise. * java/lang/StringBuffer.h: Regenerated. * java/lang/StringBuffer.java: Remerged with GNU Classpath. * java/lang/StringBuilder.h: Regenerated. * java/lang/StringBuilder.java: Remerged with GNU Classpath. * java/lang/natAbstractStringBuffer.cc: Provide common native methods for StringBuffer and StringBuilder. * java/lang/natStringBuffer.cc, * java/lang/natStringBuilder.cc: Removed. 2008-09-04 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.in, * classpath/configure: Regenerated. * gnu/gcj/util/natDebug.cc, * gnu/gcj/xlib/natColormap.cc, * gnu/gcj/xlib/natDisplay.cc, * gnu/gcj/xlib/natDrawable.cc, * gnu/gcj/xlib/natFont.cc, * gnu/gcj/xlib/natWMSizeHints.cc, * gnu/gcj/xlib/natWindow.cc, * gnu/gcj/xlib/natXImage.cc: Add :: prefix to namespaces. * java/io/CharArrayWriter.h, * java/lang/StringBuffer.h: Regenerated using patched gjavah. * java/lang/natStringBuffer.cc: Fix naming of append(jint). * java/sql/Timestamp.h: Regenerated using patched gjavah. * jni.cc: Rename p to functions to match change in GNU Classpath. * scripts/makemake.tcl: Switch gnu.java.math to BC compilation. * sources.am: Regenerated. 2008-08-21 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.in: Updated location of Configuration.java. * classpath/lib/gnu/java/locale/LocaleData.class: Regenerated. 2008-08-18 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.in: Updated with new Java files. * classpath/configure: Regenerated. * classpath/tools/Makefile.am: Add missing use of GJDOC_EX so --disable-gjdoc works. * classpath/tools/Makefile.in: Regenerated. 2008-08-15 Matthias Klose <doko@ubuntu.com> Import GNU Classpath (libgcj-import-20080811). * Regenerate class and header files. * Regenerate auto* files. * configure.ac: Don't pass --with-fastjar to classpath, substitute new dummy value in classpath/gnu/classpath/Configuration.java.in, pass --disable-gjdoc to classpath. * scripts/makemake.tcl: * sources.am: Regenerated. * java/lang/AbstractStringBuffer.java, gnu/java/lang/VMCPStringBuilder.java: New, copied from classpath, use System instead of VMSystem. * java/lang/StringBuffer.java: Merge from classpath. * java/lang/ClassLoader.java: Merge from classpath. * gcj/javaprims.h: Update class definitions, remove _Jv_jobjectRefType, jobjectRefType definitions. libjava/classpath/ChangeLog.gcj: 2008-10-21 Matthias Klose <doko@ubuntu.com> * classpath/tools/gnu/classpath/tools/gjdoc/expr/Java*: Move from ... * classpath/tools/generated/gnu/classpath/tools/gjdoc/expr/ ... here. * Update .class files. 2008-10-21 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/Makefile.am: Always generate parser in the srcdir. 2008-10-21 Matthias Klose <doko@ubuntu.com> * doc/Makefile.am (MAINTAINERCLEANFILES): Add gjdoc.1. * doc/Makefile.in: Regenerate. 2008-10-20 Matthias Klose <doko@ubuntu.com> * configure.ac: Don't check for working java, if not configured with --enable-java-maintainer-mode. * configure: Regenerate. 2008-10-19 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_java.m4: Revert previous change. * m4/ac_prog_javac.m4: Apply it here. * configure: Regenerate. 2008-10-19 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_javac.m4: Don't check for working javac, if not configured with --enable-java-maintainer-mode. * configure: Regenerate. * Makefile.in, */Makefile.in: Regenerate. 2008-09-30 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_antlr.m4: Check for cantlr binary as well. 2008-09-29 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_antlr.m4: Check for antlr binary as well. 2008-09-28 Matthias Klose <doko@ubuntu.com> * PR libgcj/37636. Revert: 2008-02-20 Matthias Klose <doko@ubuntu.com> * tools/Makefile.am ($(TOOLS_ZIP)): Revert part of previous change, Do copy resource files in JAVA_MAINTAINER_MODE only. * tools/Makefile.in: Regenerate. 2008-09-14 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_javac_works.m4, m4/ac_prog_javac.m4, m4/acinclude.m4: Revert local changes. * m4/ac_prog_antlr.m4: Check for an runantlr binary. * tools/Makefile.am, lib/Makefile.am: Revert local changes (JCOMPILER). * tools/Makefile.am: Remove USE_JAVAC_FLAGS, pass ANTLR_JAR in GLIBJ_CLASSPATH. 2008-09-14 Matthias Klose <doko@ubuntu.com> Revert: Daniel Frampton <zyridium at zyridium.net> * AUTHORS: Added. * java/lang/InheritableThreadLocal.java, * java/lang/Thread.java, * java/lang/ThreadLocal.java: Modified to use java.lang.ThreadLocalMap. * java/lang/ThreadLocalMap.java: New cheaper ThreadLocal-specific WeakHashMap. 2008-08-15 Matthias Klose <doko@ubuntu.com> * m4/acinclude.m4 (CLASSPATH_JAVAC_MEM_CHECK): Remove unknown args for javac. libjava/classpath/ChangeLog: 2008-10-20 Andrew John Hughes <gnu_andrew@member.fsf.org> * m4/ac_prog_antlr.m4: Remove redundant checks. * tools/Makefile.am: Use gjdoc_gendir when calling antlr. 2008-10-15 Andrew John Hughes <gnu_andrew@member.fsf.org> * configure.ac: Remove superfluous AC_PROG_JAVA call. 2008-10-06 Andrew John Hughes <gnu_andrew@member.fsf.org> * m4/ac_prog_antlr: Check for cantlr as well. * tools/Makefile.am: Only build GJDoc parser when both CREATE_GJDOC and CREATE_GJDOC_PARSER are on. 2008-10-02 Andrew John Hughes <gnu_andrew@member.fsf.org> * configure.ac: Add regen-gjdoc-parser option, and separate antlr tests. * m4/ac_prog_antlr.m4: Turn single test into AC_LIB_ANTLR and AC_PROG_ANTLR. * m4/ac_prog_java.m4: Quote tests. * tools/Makefile.am: Support CREATE_GJDOC_PARSER option. 2008-09-14 Andrew John Hughes <gnu_andrew@member.fsf.org> * examples/Makefile.am: Check lib directly as well as glibj.zip for boot classes. * m4/acinclude.m4: Only require the class files to be built to allow the tools and examples to be built, not the installation of glibj.zip. * tools/Makefile.am: Check lib directly as well as glibj.zip for boot classes. 2008-09-13 Andrew John Hughes <gnu_andrew@member.fsf.org> * examples/Makefile.am, * lib/Makefile.am: Add GCJ rules. * m4/ac_prog_javac.m4: Check whether JAVAC is gcj. * m4/ac_prog_javac_works.m4: Add GCJ rules. * m4/acinclude.m4: Don't bother checking for -J if using GCJ. * tools/Makefile.am: Add GCJ rules. 2007-08-23 Daniel Frampton <zyridium@zyridium.net> * AUTHORS: Added. * java/lang/InheritableThreadLocal.java, * java/lang/Thread.java, * java/lang/ThreadLocal.java: Modified to use java.lang.ThreadLocalMap. * java/lang/ThreadLocalMap.java: New cheaper ThreadLocal-specific WeakHashMap. 2008-02-07 Ian Rogers <ian.rogers@manchester.ac.uk> * java/util/zip/ZipEntry.java: Use byte fields instead of integer fields, store the time as well as the DOS time and don't retain a global Calendar instance. (setDOSTime(int)): Set KNOWN_DOSTIME instead of KNOWN_TIME, and unset KNOWN_TIME. (getDOSTime()): Compute DOS time from UNIX time only when needed. (clone()): Provide cloning via the ZipEntry constructor where possible. (setTime(long)): Don't compute DOS time at this point. (getCalendar()): Removed. 2008-09-09 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/gnu/classpath/tools/getopt/Parser.java: (setHeader(String)): Make synchronized. (setFooter(String)): Likewise. * tools/gnu/classpath/tools/rmic/SourceGiopRmicCompiler.java, (reset()): Make synchronized. (name(Class)): Likewise. 2008-09-04 Robert Schuster <robertschuster@fsfe.org> * gnu/java/nio/charset/ByteDecodeLoopHelper: (arrayDecodeLoop): Added new break label, escape to that label. * gnu/java/nio/charset/ByteEncodeLoopHelper: (arrayDecodeLoop): Added new break label, escape to that label. 2008-09-04 Robert Schuster <robertschuster@fsfe.org> * java/text/DecimalFormat.java: (scanFix): Use 'i + 1' when looking at following character. (scanNegativePattern): Dito. 2008-09-02 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/gnu/classpath/tools/javah/ClassWrapper.java: (makeVtable()): Populate methodNameMap. (printMethods(CniPrintStream)): Always use pre-populated methodNameMap for bridge targets. 2008-09-01 Mario Torre <neugens@aicas.com> * gnu/java/awt/peer/x/XImage.java (XImageProducer): remove @Override annotation to allow compilation on javac < 1.6 and ecj < 3.4. 2008-09-01 Mario Torre <neugens@aicas.com> * gnu/java/awt/peer/x/XGraphicsDevice.java (getDisplay): fix to support new Escher API. * gnu/java/awt/peer/x/XImage.java (getSource): method implemented. * gnu/java/awt/peer/x/XImage.java (XImageProducer): implement ImageProducer for getSource. 2008-09-01 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/java/util/regex/BacktrackStack.java, * gnu/java/util/regex/CharIndexed.java, * gnu/java/util/regex/CharIndexedCharArray.java, * gnu/java/util/regex/CharIndexedCharSequence.java, * gnu/java/util/regex/CharIndexedInputStream.java, * gnu/java/util/regex/CharIndexedString.java, * gnu/java/util/regex/CharIndexedStringBuffer.java, * gnu/java/util/regex/RE.java, * gnu/java/util/regex/REException.java, * gnu/java/util/regex/REFilterInputStream.java, * gnu/java/util/regex/REMatch.java, * gnu/java/util/regex/REMatchEnumeration.java, * gnu/java/util/regex/RESyntax.java, * gnu/java/util/regex/REToken.java, * gnu/java/util/regex/RETokenAny.java, * gnu/java/util/regex/RETokenBackRef.java, * gnu/java/util/regex/RETokenChar.java, * gnu/java/util/regex/RETokenEnd.java, * gnu/java/util/regex/RETokenEndOfPreviousMatch.java, * gnu/java/util/regex/RETokenEndSub.java, * gnu/java/util/regex/RETokenIndependent.java, * gnu/java/util/regex/RETokenLookAhead.java, * gnu/java/util/regex/RETokenLookBehind.java, * gnu/java/util/regex/RETokenNamedProperty.java, * gnu/java/util/regex/RETokenOneOf.java, * gnu/java/util/regex/RETokenPOSIX.java, * gnu/java/util/regex/RETokenRange.java, * gnu/java/util/regex/RETokenRepeated.java, * gnu/java/util/regex/RETokenStart.java, * gnu/java/util/regex/RETokenWordBoundary.java, * gnu/java/util/regex/UncheckedRE.java: Fix indentation. 2008-09-01 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/java/util/regex/RETokenStart.java: (getMaximumLength()): Add Override annotation. (matchThis(CharIndexed, REMatch)): Likewise. (returnsFixedLengthMatches()): Renamed from returnsFixedLengthmatches and added Override annotation. (findFixedLengthMatches(CharIndexed,REMatch,int)): Add Override annotation. (dump(CPStringBuilder)): Likewise. * gnu/javax/print/ipp/IppRequest.java: (RequestWriter.writeOperationAttributes(AttributeSet)): Throw exception, don't just create and drop it. * javax/management/MBeanServerPermission.java: (MBeanServerPermissionCollection.add(Permission)): Compare against individual Strings not the entire array, and store the result of replace. * javax/swing/text/html/StyleSheet.java: (setBaseFontSize(size)): Store result of trim(). 2008-09-01 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/tools/FileObject.java: (openReader(boolean)): Document new parameter. 2008-03-27 Michael Franz <mvfranz@gmail.com> PR classpath/35690: * javax/tools/FileObject.java: (toUri()): Fix case from toURI. (openReader(boolean)): Add missing boolean argument. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/35487: * gnu/javax/management/Server.java: (beans): Change to ConcurrentHashMap. (defaultDomain): Make final. (outer): Likewise. (LazyListenersHolder): Added to wrap listeners, also now a ConcurrentHashMap, providing lazy initialisation safely. (sequenceNumber): Documented. (getBean(ObjectName)): Remove redundant cast. (addNotificationListener(ObjectName,NotificationListener, NotificationFilter,Object)): Remove map initialisation and use holder. (getObjectInstance(ObjectName)): Remove redundant cast. (registerMBean(Object,ObjectName)): Add bean atomically. (removeNotificationListener(ObjectName,NotificationListener)): Simplified. (removeNotificationListener(ObjectName,NotificationListener, NotificationFilter,Object)): Likewise. (notify(ObjectName,String)): Documented. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/javax/management/Server.java: Genericised. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/javax/management/Translator.java: Genericised. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/management/DefaultLoaderRepository.java, * javax/management/JMX.java, * javax/management/MBeanAttributeInfo.java, * javax/management/MBeanConstructorInfo.java, * javax/management/MBeanOperationInfo.java, * javax/management/MBeanServerDelegate.java: Fix warnings due to generics. 2008-08-25 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/management/MBeanPermission.java, * javax/management/MBeanServerDelegate.java, * javax/management/MBeanServerFactory.java, * javax/management/MBeanServerInvocationHandler.java, * javax/management/MBeanServerPermission.java: Fix warnings due to use of non-generic collections. 2008-08-25 Mario Torre <neugens@aicas.com> * gnu/javax/rmi/CORBA/RmiUtilities.java (readValue): check if sender is null to avoid NPE. 2008-08-22 Mario Torre <neugens@aicas.com> * gnu/CORBA/OrbFunctional.java (set_parameters): Fix NullPointerException checking when param is null. 2008-08-23 Andrew John Hughes <gnu_andrew@member.fsf.org> * java/util/regex/Matcher.java: (reset()): Reset append position so we don't try and append to the end of the old input. 2008-08-22 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/32028: * m4/acinclude.m4: Also allow versions of GJDoc from 0.8* on, as CVS is 0.8.0-pre. 2008-08-21 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/32028: * m4/acinclude.m4: (CLASSPATH_WITH_GJDOC): Ensure version 0.7.9 is being used. 2008-08-20 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/Makefile.am: Add taglets subdirectory to list of excluded paths when GJDoc is not compiled. 2008-08-19 David P Grove <groved@us.ibm.com> * scripts/check_jni_methods.sh.in: Fix build issue on AIX by splitting generation of method list. 2008-08-18 Andrew John Hughes <gnu_andrew@member.fsf.org> * native/jni/gstreamer-peer/gst_native_pipeline.c: (get_free_space(int)): Use #else not #elif when there is no condition. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/31895: * java/text/DecimalFormat.java: (setCurrency(Currency)): Update prefixes and suffixes when currency changes. * java/text/DecimalFormatSymbols.java: (DecimalFormatSymbols(Locale)): Set locale earlier so it can be used by setCurrency(Currency). (setCurrency(Currency)): Set the symbol correctly using the locale of the instance. * java/util/Currency.java: Throw error instead of just printing a message. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/activation/ActivationDataFlavor.java: Suppress warnings from public API. (mimeType): Made final. (representationClass): Added generic type and made final. (normalizeMimeTypeParameter(String,String)): Use CPStringBuilder. * javax/activation/CommandInfo.java: (verb): Made final. (className): Made final. * javax/activation/DataHandler.java: (dataSource): Made final. * javax/activation/FileDataSource.java: (file): Made final. * javax/activation/MailcapCommandMap.java: Use generics on collections and CPStringBuilder instead of StringBuffer. * javax/activation/MimeType.java: (toString()): Use CPStringBuilder. (getBaseType()): Likewise. * javax/activation/MimeTypeParameterList.java: Use generics on collections and CPStringBuilder instead of StringBuffer. * javax/activation/MimeTypeParseException.java: (MimeTypeParseException(String,String)): Use CPStringBuilder. * javax/activation/MimetypesFileTypeMap.java: Use generics on collections and CPStringBuilder instead of StringBuffer. * javax/activation/URLDataSource.java: (url): Made final. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/javax/activation/viewers/ImageViewer.java, * gnu/javax/activation/viewers/TextEditor.java, * gnu/javax/activation/viewers/TextViewer.java, * javax/activation/ActivationDataFlavor.java, * javax/activation/CommandInfo.java, * javax/activation/CommandMap.java, * javax/activation/CommandObject.java, * javax/activation/DataContentHandler.java, * javax/activation/DataContentHandlerFactory.java, * javax/activation/DataHandler.java, * javax/activation/DataHandlerDataSource.java, * javax/activation/DataSource.java, * javax/activation/DataSourceDataContentHandler.java, * javax/activation/FileDataSource.java, * javax/activation/FileTypeMap.java, * javax/activation/MailcapCommandMap.java, * javax/activation/MimeType.java, * javax/activation/MimeTypeParameterList.java, * javax/activation/MimeTypeParseException.java, * javax/activation/MimetypesFileTypeMap.java, * javax/activation/ObjectDataContentHandler.java, * javax/activation/URLDataSource.java, * javax/activation/UnsupportedDataTypeException.java, * javax/activation/package.html, * resource/META-INF/mailcap.default, * resource/META-INF/mimetypes.default: Import GNU JAF CVS as of 17/08/2008. 2006-04-25 Archit Shah <ashah@redhat.com> * javax/activation/MimeTypeParameterList.java: Insert ';' separator before parameter list. 2005-06-29 Xavier Poinsard <xpoinsard@openpricer.com> * javax/activation/ObjectDataContentHandler.java: Fixed typo. 2005-05-28 Chris Burdess <dog@bluezoo.org> * javax/activation/CommandMap.java, * javax/activation/MailcapCommandMap.java: Updated to JAF 1.1. 2004-06-09 Chris Burdess <dog@bluezoo.org> * javax/activation/MailcapCommandMap.java: Fixed bug whereby x-java prefix was not attempted. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * AUTHORS: Added Laszlo. 2008-04-20 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/30436: * java/util/Scanner.java: Fix package to be java.util and correct indentation. 2007-07-25 Laszlo Andras Hernadi <e0327023@student.tuwien.ac.at> PR classpath/30436: * java/util/Scanner.java: Initial implementation. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * java/util/regex/Matcher.java: (toMatchResult()): Implemented. 2008-08-13 Joshua Sumali <jsumali@redhat.com> * doc/Makefile.am (gjdoc.pod): Generate gjdoc pod from cp-tools.texinfo instead of invoke.texi. Remove invoke.texi from EXTRA_DIST. * doc/invoke.texi: Removed and merged into ... * doc/cp-tools.texinfo: Here 2008-08-12 Robert Schuster <robertschuster@fsfe.org> * native/jni/java-net/local.c (local_bind): Removed fprintf call, fixed access outside of array bounds. From-SVN: r141271
1359 lines
47 KiB
Java
1359 lines
47 KiB
Java
/* Thread -- an independent thread of executable code
|
|
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
|
Free Software Foundation
|
|
|
|
This file is part of GNU Classpath.
|
|
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
any later version.
|
|
|
|
GNU Classpath 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 for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
02110-1301 USA.
|
|
|
|
Linking this library statically or dynamically with other modules is
|
|
making a combined work based on this library. Thus, the terms and
|
|
conditions of the GNU General Public License cover the whole
|
|
combination.
|
|
|
|
As a special exception, the copyright holders of this library give you
|
|
permission to link this library with independent modules to produce an
|
|
executable, regardless of the license terms of these independent
|
|
modules, and to copy and distribute the resulting executable under
|
|
terms of your choice, provided that you also meet, for each linked
|
|
independent module, the terms and conditions of the license of that
|
|
module. An independent module is a module which is not derived from
|
|
or based on this library. If you modify this library, you may extend
|
|
this exception to your version of the library, but you are not
|
|
obligated to do so. If you do not wish to do so, delete this
|
|
exception statement from your version. */
|
|
|
|
package java.lang;
|
|
|
|
import gnu.classpath.VMStackWalker;
|
|
import gnu.gcj.RawData;
|
|
import gnu.gcj.RawDataManaged;
|
|
import gnu.java.util.WeakIdentityHashMap;
|
|
|
|
import java.lang.management.ManagementFactory;
|
|
import java.lang.management.ThreadInfo;
|
|
import java.lang.management.ThreadMXBean;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
|
|
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
|
|
* "The Java Language Specification", ISBN 0-201-63451-1
|
|
* plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
|
|
* Status: Believed complete to version 1.4, with caveats. We do not
|
|
* implement the deprecated (and dangerous) stop, suspend, and resume
|
|
* methods. Security implementation is not complete.
|
|
*/
|
|
|
|
/**
|
|
* Thread represents a single thread of execution in the VM. When an
|
|
* application VM starts up, it creates a non-daemon Thread which calls the
|
|
* main() method of a particular class. There may be other Threads running,
|
|
* such as the garbage collection thread.
|
|
*
|
|
* <p>Threads have names to identify them. These names are not necessarily
|
|
* unique. Every Thread has a priority, as well, which tells the VM which
|
|
* Threads should get more running time. New threads inherit the priority
|
|
* and daemon status of the parent thread, by default.
|
|
*
|
|
* <p>There are two methods of creating a Thread: you may subclass Thread and
|
|
* implement the <code>run()</code> method, at which point you may start the
|
|
* Thread by calling its <code>start()</code> method, or you may implement
|
|
* <code>Runnable</code> in the class you want to use and then call new
|
|
* <code>Thread(your_obj).start()</code>.
|
|
*
|
|
* <p>The virtual machine runs until all non-daemon threads have died (either
|
|
* by returning from the run() method as invoked by start(), or by throwing
|
|
* an uncaught exception); or until <code>System.exit</code> is called with
|
|
* adequate permissions.
|
|
*
|
|
* <p>It is unclear at what point a Thread should be added to a ThreadGroup,
|
|
* and at what point it should be removed. Should it be inserted when it
|
|
* starts, or when it is created? Should it be removed when it is suspended
|
|
* or interrupted? The only thing that is clear is that the Thread should be
|
|
* removed when it is stopped.
|
|
*
|
|
* @author Tom Tromey
|
|
* @author John Keiser
|
|
* @author Eric Blake (ebb9@email.byu.edu)
|
|
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
|
* @see Runnable
|
|
* @see Runtime#exit(int)
|
|
* @see #run()
|
|
* @see #start()
|
|
* @see ThreadLocal
|
|
* @since 1.0
|
|
* @status updated to 1.4
|
|
*/
|
|
public class Thread implements Runnable
|
|
{
|
|
/** The minimum priority for a Thread. */
|
|
public static final int MIN_PRIORITY = 1;
|
|
|
|
/** The priority a Thread gets by default. */
|
|
public static final int NORM_PRIORITY = 5;
|
|
|
|
/** The maximum priority for a Thread. */
|
|
public static final int MAX_PRIORITY = 10;
|
|
|
|
/**
|
|
* The group this thread belongs to. This is set to null by
|
|
* ThreadGroup.removeThread when the thread dies.
|
|
*/
|
|
ThreadGroup group;
|
|
|
|
/** The object to run(), null if this is the target. */
|
|
private Runnable runnable;
|
|
|
|
/** The thread name, non-null. */
|
|
String name;
|
|
|
|
/** Whether the thread is a daemon. */
|
|
private boolean daemon;
|
|
|
|
/** The thread priority, 1 to 10. */
|
|
private int priority;
|
|
|
|
boolean interrupt_flag;
|
|
|
|
/** A thread is either alive, dead, or being sent a signal; if it is
|
|
being sent a signal, it is also alive. Thus, if you want to
|
|
know if a thread is alive, it is sufficient to test
|
|
alive_status != THREAD_DEAD. */
|
|
private static final byte THREAD_DEAD = 0;
|
|
private static final byte THREAD_ALIVE = 1;
|
|
private static final byte THREAD_SIGNALED = 2;
|
|
|
|
private boolean startable_flag;
|
|
|
|
/** The context classloader for this Thread. */
|
|
private ClassLoader contextClassLoader;
|
|
|
|
/** This thread's ID. */
|
|
private final long threadId;
|
|
|
|
/** The next thread ID to use. */
|
|
private static long nextThreadId;
|
|
|
|
/** Used to generate the next thread ID to use. */
|
|
private static long totalThreadsCreated;
|
|
|
|
/** The default exception handler. */
|
|
private static UncaughtExceptionHandler defaultHandler;
|
|
|
|
/** Thread local storage. Package accessible for use by
|
|
* InheritableThreadLocal.
|
|
*/
|
|
ThreadLocalMap locals;
|
|
|
|
/** The uncaught exception handler. */
|
|
UncaughtExceptionHandler exceptionHandler;
|
|
|
|
/** This object is recorded while the thread is blocked to permit
|
|
* monitoring and diagnostic tools to identify the reasons that
|
|
* threads are blocked.
|
|
*/
|
|
private Object parkBlocker;
|
|
|
|
/** Used by Unsafe.park and Unsafe.unpark. Se Unsafe for a full
|
|
description. */
|
|
static final byte THREAD_PARK_RUNNING = 0;
|
|
static final byte THREAD_PARK_PERMIT = 1;
|
|
static final byte THREAD_PARK_PARKED = 2;
|
|
static final byte THREAD_PARK_DEAD = 3;
|
|
|
|
/** The access control state for this thread. Package accessible
|
|
* for use by java.security.VMAccessControlState's native method.
|
|
*/
|
|
Object accessControlState = null;
|
|
|
|
// This describes the top-most interpreter frame for this thread.
|
|
RawData interp_frame;
|
|
|
|
// This describes the top most frame in the composite (interp + JNI) stack
|
|
RawData frame;
|
|
|
|
// Current state.
|
|
volatile int state;
|
|
|
|
// Our native data - points to an instance of struct natThread.
|
|
RawDataManaged data;
|
|
|
|
/**
|
|
* Allocates a new <code>Thread</code> object. This constructor has
|
|
* the same effect as <code>Thread(null, null,</code>
|
|
* <i>gname</i><code>)</code>, where <b><i>gname</i></b> is
|
|
* a newly generated name. Automatically generated names are of the
|
|
* form <code>"Thread-"+</code><i>n</i>, where <i>n</i> is an integer.
|
|
* <p>
|
|
* Threads created this way must have overridden their
|
|
* <code>run()</code> method to actually do anything. An example
|
|
* illustrating this method being used follows:
|
|
* <p><blockquote><pre>
|
|
* import java.lang.*;
|
|
*
|
|
* class plain01 implements Runnable {
|
|
* String name;
|
|
* plain01() {
|
|
* name = null;
|
|
* }
|
|
* plain01(String s) {
|
|
* name = s;
|
|
* }
|
|
* public void run() {
|
|
* if (name == null)
|
|
* System.out.println("A new thread created");
|
|
* else
|
|
* System.out.println("A new thread with name " + name +
|
|
* " created");
|
|
* }
|
|
* }
|
|
* class threadtest01 {
|
|
* public static void main(String args[] ) {
|
|
* int failed = 0 ;
|
|
*
|
|
* <b>Thread t1 = new Thread();</b>
|
|
* if (t1 != null)
|
|
* System.out.println("new Thread() succeed");
|
|
* else {
|
|
* System.out.println("new Thread() failed");
|
|
* failed++;
|
|
* }
|
|
* }
|
|
* }
|
|
* </pre></blockquote>
|
|
*
|
|
* @see java.lang.Thread#Thread(java.lang.ThreadGroup,
|
|
* java.lang.Runnable, java.lang.String)
|
|
*/
|
|
public Thread()
|
|
{
|
|
this(null, null, gen_name());
|
|
}
|
|
|
|
/**
|
|
* Allocates a new <code>Thread</code> object. This constructor has
|
|
* the same effect as <code>Thread(null, target,</code>
|
|
* <i>gname</i><code>)</code>, where <i>gname</i> is
|
|
* a newly generated name. Automatically generated names are of the
|
|
* form <code>"Thread-"+</code><i>n</i>, where <i>n</i> is an integer.
|
|
*
|
|
* @param target the object whose <code>run</code> method is called.
|
|
* @see java.lang.Thread#Thread(java.lang.ThreadGroup,
|
|
* java.lang.Runnable, java.lang.String)
|
|
*/
|
|
public Thread(Runnable target)
|
|
{
|
|
this(null, target, gen_name());
|
|
}
|
|
|
|
/**
|
|
* Allocates a new <code>Thread</code> object. This constructor has
|
|
* the same effect as <code>Thread(null, null, name)</code>.
|
|
*
|
|
* @param name the name of the new thread.
|
|
* @see java.lang.Thread#Thread(java.lang.ThreadGroup,
|
|
* java.lang.Runnable, java.lang.String)
|
|
*/
|
|
public Thread(String name)
|
|
{
|
|
this(null, null, name);
|
|
}
|
|
|
|
/**
|
|
* Allocates a new <code>Thread</code> object. This constructor has
|
|
* the same effect as <code>Thread(group, target,</code>
|
|
* <i>gname</i><code>)</code>, where <i>gname</i> is
|
|
* a newly generated name. Automatically generated names are of the
|
|
* form <code>"Thread-"+</code><i>n</i>, where <i>n</i> is an integer.
|
|
*
|
|
* @param group the group to put the Thread into
|
|
* @param target the Runnable object to execute
|
|
* @throws SecurityException if this thread cannot access <code>group</code>
|
|
* @throws IllegalThreadStateException if group is destroyed
|
|
* @see #Thread(ThreadGroup, Runnable, String)
|
|
*/
|
|
public Thread(ThreadGroup group, Runnable target)
|
|
{
|
|
this(group, target, gen_name());
|
|
}
|
|
|
|
/**
|
|
* Allocates a new <code>Thread</code> object. This constructor has
|
|
* the same effect as <code>Thread(group, null, name)</code>
|
|
*
|
|
* @param group the group to put the Thread into
|
|
* @param name the name for the Thread
|
|
* @throws NullPointerException if name is null
|
|
* @throws SecurityException if this thread cannot access <code>group</code>
|
|
* @throws IllegalThreadStateException if group is destroyed
|
|
* @see #Thread(ThreadGroup, Runnable, String)
|
|
*/
|
|
public Thread(ThreadGroup group, String name)
|
|
{
|
|
this(group, null, name);
|
|
}
|
|
|
|
/**
|
|
* Allocates a new <code>Thread</code> object. This constructor has
|
|
* the same effect as <code>Thread(null, target, name)</code>.
|
|
*
|
|
* @param target the Runnable object to execute
|
|
* @param name the name for the Thread
|
|
* @throws NullPointerException if name is null
|
|
* @see #Thread(ThreadGroup, Runnable, String)
|
|
*/
|
|
public Thread(Runnable target, String name)
|
|
{
|
|
this(null, target, name);
|
|
}
|
|
|
|
/**
|
|
* Allocate a new Thread object, with the specified ThreadGroup and name, and
|
|
* using the specified Runnable object's <code>run()</code> method to
|
|
* execute. If the Runnable object is null, <code>this</code> (which is
|
|
* a Runnable) is used instead.
|
|
*
|
|
* <p>If the ThreadGroup is null, the security manager is checked. If a
|
|
* manager exists and returns a non-null object for
|
|
* <code>getThreadGroup</code>, that group is used; otherwise the group
|
|
* of the creating thread is used. Note that the security manager calls
|
|
* <code>checkAccess</code> if the ThreadGroup is not null.
|
|
*
|
|
* <p>The new Thread will inherit its creator's priority and daemon status.
|
|
* These can be changed with <code>setPriority</code> and
|
|
* <code>setDaemon</code>.
|
|
*
|
|
* @param group the group to put the Thread into
|
|
* @param target the Runnable object to execute
|
|
* @param name the name for the Thread
|
|
* @throws NullPointerException if name is null
|
|
* @throws SecurityException if this thread cannot access <code>group</code>
|
|
* @throws IllegalThreadStateException if group is destroyed
|
|
* @see Runnable#run()
|
|
* @see #run()
|
|
* @see #setDaemon(boolean)
|
|
* @see #setPriority(int)
|
|
* @see SecurityManager#checkAccess(ThreadGroup)
|
|
* @see ThreadGroup#checkAccess()
|
|
*/
|
|
public Thread(ThreadGroup group, Runnable target, String name)
|
|
{
|
|
this(currentThread(), group, target, name, false);
|
|
}
|
|
|
|
/**
|
|
* Allocate a new Thread object, as if by
|
|
* <code>Thread(group, null, name)</code>, and give it the specified stack
|
|
* size, in bytes. The stack size is <b>highly platform independent</b>,
|
|
* and the virtual machine is free to round up or down, or ignore it
|
|
* completely. A higher value might let you go longer before a
|
|
* <code>StackOverflowError</code>, while a lower value might let you go
|
|
* longer before an <code>OutOfMemoryError</code>. Or, it may do absolutely
|
|
* nothing! So be careful, and expect to need to tune this value if your
|
|
* virtual machine even supports it.
|
|
*
|
|
* @param group the group to put the Thread into
|
|
* @param target the Runnable object to execute
|
|
* @param name the name for the Thread
|
|
* @param size the stack size, in bytes; 0 to be ignored
|
|
* @throws NullPointerException if name is null
|
|
* @throws SecurityException if this thread cannot access <code>group</code>
|
|
* @throws IllegalThreadStateException if group is destroyed
|
|
* @since 1.4
|
|
*/
|
|
public Thread(ThreadGroup group, Runnable target, String name, long size)
|
|
{
|
|
// Just ignore stackSize for now.
|
|
this(currentThread(), group, target, name, false);
|
|
}
|
|
|
|
/**
|
|
* Allocate a new Thread object for threads used internally to the
|
|
* run time. Runtime threads should not be members of an
|
|
* application ThreadGroup, nor should they execute arbitrary user
|
|
* code as part of the InheritableThreadLocal protocol.
|
|
*
|
|
* @param name the name for the Thread
|
|
* @param noInheritableThreadLocal if true, do not initialize
|
|
* InheritableThreadLocal variables for this thread.
|
|
* @throws IllegalThreadStateException if group is destroyed
|
|
*/
|
|
Thread(String name, boolean noInheritableThreadLocal)
|
|
{
|
|
this(null, null, null, name, noInheritableThreadLocal);
|
|
}
|
|
|
|
private Thread (Thread current, ThreadGroup g, Runnable r, String n, boolean noInheritableThreadLocal)
|
|
{
|
|
// Make sure the current thread may create a new thread.
|
|
checkAccess();
|
|
|
|
// The Class Libraries book says ``threadName cannot be null''. I
|
|
// take this to mean NullPointerException.
|
|
if (n == null)
|
|
throw new NullPointerException ();
|
|
|
|
if (g == null)
|
|
{
|
|
// If CURRENT is null, then we are bootstrapping the first thread.
|
|
// Use ThreadGroup.root, the main threadgroup.
|
|
if (current == null)
|
|
group = ThreadGroup.root;
|
|
else
|
|
group = current.getThreadGroup();
|
|
}
|
|
else
|
|
group = g;
|
|
|
|
data = null;
|
|
interrupt_flag = false;
|
|
startable_flag = true;
|
|
|
|
synchronized (Thread.class)
|
|
{
|
|
this.threadId = nextThreadId++;
|
|
}
|
|
|
|
// Always create the ThreadLocalMap when creating a thread; the
|
|
// previous code did this lazily when getThreadLocals was called,
|
|
// but this is a divergence from Classpath's implementation of
|
|
// ThreadLocal.
|
|
this.locals = new ThreadLocalMap();
|
|
|
|
if (current != null)
|
|
{
|
|
group.checkAccess();
|
|
|
|
daemon = current.isDaemon();
|
|
int gmax = group.getMaxPriority();
|
|
int pri = current.getPriority();
|
|
priority = (gmax < pri ? gmax : pri);
|
|
contextClassLoader = current.contextClassLoader;
|
|
// InheritableThreadLocal allows arbitrary user code to be
|
|
// executed, only do this if our caller desires it.
|
|
if (!noInheritableThreadLocal)
|
|
InheritableThreadLocal.newChildThread(this);
|
|
}
|
|
else
|
|
{
|
|
daemon = false;
|
|
priority = NORM_PRIORITY;
|
|
}
|
|
|
|
name = n;
|
|
group.addThread(this);
|
|
runnable = r;
|
|
|
|
initialize_native ();
|
|
}
|
|
|
|
/**
|
|
* Get the number of active threads in the current Thread's ThreadGroup.
|
|
* This implementation calls
|
|
* <code>currentThread().getThreadGroup().activeCount()</code>.
|
|
*
|
|
* @return the number of active threads in the current ThreadGroup
|
|
* @see ThreadGroup#activeCount()
|
|
*/
|
|
public static int activeCount()
|
|
{
|
|
return currentThread().group.activeCount();
|
|
}
|
|
|
|
/**
|
|
* Check whether the current Thread is allowed to modify this Thread. This
|
|
* passes the check on to <code>SecurityManager.checkAccess(this)</code>.
|
|
*
|
|
* @throws SecurityException if the current Thread cannot modify this Thread
|
|
* @see SecurityManager#checkAccess(Thread)
|
|
*/
|
|
public final void checkAccess()
|
|
{
|
|
SecurityManager sm = System.getSecurityManager();
|
|
if (sm != null)
|
|
sm.checkAccess(this);
|
|
}
|
|
|
|
/**
|
|
* Count the number of stack frames in this Thread. The Thread in question
|
|
* must be suspended when this occurs.
|
|
*
|
|
* @return the number of stack frames in this Thread
|
|
* @throws IllegalThreadStateException if this Thread is not suspended
|
|
* @deprecated pointless, since suspend is deprecated
|
|
*/
|
|
public native int countStackFrames();
|
|
|
|
/**
|
|
* Get the currently executing Thread. In the situation that the
|
|
* currently running thread was created by native code and doesn't
|
|
* have an associated Thread object yet, a new Thread object is
|
|
* constructed and associated with the native thread.
|
|
*
|
|
* @return the currently executing Thread
|
|
*/
|
|
public static native Thread currentThread();
|
|
|
|
/**
|
|
* Originally intended to destroy this thread, this method was never
|
|
* implemented by Sun, and is hence a no-op.
|
|
*
|
|
* @deprecated This method was originally intended to simply destroy
|
|
* the thread without performing any form of cleanup operation.
|
|
* However, it was never implemented. It is now deprecated
|
|
* for the same reason as <code>suspend()</code>,
|
|
* <code>stop()</code> and <code>resume()</code>; namely,
|
|
* it is prone to deadlocks. If a thread is destroyed while
|
|
* it still maintains a lock on a resource, then this resource
|
|
* will remain locked and any attempts by other threads to
|
|
* access the resource will result in a deadlock. Thus, even
|
|
* an implemented version of this method would be still be
|
|
* deprecated, due to its unsafe nature.
|
|
* @throws NoSuchMethodError as this method was never implemented.
|
|
*/
|
|
public void destroy()
|
|
{
|
|
throw new NoSuchMethodError();
|
|
}
|
|
|
|
/**
|
|
* Print a stack trace of the current thread to stderr using the same
|
|
* format as Throwable's printStackTrace() method.
|
|
*
|
|
* @see Throwable#printStackTrace()
|
|
*/
|
|
public static void dumpStack()
|
|
{
|
|
(new Exception("Stack trace")).printStackTrace();
|
|
}
|
|
|
|
/**
|
|
* Copy every active thread in the current Thread's ThreadGroup into the
|
|
* array. Extra threads are silently ignored. This implementation calls
|
|
* <code>getThreadGroup().enumerate(array)</code>, which may have a
|
|
* security check, <code>checkAccess(group)</code>.
|
|
*
|
|
* @param array the array to place the Threads into
|
|
* @return the number of Threads placed into the array
|
|
* @throws NullPointerException if array is null
|
|
* @throws SecurityException if you cannot access the ThreadGroup
|
|
* @see ThreadGroup#enumerate(Thread[])
|
|
* @see #activeCount()
|
|
* @see SecurityManager#checkAccess(ThreadGroup)
|
|
*/
|
|
public static int enumerate(Thread[] array)
|
|
{
|
|
return currentThread().group.enumerate(array);
|
|
}
|
|
|
|
/**
|
|
* Get this Thread's name.
|
|
*
|
|
* @return this Thread's name
|
|
*/
|
|
public final String getName()
|
|
{
|
|
return name;
|
|
}
|
|
|
|
/**
|
|
* Get this Thread's priority.
|
|
*
|
|
* @return the Thread's priority
|
|
*/
|
|
public final int getPriority()
|
|
{
|
|
return priority;
|
|
}
|
|
|
|
/**
|
|
* Get the ThreadGroup this Thread belongs to. If the thread has died, this
|
|
* returns null.
|
|
*
|
|
* @return this Thread's ThreadGroup
|
|
*/
|
|
public final ThreadGroup getThreadGroup()
|
|
{
|
|
return group;
|
|
}
|
|
|
|
/**
|
|
* Checks whether the current thread holds the monitor on a given object.
|
|
* This allows you to do <code>assert Thread.holdsLock(obj)</code>.
|
|
*
|
|
* @param obj the object to test lock ownership on.
|
|
* @return true if the current thread is currently synchronized on obj
|
|
* @throws NullPointerException if obj is null
|
|
* @since 1.4
|
|
*/
|
|
public static native boolean holdsLock(Object obj);
|
|
|
|
/**
|
|
* Interrupt this Thread. First, there is a security check,
|
|
* <code>checkAccess</code>. Then, depending on the current state of the
|
|
* thread, various actions take place:
|
|
*
|
|
* <p>If the thread is waiting because of {@link #wait()},
|
|
* {@link #sleep(long)}, or {@link #join()}, its <i>interrupt status</i>
|
|
* will be cleared, and an InterruptedException will be thrown. Notice that
|
|
* this case is only possible if an external thread called interrupt().
|
|
*
|
|
* <p>If the thread is blocked in an interruptible I/O operation, in
|
|
* {@link java.nio.channels.InterruptibleChannel}, the <i>interrupt
|
|
* status</i> will be set, and ClosedByInterruptException will be thrown.
|
|
*
|
|
* <p>If the thread is blocked on a {@link java.nio.channels.Selector}, the
|
|
* <i>interrupt status</i> will be set, and the selection will return, with
|
|
* a possible non-zero value, as though by the wakeup() method.
|
|
*
|
|
* <p>Otherwise, the interrupt status will be set.
|
|
*
|
|
* @throws SecurityException if you cannot modify this Thread
|
|
*/
|
|
public native void interrupt();
|
|
|
|
/**
|
|
* Determine whether the current Thread has been interrupted, and clear
|
|
* the <i>interrupted status</i> in the process.
|
|
*
|
|
* @return whether the current Thread has been interrupted
|
|
* @see #isInterrupted()
|
|
*/
|
|
public static boolean interrupted()
|
|
{
|
|
return currentThread().isInterrupted(true);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the given Thread has been interrupted, but leave
|
|
* the <i>interrupted status</i> alone in the process.
|
|
*
|
|
* @return whether the Thread has been interrupted
|
|
* @see #interrupted()
|
|
*/
|
|
public boolean isInterrupted()
|
|
{
|
|
return interrupt_flag;
|
|
}
|
|
|
|
/**
|
|
* Determine whether this Thread is alive. A thread which is alive has
|
|
* started and not yet died.
|
|
*
|
|
* @return whether this Thread is alive
|
|
*/
|
|
public final native boolean isAlive();
|
|
|
|
/**
|
|
* Tell whether this is a daemon Thread or not.
|
|
*
|
|
* @return whether this is a daemon Thread or not
|
|
* @see #setDaemon(boolean)
|
|
*/
|
|
public final boolean isDaemon()
|
|
{
|
|
return daemon;
|
|
}
|
|
|
|
/**
|
|
* Wait forever for the Thread in question to die.
|
|
*
|
|
* @throws InterruptedException if the Thread is interrupted; it's
|
|
* <i>interrupted status</i> will be cleared
|
|
*/
|
|
public final void join() throws InterruptedException
|
|
{
|
|
join(0, 0);
|
|
}
|
|
|
|
/**
|
|
* Wait the specified amount of time for the Thread in question to die.
|
|
*
|
|
* @param ms the number of milliseconds to wait, or 0 for forever
|
|
* @throws InterruptedException if the Thread is interrupted; it's
|
|
* <i>interrupted status</i> will be cleared
|
|
*/
|
|
public final void join(long ms) throws InterruptedException
|
|
{
|
|
join(ms, 0);
|
|
}
|
|
|
|
/**
|
|
* Wait the specified amount of time for the Thread in question to die.
|
|
*
|
|
* <p>Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs do
|
|
* not offer that fine a grain of timing resolution. Besides, there is
|
|
* no guarantee that this thread can start up immediately when time expires,
|
|
* because some other thread may be active. So don't expect real-time
|
|
* performance.
|
|
*
|
|
* @param ms the number of milliseconds to wait, or 0 for forever
|
|
* @param ns the number of extra nanoseconds to sleep (0-999999)
|
|
* @throws InterruptedException if the Thread is interrupted; it's
|
|
* <i>interrupted status</i> will be cleared
|
|
* @throws IllegalArgumentException if ns is invalid
|
|
* @XXX A ThreadListener would be nice, to make this efficient.
|
|
*/
|
|
public final native void join(long ms, int ns)
|
|
throws InterruptedException;
|
|
|
|
/**
|
|
* Resume this Thread. If the thread is not suspended, this method does
|
|
* nothing. To mirror suspend(), there may be a security check:
|
|
* <code>checkAccess</code>.
|
|
*
|
|
* @throws SecurityException if you cannot resume the Thread
|
|
* @see #checkAccess()
|
|
* @see #suspend()
|
|
* @deprecated pointless, since suspend is deprecated
|
|
*/
|
|
public final native void resume();
|
|
|
|
private final native void finish_();
|
|
|
|
/**
|
|
* Determine whether the given Thread has been interrupted, but leave
|
|
* the <i>interrupted status</i> alone in the process.
|
|
*
|
|
* @return whether the current Thread has been interrupted
|
|
* @see #interrupted()
|
|
*/
|
|
private boolean isInterrupted(boolean clear_flag)
|
|
{
|
|
boolean r = interrupt_flag;
|
|
if (clear_flag && r)
|
|
{
|
|
// Only clear the flag if we saw it as set. Otherwise this could
|
|
// potentially cause us to miss an interrupt in a race condition,
|
|
// because this method is not synchronized.
|
|
interrupt_flag = false;
|
|
}
|
|
return r;
|
|
}
|
|
|
|
/**
|
|
* The method of Thread that will be run if there is no Runnable object
|
|
* associated with the Thread. Thread's implementation does nothing at all.
|
|
*
|
|
* @see #start()
|
|
* @see #Thread(ThreadGroup, Runnable, String)
|
|
*/
|
|
public void run()
|
|
{
|
|
if (runnable != null)
|
|
runnable.run();
|
|
}
|
|
|
|
/**
|
|
* Set the daemon status of this Thread. If this is a daemon Thread, then
|
|
* the VM may exit even if it is still running. This may only be called
|
|
* before the Thread starts running. There may be a security check,
|
|
* <code>checkAccess</code>.
|
|
*
|
|
* @param daemon whether this should be a daemon thread or not
|
|
* @throws SecurityException if you cannot modify this Thread
|
|
* @throws IllegalThreadStateException if the Thread is active
|
|
* @see #isDaemon()
|
|
* @see #checkAccess()
|
|
*/
|
|
public final void setDaemon(boolean daemon)
|
|
{
|
|
if (!startable_flag)
|
|
throw new IllegalThreadStateException();
|
|
checkAccess();
|
|
this.daemon = daemon;
|
|
}
|
|
|
|
/**
|
|
* Returns the context classloader of this Thread. The context
|
|
* classloader can be used by code that want to load classes depending
|
|
* on the current thread. Normally classes are loaded depending on
|
|
* the classloader of the current class. There may be a security check
|
|
* for <code>RuntimePermission("getClassLoader")</code> if the caller's
|
|
* class loader is not null or an ancestor of this thread's context class
|
|
* loader.
|
|
*
|
|
* @return the context class loader
|
|
* @throws SecurityException when permission is denied
|
|
* @see #setContextClassLoader(ClassLoader)
|
|
* @since 1.2
|
|
*/
|
|
public synchronized ClassLoader getContextClassLoader()
|
|
{
|
|
if (contextClassLoader == null)
|
|
contextClassLoader = ClassLoader.getSystemClassLoader();
|
|
|
|
// Check if we may get the classloader
|
|
SecurityManager sm = System.getSecurityManager();
|
|
if (contextClassLoader != null && sm != null)
|
|
{
|
|
// Get the calling classloader
|
|
ClassLoader cl = VMStackWalker.getCallingClassLoader();
|
|
if (cl != null && !cl.isAncestorOf(contextClassLoader))
|
|
sm.checkPermission(new RuntimePermission("getClassLoader"));
|
|
}
|
|
return contextClassLoader;
|
|
}
|
|
|
|
/**
|
|
* Sets the context classloader for this Thread. When not explicitly set,
|
|
* the context classloader for a thread is the same as the context
|
|
* classloader of the thread that created this thread. The first thread has
|
|
* as context classloader the system classloader. There may be a security
|
|
* check for <code>RuntimePermission("setContextClassLoader")</code>.
|
|
*
|
|
* @param classloader the new context class loader
|
|
* @throws SecurityException when permission is denied
|
|
* @see #getContextClassLoader()
|
|
* @since 1.2
|
|
*/
|
|
public synchronized void setContextClassLoader(ClassLoader classloader)
|
|
{
|
|
SecurityManager sm = System.getSecurityManager();
|
|
if (sm != null)
|
|
sm.checkPermission(new RuntimePermission("setContextClassLoader"));
|
|
this.contextClassLoader = classloader;
|
|
}
|
|
|
|
/**
|
|
* Set this Thread's name. There may be a security check,
|
|
* <code>checkAccess</code>.
|
|
*
|
|
* @param name the new name for this Thread
|
|
* @throws NullPointerException if name is null
|
|
* @throws SecurityException if you cannot modify this Thread
|
|
*/
|
|
public final void setName(String name)
|
|
{
|
|
checkAccess();
|
|
// The Class Libraries book says ``threadName cannot be null''. I
|
|
// take this to mean NullPointerException.
|
|
if (name == null)
|
|
throw new NullPointerException();
|
|
this.name = name;
|
|
}
|
|
|
|
/**
|
|
* Yield to another thread. The Thread will not lose any locks it holds
|
|
* during this time. There are no guarantees which thread will be
|
|
* next to run, and it could even be this one, but most VMs will choose
|
|
* the highest priority thread that has been waiting longest.
|
|
*/
|
|
public static native void yield();
|
|
|
|
/**
|
|
* Suspend the current Thread's execution for the specified amount of
|
|
* time. The Thread will not lose any locks it has during this time. There
|
|
* are no guarantees which thread will be next to run, but most VMs will
|
|
* choose the highest priority thread that has been waiting longest.
|
|
*
|
|
* @param ms the number of milliseconds to sleep, or 0 for forever
|
|
* @throws InterruptedException if the Thread is (or was) interrupted;
|
|
* it's <i>interrupted status</i> will be cleared
|
|
* @throws IllegalArgumentException if ms is negative
|
|
* @see #interrupt()
|
|
* @see #notify()
|
|
* @see #wait(long)
|
|
*/
|
|
public static void sleep(long ms) throws InterruptedException
|
|
{
|
|
sleep(ms, 0);
|
|
}
|
|
|
|
/**
|
|
* Suspend the current Thread's execution for the specified amount of
|
|
* time. The Thread will not lose any locks it has during this time. There
|
|
* are no guarantees which thread will be next to run, but most VMs will
|
|
* choose the highest priority thread that has been waiting longest.
|
|
* <p>
|
|
* Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs
|
|
* do not offer that fine a grain of timing resolution. When ms is
|
|
* zero and ns is non-zero the Thread will sleep for at least one
|
|
* milli second. There is no guarantee that this thread can start up
|
|
* immediately when time expires, because some other thread may be
|
|
* active. So don't expect real-time performance.
|
|
*
|
|
* @param ms the number of milliseconds to sleep, or 0 for forever
|
|
* @param ns the number of extra nanoseconds to sleep (0-999999)
|
|
* @throws InterruptedException if the Thread is (or was) interrupted;
|
|
* it's <i>interrupted status</i> will be cleared
|
|
* @throws IllegalArgumentException if ms or ns is negative
|
|
* or ns is larger than 999999.
|
|
* @see #interrupt()
|
|
* @see #notify()
|
|
* @see #wait(long, int)
|
|
*/
|
|
public static native void sleep(long timeout, int nanos)
|
|
throws InterruptedException;
|
|
|
|
/**
|
|
* Start this Thread, calling the run() method of the Runnable this Thread
|
|
* was created with, or else the run() method of the Thread itself. This
|
|
* is the only way to start a new thread; calling run by yourself will just
|
|
* stay in the same thread. The virtual machine will remove the thread from
|
|
* its thread group when the run() method completes.
|
|
*
|
|
* @throws IllegalThreadStateException if the thread has already started
|
|
* @see #run()
|
|
*/
|
|
public native void start();
|
|
|
|
/**
|
|
* Cause this Thread to stop abnormally because of the throw of a ThreadDeath
|
|
* error. If you stop a Thread that has not yet started, it will stop
|
|
* immediately when it is actually started.
|
|
*
|
|
* <p>This is inherently unsafe, as it can interrupt synchronized blocks and
|
|
* leave data in bad states. Hence, there is a security check:
|
|
* <code>checkAccess(this)</code>, plus another one if the current thread
|
|
* is not this: <code>RuntimePermission("stopThread")</code>. If you must
|
|
* catch a ThreadDeath, be sure to rethrow it after you have cleaned up.
|
|
* ThreadDeath is the only exception which does not print a stack trace when
|
|
* the thread dies.
|
|
*
|
|
* @throws SecurityException if you cannot stop the Thread
|
|
* @see #interrupt()
|
|
* @see #checkAccess()
|
|
* @see #start()
|
|
* @see ThreadDeath
|
|
* @see ThreadGroup#uncaughtException(Thread, Throwable)
|
|
* @see SecurityManager#checkAccess(Thread)
|
|
* @see SecurityManager#checkPermission(Permission)
|
|
* @deprecated unsafe operation, try not to use
|
|
*/
|
|
public final void stop()
|
|
{
|
|
// Argument doesn't matter, because this is no longer
|
|
// supported.
|
|
stop(null);
|
|
}
|
|
|
|
/**
|
|
* Cause this Thread to stop abnormally and throw the specified exception.
|
|
* If you stop a Thread that has not yet started, the stop is ignored
|
|
* (contrary to what the JDK documentation says).
|
|
* <b>WARNING</b>This bypasses Java security, and can throw a checked
|
|
* exception which the call stack is unprepared to handle. Do not abuse
|
|
* this power.
|
|
*
|
|
* <p>This is inherently unsafe, as it can interrupt synchronized blocks and
|
|
* leave data in bad states. Hence, there is a security check:
|
|
* <code>checkAccess(this)</code>, plus another one if the current thread
|
|
* is not this: <code>RuntimePermission("stopThread")</code>. If you must
|
|
* catch a ThreadDeath, be sure to rethrow it after you have cleaned up.
|
|
* ThreadDeath is the only exception which does not print a stack trace when
|
|
* the thread dies.
|
|
*
|
|
* @param t the Throwable to throw when the Thread dies
|
|
* @throws SecurityException if you cannot stop the Thread
|
|
* @throws NullPointerException in the calling thread, if t is null
|
|
* @see #interrupt()
|
|
* @see #checkAccess()
|
|
* @see #start()
|
|
* @see ThreadDeath
|
|
* @see ThreadGroup#uncaughtException(Thread, Throwable)
|
|
* @see SecurityManager#checkAccess(Thread)
|
|
* @see SecurityManager#checkPermission(Permission)
|
|
* @deprecated unsafe operation, try not to use
|
|
*/
|
|
public final native void stop(Throwable t);
|
|
|
|
/**
|
|
* Suspend this Thread. It will not come back, ever, unless it is resumed.
|
|
*
|
|
* <p>This is inherently unsafe, as the suspended thread still holds locks,
|
|
* and can potentially deadlock your program. Hence, there is a security
|
|
* check: <code>checkAccess</code>.
|
|
*
|
|
* @throws SecurityException if you cannot suspend the Thread
|
|
* @see #checkAccess()
|
|
* @see #resume()
|
|
* @deprecated unsafe operation, try not to use
|
|
*/
|
|
public final native void suspend();
|
|
|
|
/**
|
|
* Set this Thread's priority. There may be a security check,
|
|
* <code>checkAccess</code>, then the priority is set to the smaller of
|
|
* priority and the ThreadGroup maximum priority.
|
|
*
|
|
* @param priority the new priority for this Thread
|
|
* @throws IllegalArgumentException if priority exceeds MIN_PRIORITY or
|
|
* MAX_PRIORITY
|
|
* @throws SecurityException if you cannot modify this Thread
|
|
* @see #getPriority()
|
|
* @see #checkAccess()
|
|
* @see ThreadGroup#getMaxPriority()
|
|
* @see #MIN_PRIORITY
|
|
* @see #MAX_PRIORITY
|
|
*/
|
|
public final native void setPriority(int newPriority);
|
|
|
|
/**
|
|
* Returns a string representation of this thread, including the
|
|
* thread's name, priority, and thread group.
|
|
*
|
|
* @return a human-readable String representing this Thread
|
|
*/
|
|
public String toString()
|
|
{
|
|
return ("Thread[" + name + "," + priority + ","
|
|
+ (group == null ? "" : group.getName()) + "]");
|
|
}
|
|
|
|
private final native void initialize_native();
|
|
|
|
private final native static String gen_name();
|
|
|
|
/**
|
|
* Returns the map used by ThreadLocal to store the thread local values.
|
|
*/
|
|
static ThreadLocalMap getThreadLocals()
|
|
{
|
|
Thread thread = currentThread();
|
|
ThreadLocalMap locals = thread.locals;
|
|
|
|
return locals;
|
|
}
|
|
|
|
/**
|
|
* Assigns the given <code>UncaughtExceptionHandler</code> to this
|
|
* thread. This will then be called if the thread terminates due
|
|
* to an uncaught exception, pre-empting that of the
|
|
* <code>ThreadGroup</code>.
|
|
*
|
|
* @param h the handler to use for this thread.
|
|
* @throws SecurityException if the current thread can't modify this thread.
|
|
* @since 1.5
|
|
*/
|
|
public void setUncaughtExceptionHandler(UncaughtExceptionHandler h)
|
|
{
|
|
SecurityManager sm = SecurityManager.current; // Be thread-safe.
|
|
if (sm != null)
|
|
sm.checkAccess(this);
|
|
exceptionHandler = h;
|
|
}
|
|
|
|
/**
|
|
* <p>
|
|
* Returns the handler used when this thread terminates due to an
|
|
* uncaught exception. The handler used is determined by the following:
|
|
* </p>
|
|
* <ul>
|
|
* <li>If this thread has its own handler, this is returned.</li>
|
|
* <li>If not, then the handler of the thread's <code>ThreadGroup</code>
|
|
* object is returned.</li>
|
|
* <li>If both are unavailable, then <code>null</code> is returned
|
|
* (which can only happen when the thread was terminated since
|
|
* then it won't have an associated thread group anymore).</li>
|
|
* </ul>
|
|
*
|
|
* @return the appropriate <code>UncaughtExceptionHandler</code> or
|
|
* <code>null</code> if one can't be obtained.
|
|
* @since 1.5
|
|
*/
|
|
public UncaughtExceptionHandler getUncaughtExceptionHandler()
|
|
{
|
|
// FIXME: if thread is dead, should return null...
|
|
return exceptionHandler != null ? exceptionHandler : group;
|
|
}
|
|
|
|
/**
|
|
* <p>
|
|
* Sets the default uncaught exception handler used when one isn't
|
|
* provided by the thread or its associated <code>ThreadGroup</code>.
|
|
* This exception handler is used when the thread itself does not
|
|
* have an exception handler, and the thread's <code>ThreadGroup</code>
|
|
* does not override this default mechanism with its own. As the group
|
|
* calls this handler by default, this exception handler should not defer
|
|
* to that of the group, as it may lead to infinite recursion.
|
|
* </p>
|
|
* <p>
|
|
* Uncaught exception handlers are used when a thread terminates due to
|
|
* an uncaught exception. Replacing this handler allows default code to
|
|
* be put in place for all threads in order to handle this eventuality.
|
|
* </p>
|
|
*
|
|
* @param h the new default uncaught exception handler to use.
|
|
* @throws SecurityException if a security manager is present and
|
|
* disallows the runtime permission
|
|
* "setDefaultUncaughtExceptionHandler".
|
|
* @since 1.5
|
|
*/
|
|
public static void
|
|
setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler h)
|
|
{
|
|
SecurityManager sm = SecurityManager.current; // Be thread-safe.
|
|
if (sm != null)
|
|
sm.checkPermission(new RuntimePermission("setDefaultUncaughtExceptionHandler"));
|
|
defaultHandler = h;
|
|
}
|
|
|
|
/**
|
|
* Returns the handler used by default when a thread terminates
|
|
* unexpectedly due to an exception, or <code>null</code> if one doesn't
|
|
* exist.
|
|
*
|
|
* @return the default uncaught exception handler.
|
|
* @since 1.5
|
|
*/
|
|
public static UncaughtExceptionHandler getDefaultUncaughtExceptionHandler()
|
|
{
|
|
return defaultHandler;
|
|
}
|
|
|
|
/**
|
|
* Returns the unique identifier for this thread. This ID is generated
|
|
* on thread creation, and may be re-used on its death.
|
|
*
|
|
* @return a positive long number representing the thread's ID.
|
|
* @since 1.5
|
|
*/
|
|
public long getId()
|
|
{
|
|
return threadId;
|
|
}
|
|
|
|
/**
|
|
* <p>
|
|
* This interface is used to handle uncaught exceptions
|
|
* which cause a <code>Thread</code> to terminate. When
|
|
* a thread, t, is about to terminate due to an uncaught
|
|
* exception, the virtual machine looks for a class which
|
|
* implements this interface, in order to supply it with
|
|
* the dying thread and its uncaught exception.
|
|
* </p>
|
|
* <p>
|
|
* The virtual machine makes two attempts to find an
|
|
* appropriate handler for the uncaught exception, in
|
|
* the following order:
|
|
* </p>
|
|
* <ol>
|
|
* <li>
|
|
* <code>t.getUncaughtExceptionHandler()</code> --
|
|
* the dying thread is queried first for a handler
|
|
* specific to that thread.
|
|
* </li>
|
|
* <li>
|
|
* <code>t.getThreadGroup()</code> --
|
|
* the thread group of the dying thread is used to
|
|
* handle the exception. If the thread group has
|
|
* no special requirements for handling the exception,
|
|
* it may simply forward it on to
|
|
* <code>Thread.getDefaultUncaughtExceptionHandler()</code>,
|
|
* the default handler, which is used as a last resort.
|
|
* </li>
|
|
* </ol>
|
|
* <p>
|
|
* The first handler found is the one used to handle
|
|
* the uncaught exception.
|
|
* </p>
|
|
*
|
|
* @author Tom Tromey <tromey@redhat.com>
|
|
* @author Andrew John Hughes <gnu_andrew@member.fsf.org>
|
|
* @since 1.5
|
|
* @see Thread#getUncaughtExceptionHandler()
|
|
* @see Thread#setUncaughtExceptionHandler(UncaughtExceptionHandler)
|
|
* @see Thread#getDefaultUncaughtExceptionHandler()
|
|
* @see
|
|
* Thread#setDefaultUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)
|
|
*/
|
|
public interface UncaughtExceptionHandler
|
|
{
|
|
/**
|
|
* Invoked by the virtual machine with the dying thread
|
|
* and the uncaught exception. Any exceptions thrown
|
|
* by this method are simply ignored by the virtual
|
|
* machine.
|
|
*
|
|
* @param thr the dying thread.
|
|
* @param exc the uncaught exception.
|
|
*/
|
|
void uncaughtException(Thread thr, Throwable exc);
|
|
}
|
|
|
|
/**
|
|
* <p>
|
|
* Represents the current state of a thread, according to the VM rather
|
|
* than the operating system. It can be one of the following:
|
|
* </p>
|
|
* <ul>
|
|
* <li>NEW -- The thread has just been created but is not yet running.</li>
|
|
* <li>RUNNABLE -- The thread is currently running or can be scheduled
|
|
* to run.</li>
|
|
* <li>BLOCKED -- The thread is blocked waiting on an I/O operation
|
|
* or to obtain a lock.</li>
|
|
* <li>WAITING -- The thread is waiting indefinitely for another thread
|
|
* to do something.</li>
|
|
* <li>TIMED_WAITING -- The thread is waiting for a specific amount of time
|
|
* for another thread to do something.</li>
|
|
* <li>TERMINATED -- The thread has exited.</li>
|
|
* </ul>
|
|
*
|
|
* @since 1.5
|
|
*/
|
|
public enum State
|
|
{
|
|
BLOCKED, NEW, RUNNABLE, TERMINATED, TIMED_WAITING, WAITING;
|
|
}
|
|
|
|
|
|
/**
|
|
* Returns the current state of the thread. This
|
|
* is designed for monitoring thread behaviour, rather
|
|
* than for synchronization control.
|
|
*
|
|
* @return the current thread state.
|
|
*/
|
|
public native State getState();
|
|
|
|
/**
|
|
* <p>
|
|
* Returns a map of threads to stack traces for each
|
|
* live thread. The keys of the map are {@link Thread}
|
|
* objects, which map to arrays of {@link StackTraceElement}s.
|
|
* The results obtained from Calling this method are
|
|
* equivalent to calling {@link getStackTrace()} on each
|
|
* thread in succession. Threads may be executing while
|
|
* this takes place, and the results represent a snapshot
|
|
* of the thread at the time its {@link getStackTrace()}
|
|
* method is called.
|
|
* </p>
|
|
* <p>
|
|
* The stack trace information contains the methods called
|
|
* by the thread, with the most recent method forming the
|
|
* first element in the array. The array will be empty
|
|
* if the virtual machine can not obtain information on the
|
|
* thread.
|
|
* </p>
|
|
* <p>
|
|
* To execute this method, the current security manager
|
|
* (if one exists) must allow both the
|
|
* <code>"getStackTrace"</code> and
|
|
* <code>"modifyThreadGroup"</code> {@link RuntimePermission}s.
|
|
* </p>
|
|
*
|
|
* @return a map of threads to arrays of {@link StackTraceElement}s.
|
|
* @throws SecurityException if a security manager exists, and
|
|
* prevents either or both the runtime
|
|
* permissions specified above.
|
|
* @since 1.5
|
|
* @see #getStackTrace()
|
|
*/
|
|
public static Map<Thread, StackTraceElement[]> getAllStackTraces()
|
|
{
|
|
ThreadGroup group = currentThread().group;
|
|
while (group.getParent() != null)
|
|
group = group.getParent();
|
|
int arraySize = group.activeCount();
|
|
Thread[] threadList = new Thread[arraySize];
|
|
int filled = group.enumerate(threadList);
|
|
while (filled == arraySize)
|
|
{
|
|
arraySize *= 2;
|
|
threadList = new Thread[arraySize];
|
|
filled = group.enumerate(threadList);
|
|
}
|
|
Map traces = new HashMap();
|
|
for (int a = 0; a < filled; ++a)
|
|
traces.put(threadList[a],
|
|
threadList[a].getStackTrace());
|
|
return traces;
|
|
}
|
|
|
|
/**
|
|
* <p>
|
|
* Returns an array of {@link StackTraceElement}s
|
|
* representing the current stack trace of this thread.
|
|
* The first element of the array is the most recent
|
|
* method called, and represents the top of the stack.
|
|
* The elements continue in this order, with the last
|
|
* element representing the bottom of the stack.
|
|
* </p>
|
|
* <p>
|
|
* A zero element array is returned for threads which
|
|
* have not yet started (and thus have not yet executed
|
|
* any methods) or for those which have terminated.
|
|
* Where the virtual machine can not obtain a trace for
|
|
* the thread, an empty array is also returned. The
|
|
* virtual machine may also omit some methods from the
|
|
* trace in non-zero arrays.
|
|
* </p>
|
|
* <p>
|
|
* To execute this method, the current security manager
|
|
* (if one exists) must allow both the
|
|
* <code>"getStackTrace"</code> and
|
|
* <code>"modifyThreadGroup"</code> {@link RuntimePermission}s.
|
|
* </p>
|
|
*
|
|
* @return a stack trace for this thread.
|
|
* @throws SecurityException if a security manager exists, and
|
|
* prevents the use of the
|
|
* <code>"getStackTrace"</code>
|
|
* permission.
|
|
* @since 1.5
|
|
* @see #getAllStackTraces()
|
|
*/
|
|
public StackTraceElement[] getStackTrace()
|
|
{
|
|
SecurityManager sm = SecurityManager.current; // Be thread-safe.
|
|
if (sm != null)
|
|
sm.checkPermission(new RuntimePermission("getStackTrace"));
|
|
|
|
// Calling java.lang.management via reflection means that
|
|
// javax.management be overridden in the endorsed directory.
|
|
|
|
// This is the equivalent code:
|
|
//
|
|
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
|
|
// ThreadInfo info = bean.getThreadInfo(getId(), Integer.MAX_VALUE);
|
|
// return info.getStackTrace();
|
|
|
|
try
|
|
{
|
|
try
|
|
{
|
|
Object bean
|
|
= (Class.forName("java.lang.management.ManagementFactory")
|
|
.getDeclaredMethod("getThreadMXBean")
|
|
.invoke(null));
|
|
Object info = bean.getClass()
|
|
.getDeclaredMethod("getThreadInfo", long.class, int.class)
|
|
.invoke(bean, new Long(getId()), new Integer(Integer.MAX_VALUE));
|
|
Object trace = info.getClass()
|
|
.getDeclaredMethod("getStackTrace").invoke(info);
|
|
return (StackTraceElement[])trace;
|
|
}
|
|
catch (InvocationTargetException e)
|
|
{
|
|
throw (Exception)e.getTargetException();
|
|
}
|
|
}
|
|
catch (UnsupportedOperationException e)
|
|
{
|
|
throw e;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw new UnsupportedOperationException(e);
|
|
}
|
|
}
|
|
}
|