- 浏览: 236853 次
- 性别:
- 来自: 苏州
文章分类
- 全部博客 (188)
- Java (68)
- SQL (9)
- JavaScript (1)
- Spring (3)
- Struts (0)
- OS (4)
- Mywork (8)
- IT News (10)
- Passtime (15)
- English (11)
- SCJP (2)
- Linux (4)
- Maven (6)
- OpenSource (1)
- 持续集成CI (1)
- CVS (3)
- Hudson (3)
- OpenID (5)
- Web (8)
- Project Management (6)
- CRM (3)
- CaseStudy (2)
- SSO (1)
- OpenLDAP (4)
- Thinking (1)
- JGroup (1)
最新评论
-
guji528:
谢谢分享!
一些关于Emma的资料 -
atgoingguoat:
我也碰到这个问题
Linux 下具体如何处理.
java.net.UnknownHostException: ibatis.apache.org -
zerostar88:
http://www.limodev.cn/blog/arch ...
HTC G3 刷 Recovery and ROM -
zerostar88:
but DES now is deprecated, we u ...
DES/CBC/PKCS5Padding密码 -
xnxylxh:
辛苦了
数字证书
Debug your Java code with ease using JPDA
Source: http://articles.techrepublic.com.com/5100-10878_11-6139512.html
Takeaway: The Java Platform Debugger Architecture (JPDA) helps developers debug a running Java application in all situations. Peter V. Mikhalenko explains how this technology works and discusses some practical aspects of its usage.
Debugging a Java program can be really boring, especially when it's not easy to get access to the running instance. The problem becomes even more difficult when an application runs on a remote environment and does not produce any output on the console or log file. The Java Platform Debugger Architecture (JPDA) technology from Sun helps when you need to debug a running Java application in all situations.
JPDA is a collection of APIs aimed to help with debugging Java code. The JPDA set of tools is available in J2SE starting from the 1.2.2 version, and beginning from 1.3.x, it's included directly into the J2SE package.
It's important to understand that JPDA is not an application or a debugging tool but a set of well-designed and implemented interfaces and protocols. Sun's mission in this standard is to provide an infrastructure, so third-party tools and debuggers can use it in the most efficient way. There are a lot of excellent debuggers and IDEs that use JPDA, including such widely recognized tools as Borland JBuilder, Oracle JDeveloper, IntelliJ IDEA, Sun NetBeans, IBM Eclipse, and many others. However, Sun provides a reference implementation in its traditional command-line debugger jdb, rewritten in Java 1.3 for supporting JPDA. In this article, I will discuss the JPDA technology and some practical aspects of its usage.
How it works
JPDA consists of three interfaces designed for use by debuggers in development environments for desktop systems. The Java Virtual Machine Tools Interface (JVMTI) defines the services a VM must provide for debugging. (JVMTI in Java 5.0 is a replacement for the Java Virtual Machine Debug Interface, which has been deprecated). The Java Debug Wire Protocol (JDWP) defines the format of information and requests transferred between the process being debugged and the debugger front end, which implements the Java Debug Interface (JDI). The JDI defines information and requests at the user code level.
The JPDA concept splits the debugging process into two parts: the program that is being debugged ("debuggee") and the JDI, which is normally a user interface of a debugger application (or a part of Java IDE). A debuggee application runs in a back-end part, while the JDI runs in a front-end part. Between the back-end and a front-end there is a communication channel working on top of the JDWP protocol; therefore, the debuggee and the debugger can be located on the same box or on different boxes.
From a developer's point of view, a debugger application may hook into JPDA at any layer. Since the JDI is the highest level and the easiest to use, it's always recommended to use this interface. Suppose a company develops a debugger using JDI. The company can use it with the reference implementation, and it will automatically work with the VMs and the platforms Sun supports, thus most IDE vendors go that way. It can also work, for example, with the reference implementation front-end and a debuggee running another company's VM that implements JDWP (which might use or by-pass JVMTI).
Some debuggers are built on top of lower layers, such as JDWP (for example, if the front-end is not written in Java) or JVMTI (for specialized debuggers which need low-level functionality).
The back-end of the debugger is responsible for communicating requests like "tell me the value of variable X" from the debugger front-end to the debuggee VM and for communicating the response to these requests (including desired events like breakpoint reach) to the front-end. The back-end communicates with the front-end over a communications channel using the JDWP. The back-end communicates with the debuggee VM using the JVMTI.
The communications channel is the link between the front- and back-ends of the debugger. You can think of it as consisting of two mechanisms: a connector and a transport. A connector is a JDI object that is the means by which a connection is established between the front- and back-ends. There can be three types of connectors:
- listening : The front-end listens for an incoming connection from the back-end.
- attaching : The front-end attaches to an already running back-end.
- launching : The front-end actually launches the Java process that will run the debuggee code and the back-end.
A transport is the underlying mechanism used to move bits between the front-end and the back-end. The transport mechanism that must be used is not specified in the JPDA specification; possible mechanisms include: sockets, serial lines, and shared memory. However, the format and semantics of the serialized bit-stream flowing over the channel is specified by the JDWP. Most IDEs and debuggers support two transport types (as does the Sun reference implementation): shared memory (if the debuggee and debugger are located on the same box) and socket (the debuggee and debugger can be located anywhere, including the same box).
Starting with J2SE 5.0, JPDA includes service provider interfaces to allow the development and deployment of connector and transport implementations. These service provider interfaces allow the debugger and other tool vendors to develop new connector implementations and provide additional transport mechanisms over and beyond the socket and shared memory transport provided by Sun.
The communication between the debuggee and debugger is connection oriented; therefore one side must act as a server, listening for a connection. The other side acts as a client and connects to the server. JPDA allows either the debugger application or the target VM to act as the server.
Use JPDA in practice
If you need to use socket transport, identify the type of transport as name dt_socket in the corresponding JVM argument. If the debugger and debuggee are located on the same machine and the box is Windows-based, you can use shared memory connector with the name dt_shmem. If you want to debug your application with a JPDA-compliant debugger, you should just run it with debug mode switched on and pass additional parameters such as transport type, names of hosts and port number, and other information. All JPDA and debugging parameters must be passed as arguments to Java VM at the start of your application.
To enable debugging you should load the JDWP agent for debugging into your application's JVM. Starting from Java 5.0, you can do it with -agentlib:jdwp option. For releases prior to 5.0, the -Xdebug and -Xrunjdwp options are used (the 5.0 implementation also supports the -Xdebug and -Xrunjdwp options, but the newer -agentlib:jdwp option is preferable as the JDWP agent in 5.0 uses the JVMTI interface to the VM rather than the older JVMDI interface). You should provide sub-options to the –agentlib:jdwp parameter (in Java 5.0) or to –Xrunjdwp: (prior to Java 5.0); the set of possible sub-options is the same.
The sub-options are specified as follows:
-agentlib:jdwp=<name1>[=<value1>],<name2>[=<value2>]...
or
-Xrunjdwp:<name1>[=<value1>],<name2>[=<value2>]...
You can use these options:
- help: prints a brief message on how to use it and exits the VM.
- server : ("n" or "y") If "y," listen for a debugger application to attach; otherwise, attach to the debugger application at the specified address.
- address : transport address for the connection. If server=n, attempt to attach to a debugger application at this address. If server=y, listen for a connection at this address.
- timeout : If server=y, this specifies the timeout, in milliseconds, to wait for the debugger to attach. If server=n, this specifies the timeout, in milliseconds, to use when attaching to the debugger.
- suspend : If "y," JVM suspends the execution until a debugger connects to the debuggee JVM.
Here are command line examples:
-agentlib:jdwp=transport=dt_socket,server=y,address=8000
Listen for a socket connection on port 8000. Suspend this VM before the main class loads (suspend=y by default). Once the debugger application connects, it can send a JDWP command to resume the VM.
-agentlib:jdwp=transport=dt_shmem,server=y,suspend=n
Choose an available shared memory transport address and print it to stdout. Listen for a shared memory connection at that address. Allow the VM to begin executing before the debugger application attaches.
-agentlib:jdwp=transport=dt_socket,address=myhost:8000
Attach to a running debugger application via socket on host myhost at port 8000. Suspend this VM before the main class loads.
Peter V. Mikhalenko is a Sun certified professional who works for Deutsche Bank as a business consultant.
发表评论
-
Java 代码块加载顺序
2015-07-19 13:29 607静态代码块 > 构造代码块 > 构造方法 pu ... -
Sprint JPA Test
2015-02-14 13:45 859@RunWith(SpringJUnit4ClassRunn ... -
WARNING: JMockit was initialized on demand, which may cause certain tests to fai
2013-08-05 09:04 2324When we using Jmokit and Junit ... -
Common log4j Console output when unit testing
2013-08-02 10:23 752#set up stdout appenderlog4j.ap ... -
JGroups 广播检查
2013-01-08 09:52 917先下载JGroup jar包 设置到环境变量CLASSPAT ... -
(转)一步步优化JVM4:决定Java堆的大小以及内存占用
2012-09-22 10:45 937一步步优化JVM4:决定Java堆的大小以及内存占用 htt ... -
让开发自动化: 用 Eclipse 插件提高代码质量
2012-08-02 22:25 1094让开发自动化: 用 Eclipse ... -
从 Java 代码到 Java 堆 理解和优化您的应用程序的内存使用
2012-08-01 09:29 1008从 Java 代码到 Java 堆 理解和优化您的应用程 ... -
Unable to read TLD from JAR file
2011-07-06 14:35 1366Today I try myBatis project Jpe ... -
Java Trouble shooting from IBM
2011-06-16 15:50 784Here is a good repository for J ... -
DES/CBC/PKCS5Padding密码
2011-05-10 10:06 3707DES/CBC/PKCS5Padding 加密解密 i ... -
【java】AES加密解密 AES/CBC/PKCS5Padding
2011-05-10 10:05 18188<Source>http://www.cnblog ... -
Tomcat JNDI configuration
2010-10-18 14:15 1128Tomcat JNDI configuration ... -
(转)设计与开发 JAX-WS 2.0 Web 服务
2010-10-11 08:33 1028https://www6.software.ibm.com/d ... -
初学者如何开发出高质量J2EE系统
2010-09-16 08:34 858(转自CSDN)初学者如何开发出高质量J2EE系统 S ... -
Jpetstore
2010-09-16 08:32 1053http://www.hudong.com/wiki/Jpet ... -
Google SAML2 SSO
2010-09-09 16:40 1532Source: http://code.google.com/ ... -
(Forward)程序员从初级到中级10个秘诀
2010-08-22 11:06 812http://sd.csdn.net/a/20100820/2 ... -
为什么5%的技术人员开发效率是其他95%的20倍?
2010-08-22 10:54 868Source: http://sd.csdn.net/a/20 ... -
2009 Java 专区最受欢迎内容
2010-08-18 14:02 8162009 Java 专区最受欢迎内容 http://www. ...
相关推荐
Administrate MySQL Databases With Ease Using a Graphical Interface MySQL is probably the world's most popular open source database engine but it can b
Build fast and concurrent applications with ease, without the complexity of Java's concurrent API and shared states Explore a wide variety of code examples to easily get used to all the features and ...
By the end of the book, you’ll be fully prepared to take advantage of Java's ease of development, and able to create powerful, sophisticated Java applications. What youll learn How to use and ...
By the end of the book, you’ll be fully prepared to take advantage of Java's ease of development, and able to create powerful, sophisticated Java applications. What youll learn How to use and ...
What You Will Learn Discover Jenkins Blue Ocean and how to use it ...code Extend pipelines with Jenkins shared libraries Visualize pipelines from classic Jenkins in Blue Ocean Configure and view test ...
you'll not only have a lovely little project management application app running, but you'll also take with you the confidence to innovate and build your own applications with ease. What you will ...
What you will learnIdentify performance bottlenecks in an ...with Java EE applicationsImplement transparent caching on your applicationsExtract more information from your applications using ...
Analyze the Titanic data set to obtain desired results with ease Implement and organize your Tensorflow projects in a professional manner Use Tensorboard to inspect various metrics and monitor your ...
名称:copy 2 clipboard with ease ---------------------------------------- 版本:2.1.0 作者:cage.chung 分类:实用工具 ---------------------------------------- 概述:轻松复制标签标题和网址的简单方法。 ...
The subscription also includes CodeRush for Visual Studio, so you can Code-Debug-Refactor with ease. What's Included PLATFORMS: WinForms ASP.NET WPF Silverlight Windows 8 XAML FRAMEWORKS: ...
the book ends by walking you through building a Java client for your RESTful web service, along with some scaling techniques using the new Spring Reactive libraries. What You Will Learn Deep dive ...
your webpage with ease. Google brought web services that anyone can connect to and use their services without any cost. Well, there is some restriction to the use of gmap. They have two versions of ...
The subscription also includes CodeRush for Visual Studio, so you can Code-Debug-Refactor with ease. What's Included PLATFORMS: WinForms ASP.NET WPF Silverlight Windows 8 XAML FRAMEWORKS: ...
What you will learnIdentify performance bottlenecks in an ...with Java EE applicationsImplement transparent caching on your applicationsExtract more information from your applications using ...
Deploy deep learning solutions in production with ease using TensorFlow. You'll also develop the mathematical understanding and intuition required to invent new deep learning architectures and ...
Chapter 1 will introduce you to pure OpenCV on the JVM using Java, Scala, and Kotlin and present some of their shortcomings. Chapter 2 will present Origami, the Clojure wrapper, and how to use it to ...