The jstack Utility | jstack Tutorial | scmGalaxy

jstack-utility

The release of JDK 8 introduced Java Mission Control, Java Flight Recorder, and jcmd utility for diagnosing problems with JVM and Java applications. It is suggested to use the latest utility, jcmd instead of the previous jstack utility for enhanced diagnostics and reduced performance overhead.

The following sections describe troubleshooting techniques with jstack utility.

2.16.1 Troubleshoot with jstack Utility

The jstack command-line utility attaches to the specified process or core file and prints the stack traces of all threads that are attached to the virtual machine, including Java threads and VM internal threads, and optionally native stack frames. The utility also performs deadlock detection.

The utility can also use the jsadebugd daemon to query a process or core file on a remote machine. Note: The output takes longer to print in this case.

A stack trace of all threads can be useful in diagnosing a number of issues, such as deadlocks or hangs.

The -l option, which instructs the utility to look for ownable synchronizers in the heap and print information about java.util.concurrent.locks. Without this option, the thread dump includes information only on monitors.

The output from the jstack pid option is the same as that obtained by pressing Ctrl+\ at the application console (standard input) or by sending the process a QUIT signal. See Control+Break Handler for an output example.

Thread dumps can also be obtained programmatically using the Thread.getAllStackTraces method, or in the debugger using the debugger option to print all thread stacks (the where command in the case of the jdb sample debugger).

For more details on the jstack utility, see the jstack command man page.

2.16.2 Force a Stack Dump

If the jstack pid command does not respond because of a hung process, then the -F option can be used (on Oracle Solaris and Linux operating systems only) to force a stack dump, as shown in Example 2-29.

Example 2-29 Force a Stack Dump with jstack Utility

$ jstack -F 8321 Attaching to process ID 8321, please wait... Debugger attached successfully. Client compiler detected. JVM version is 1.6.0-rc-b100 Deadlock Detection: Found one Java-level deadlock: ============================= "Thread2": waiting to lock Monitor@0x000af398 (Object@0xf819aa10, a java/lang/String), which is held by "Thread1" "Thread1": waiting to lock Monitor@0x000af400 (Object@0xf819aa48, a java/lang/String), which is held by "Thread2" Found a total of 1 deadlock. Thread t@2: (state = BLOCKED) Thread t@11: (state = BLOCKED) - Deadlock$DeadlockMakerThread.run() @bci=108, line=32 (Interpreted frame) Thread t@10: (state = BLOCKED) - Deadlock$DeadlockMakerThread.run() @bci=108, line=32 (Interpreted frame) Thread t@6: (state = BLOCKED) Thread t@5: (state = BLOCKED) - java.lang.Object.wait(long) @bci=-1107318896 (Interpreted frame) - java.lang.Object.wait(long) @bci=0 (Interpreted frame) - java.lang.ref.ReferenceQueue.remove(long) @bci=44, line=116 (Interpreted frame) - java.lang.ref.ReferenceQueue.remove() @bci=2, line=132 (Interpreted frame) - java.lang.ref.Finalizer$FinalizerThread.run() @bci=3, line=159 (Interpreted frame) Thread t@4: (state = BLOCKED) - java.lang.Object.wait(long) @bci=0 (Interpreted frame) - java.lang.Object.wait(long) @bci=0 (Interpreted frame) - java.lang.Object.wait() @bci=2, line=485 (Interpreted frame) - java.lang.ref.Reference$ReferenceHandler.run() @bci=46, line=116 (Interpreted frame)

2.16.3 Stack Trace from a Core Dump

To obtain stack traces from a core dump, execute the jstack command on a core file, as shown in Example 2-30.

Example 2-30 Stack Trace from a Core Dump

$ jstack $JAVA_HOME/bin/java core

2.16.4 Mixed Stack

The jstack utility can also be used to print a mixed stack; that is, it can print native stack frames in addition to the Java stack. Native frames are the C/C++ frames associated with VM code and JNI/native code.

To print a mixed stack, use the -m option, as shown in Example 2-31.

Example 2-31 Mixed Java Stack with jstack Utility

$ jstack -m 21177 Attaching to process ID 21177, please wait... Debugger attached successfully. Client compiler detected. JVM version is 1.6.0-rc-b100 Deadlock Detection: Found one Java-level deadlock: ============================= "Thread1": waiting to lock Monitor@0x0005c750 (Object@0xd4405938, a java/lang/String), which is held by "Thread2" "Thread2": waiting to lock Monitor@0x0005c6e8 (Object@0xd4405900, a java/lang/String), which is held by "Thread1" Found a total of 1 deadlock. ----------------- t@1 ----------------- 0xff2c0fbc __lwp_wait + 0x4 0xff2bc9bc _thrp_join + 0x34 0xff2bcb28 thr_join + 0x10 0x00018a04 ContinueInNewThread + 0x30 0x00012480 main + 0xeb0 0x000111a0 _start + 0x108 ----------------- t@2 ----------------- 0xff2c1070 ___lwp_cond_wait + 0x4 0xfec03638 bool Monitor::wait(bool,long) + 0x420 0xfec9e2c8 bool Threads::destroy_vm() + 0xa4 0xfe93ad5c jni_DestroyJavaVM + 0x1bc 0x00013ac0 JavaMain + 0x1600 0xff2bfd9c _lwp_start ----------------- t@3 ----------------- 0xff2c1070 ___lwp_cond_wait + 0x4 0xff2ac104 _lwp_cond_timedwait + 0x1c 0xfec034f4 bool Monitor::wait(bool,long) + 0x2dc 0xfece60bc void VMThread::loop() + 0x1b8 0xfe8b66a4 void VMThread::run() + 0x98 0xfec139f4 java_start + 0x118 0xff2bfd9c _lwp_start ----------------- t@4 ----------------- 0xff2c1070 ___lwp_cond_wait + 0x4 0xfec195e8 void os::PlatformEvent::park() + 0xf0 0xfec88464 void ObjectMonitor::wait(long long,bool,Thread*) + 0x548 0xfe8cb974 void ObjectSynchronizer::wait(Handle,long long,Thread*) + 0x148 0xfe8cb508 JVM_MonitorWait + 0x29c 0xfc40e548 * java.lang.Object.wait(long) bci:0 (Interpreted frame) 0xfc40e4f4 * java.lang.Object.wait(long) bci:0 (Interpreted frame) 0xfc405a10 * java.lang.Object.wait() bci:2 line:485 (Interpreted frame) ... more lines removed here to reduce output... ----------------- t@12 ----------------- 0xff2bfe3c __lwp_park + 0x10 0xfe9925e4 AttachOperation*AttachListener::dequeue() + 0x148 0xfe99115c void attach_listener_thread_entry(JavaThread*,Thread*) + 0x1fc 0xfec99ad8 void JavaThread::thread_main_inner() + 0x48 0xfec139f4 java_start + 0x118 0xff2bfd9c _lwp_start ----------------- t@13 ----------------- 0xff2c1500 _door_return + 0xc ----------------- t@14 ----------------- 0xff2c1500 _door_return + 0xc

Frames that are prefixed with an asterisk (*) are Java frames, whereas frames that are not prefixed with an asterisk are native C/C++ frames.

The output of the utility can be piped through c++filt to demangle C++ mangled symbol names. Because the Java HotSpot VM is developed in the C++ language, the jstack utility prints C++ mangled symbol names for the Java HotSpot internal functions.

The c++filt utility is delivered with the native C++ compiler suite: SUNWspro on Oracle Solaris operating system and gnu on Linux.

Tagged : / / / / / / / / /

Jacksum – a java checksum utility – Introduction and usage

jacksum-introduction

Jacksum, a java checksum utility

Software Name : Jacksum

Website : http://jacksum.net/en/index.html

Version : 1.7.0

Jacksum is a platform independent checksum utility (written entirely in Java) for computing and verifying (integrity check) checksums, CRC and hashes (fingerprints). It supports 58 popular hash algorithms and a lot of unique features.

The Jacksum is a freeware tool and suitable for more advanced users verify checksum values. It is platform independent software (support Windows and Unix) and supports 58 popular standard algorithms (Adler32, BSD sum, Bzip2’s CRC-32, POSIX cksum, CRC-8, CRC-16, CRC-24, CRC-32 (FCS-32), CRC-64, ELF-32, eMule/eDonkey, FCS-16, GOST R 34.11-94, HAS-160, HAVAL (3/4/5 passes, 128/160/192/224/256 bits), MD2, MD4, MD5, MPEG-2’s CRC-32, RIPEMD-128, RIPEMD-160, RIPEMD-256, RIPEMD-320, SHA-0, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, Tiger-128, Tiger-160, Tiger, Tiger2, Tiger Tree Hash, Tiger2 Tree Hash, Unix System V sum, sum8, sum16, sum24, sum32, Whirlpool-0, Whirlpool-1, Whirlpool and xor8).
The Jacksum is written in Java and open source, we can download the source code and try to understand how Jacksum implement the above algorithm.
Use of Jacksum

  • Often time, while we downloading files or software via some secure website, “Checksum” values in MD5 or SHA1 format are provided to protect users from downloading corrupted files or trojan infected files. Unfortunately, many users has no idea how to verify the downloaded file with “Checksum” value, end up in downloading virus or trojan infected files.
  • With Jacksum you can check if a filetransfer was successful. If you download software or huge files, like CD-images (so called iso files) from the internet, often there is a checksum or a hashcode provided. With Jacksum you can calculate such a checksum or hashcode from your local copy. If both checksequences are identical you know that the filetransfer was successful.
  • As Jacksum supports recursively file processing, you can compare two directory trees. Therefore you will be able to verify, if your copies or backups are identical with the original source, even if you don’t have access to both trees at the same time (compare two DVDs with just one drive for example).
  • Jacksum can assist you if you want to perform an unidirectional sync of two directory trees, even if they are on two different computer without a connection in between.
    As Jacksum reads each byte of a file, you can check if all files are still readable on your CD-ROM or DVD.
  • As Jacksum supports a platform independent and compatible file format, it helps you to verify data integrity of burned data on CD-ROMs or DVDs even after many years and even if you will have changed your Operating System.
  • Jacksum can help you to create incremental backups. If you are a developer, Jacksum can help you to create patches for your customers.
  • You can use Jacksum for intrusion detection, because Jacksum can check whether and what files have been changed or deleted on your system. Jacksum can not only check the content of each file you want, but also the file timestamps.
  • Use Jacksum for website content change detection, so get informed if something has changed on your favorite website (can be useful if the website has no announcement-mail-alias).
  • This software is OSI Certified Open Source software
  • It is entirely free software (it runs on free platforms and therefore it is listed also at the Free
  • Software Foundation directory)
  • It is free of charge, it costs nothing
  • It is free of registration (well, I’m happy if you write an e-mail to jonelo@jonelo.de for feedback
  • It never expires
    Requirements:· JRE version 1.3.1 or later

Links:
http://manpages.ubuntu.com/manpages/jaunty/man1/jacksum.1.html
http://linux.softpedia.com/get/Utilities/Jacksum-7175.shtml
http://packages.ubuntu.com/lucid/jacksum
https://jacksum.dev.java.net/
http://www.jonelo.de/java/jacksum/
http://sourceforge.net/projects/jacksum/

Tagged : / / / / / / / / / / / / / / /

SSARC Utility & SSRESTOR Utility – Archive, Restore VSS Project – Guide

ssarc-utility-ssrestor-utility

Question: 

How to Archive VSS Project in Visual Source Safe (VSS)?

How to Restore VSS Project in  Visual Source Safe (VSS)?

What is SSARC Utility?

What is SSRESTOR Utility?

SSARC Utility

Allows you to archive files, projects, or old versions from a Visual SourceSafe database. Each time you run SSARC (Ssarc.exe), the utility asks only once before it deletes the files/projects. Visual SourceSafe also implements archive operations through its Archive wizard, available in Visual SourceSafe Administrator.

The utility SSRESTOR is used for restoration of archived files. Use of SSARC and SSRESTOR together allows wide-area Visual SourceSafe installations to move files and projects among databases.

Limitation: SSARC cannot create an archive file that is greater than 2 GB. If you try to archive a project larger than this, you will receive an Out of Memory and/or a CRC mismatch error message. To work around this limitation, you will need to archive each subproject.

 

Syntax

ssarc [-C][-D][-I-][-O][-S][-V][-X][-Y] <archive file to create> <files/projects to archive>

If you are not familiar with the syntax conventions used, < and > are used to delimit arguments. The < and > characters are not typed in. The | means a choice of options. Items enclosed in square brackets, [] are optional, and items not enclosed in square brackets are mandatory.

 

Utility Options

The following table describes options available with SSARC.

-C

Specifies a comment (standard Visual SourceSafe parameter). The comment is inserted into the Visual SourceSafe history if the items are deleted from the database as part of the archived record. The comment is also inserted into the archive file itself, if there is one.

-C-

Specifies no comment.

-D

Deletes the archived items from the database.

Specifiying the -d option will delete from your project the items that you are archiving. This will delete your project from Sourcesafe if you use it! Of course, you can restore from your backup file, but for normal use, and for smaller projects I don’t recommend this. This function obviously has its uses, but be sure you want to do this.

-D-

Controls whether Visual SourceSafe actually deletes anything from the database. If this option is not used, the default is to ask.

If the -d- option is used, then SSARC will not delete the projects the items you are archiving. The default is to prompt the user interactively, so if you want to run this from a script, you will need to choose one of the options, or use the -i- flag

-I-

Specifies no prompt for input (standard Visual SourceSafe parameter).

-O

Paginates or redirects output (standard Visual SourceSafe parameter).

-S<srcsafe.ini path>, <data path>

Specifies a path to Srcsafe.ini and the Data directory. The full syntax looks like -Sc: \VSS, OldDB. The item before the comma is the full path to Srcsafe.ini, and the item after the comma is the string in parentheses in a Data_Path setting. If there is no comma, a Srcsafe.ini path is indicated, but no data string. If the first character after the –S is a comma, a data string is specified, but no Srcsafe.ini path.

 

-V[D|L]<version>

Specifies a version number to archive (standard Visual SourceSafe parameter). Enter the version number in standard Visual SourceSafe format (number, date, or label). If this option is not used, SSARC operates on entire files or projects, instead of all versions up to and including a certain version.

Note that SSARC is generally inclusive. That is, if you type –V9, you create an archive file that contains version 9.0 and everything before it. The delete pass is also inclusive, that is, version 9.0 is actually deleted unless it is in the label format. In the latter case, the label is stored in the archive file but is not deleted. If –V is specified, you never delete the current version, even if you specify -D9/9/99. If you are using a version the label format, and the label has a space in it, you must place the entire option in quotation marks, for example, “-VThisOne”.

-X

Archives only deleted items in the specified files and projects. Deleted items are still stored in the Visual SourceSafe database unless the Destroy Permanently option is selected when performing a Delete command.

-X-

Archives all items in the specified files and projects.

-Y<user>,<pwd>

Specifies the user name and password (standard Visual SourceSafe parameter). An example is -YAdmin,Bunny.

archive file to create

Specifies the name of the archive file to create during the archive operation.

files/projects to archive

Specifies files and projects to back up.

Examples

SSARC -d- -yadmin,password archive.ssa $/
Backup the entire default Sourcesafe database to archive.ssa, leaving the database exactly as it is.
SSARC -d- "-vlProduction Release" -yadmin,password -olog.txt archive.ssa $/Test
Backup everything since the version labelled ‘Production Release’ and create a log file with the results of the archiving process.
SSARC -d -x -yadmin,password archive.ssa "$/Project Global Domination" $/OtherProject
Archive, and delete the deleted files from two projects.
SSARC -i -yadmin,password -olog.txt "-cArchive Everything" archive.ssa $/
Archive the entire Sourcesafe database, while creating a log file, adding a comment, and running non-interactively, suitable for a scheduled task.

SSRESTOR Utility

Restores information from a previously created archive. If the restore operation attempts to create a duplicate file or project name, the operation fails. Visual SourcSafe also implements restore operations through its Restore wizard, available in Visual SourceSafe Administrator.

Limitation: SSRESTOR cannot restore a project that is larger than 2 GB. A project larger than this cannot be archived.

 

Syntax:

ssrestor [-C][-I-][-L][-O][-P<project>][-S][-T][-X][-Y]

<archive file to restore> [files/projects]

 

Utility Options

The following table describes options available with this command.

-C

Specifies a comment (standard Visual SourceSafe parameter). The comment is applied to the history entry for restored item(s).

-C-

Specifies no comment.

-I-

Specifies no input (standard Visual SourceSafe parameter).

-L

Specifies a list only, without any restoration.

-LA

Specifies a list of all files and subprojects listed under a project, for example, project $/A.

-O

Redirects output (standard Visual SourceSafe parameter).

-P<project>

Specifies a project to which to restore content. For instance, if you archive $/A/BAR.C and then restore it, it will be restored as $/A/BAR.C.

-S<srcsafe.ini path><data path>

Specifies a path to Srcsafe.ini and the Data directory.

-T

Tests the archive file for corruption, but does not actually restore from the archive.

-X, -X-

Identifies an item that you want to restore, for example, $/a/b. This option distinguishes between deleted projects and undeleted projects that have the same names. For example, if you have deleted $a/b and specify the -X option, SSRESTOR restores the deleted $/a/b. If you specify -X-, SSRESTOR restores an undeleted $/a/b. Even though they have the same name, note that these are two different projects that the utility treats differently.

-Y<user>,<pwd>

Specifies user name and password (standard Visual SourceSafe parameter). An example is -YAdmin,Moggy.

archive file to restore

Specifies the name of the archive file from which to restore the database.

files/projects

Specifies files and projects to restore.

Examples

SSRESTOR -la -yadmin,password archive.ssa $/
Display a list of all of the files archived in archive.ssa.
SSRESTOR "-p$/Test 2" -sD:\newfolder\ -yadmin,password backup.ssa $/Test
Restores project $/Test to the database to a new location, $/Test 2, from the archive file backup.ssa, in a different Sourcesafe database.

Miscellaneous tips

  • Putting the path to the <VSS PATH>\win32 folder in your PATH environment variable makes shell commands a lot easier
  • If you get a message “Only ADMIN can run this utility”, it means that you are either not specifying the admin account, or the password is incorrect. Use "-yadmin,password" if the admin password is “password”, or "-yadmin," if the admin password is not set (not recommended!).
  • If you are using an option that has a space in the argument, enclose the whole thing with quote marks, i.e. “-p$/Project A”
  • A daily archive is easy to do with a Windows shell script, maybe something like this. Then use Scheduled Tasks to have this run every day.
    function q (str)
    	' to make the command a bit more readable, I hope
    	q = """" & str & """"
    end function

    PROJECT = “$/”
    USERID = “admin”
    PASSWORD = “admin”

    ‘ location of SSARC program
    SSARCPATH = “C:\program files\microsoft visual studio\common\vss\win32\ssarc.exe”
    ‘ folder of srcsafe.ini
    SRCSAFEINIPATH = “”
    ‘ prepended to filename in case you’re doing more than one.
    LABEL = “ARCHIVE”
    ‘ destination of archive files
    BACKUPFOLDER = “C:\BACKUPS\”

    ‘ generate a name based on the time.
    today = now()
    backupfilename = LABEL & “-” & formatdatetime(now,2) & “.ssa”

    cmd = q(SSARCPATH) & ” ” & _
    q(“-s” & SRCSAFEINIPATH & “,”) & ” -i- ” & ” -d- ” & _
    q(“-y” & USERID & “,” & PASSWORD) & ” ” & _
    q(BACKUPFOLDER & backupfilename) & ” ” & q(PROJECT)

    Set WshShell = WScript.CreateObject(“WScript.Shell”)
    wscript.echo cmd
    WshShell.run cmd
    set wsshell = nothing

Tagged : / / / / / / / / / / / / / / / / / / / /