DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Java Developers, Don't Throw Out Your Mac Yet: Apple Will Contribute To OpenJDK
  • Java Development Trends 2023
  • Binary Code Verification in Open Source World
  • Hack OpenJDK with NetBeans IDE

Trending

  • How to Migrate Vector Data from PostgreSQL to MyScale
  • An Introduction to Build Servers and Continuous Integration
  • Information Security: AI Security Within the IoT Industry
  • The Stairway to Apache Kafka® Tiered Storage
  1. DZone
  2. Coding
  3. Java
  4. Debugging OpenJDK

Debugging OpenJDK

Jakub Kubrynski user avatar by
Jakub Kubrynski
·
Aug. 23, 14 · Interview
Like (0)
Save
Tweet
Share
10.49K Views

Join the DZone community and get the full member experience.

Join For Free

knowyourmeme.com/photos/531557 thx to @mihn
Sometimes debugging Java code is not enough and we need to step over the
native part of Java. I spent some time to achieve proper state of my JDK to do that, so short description probably will be useful for ones starting their trip. I'll use the brand new OpenJDK 9!

At first you have to obtain main repository by typing:
hg clone http://hg.openjdk.java.net/jdk9/jdk9 openjdk9
Then in the openjdk9 directory type:
bash get_source.sh
That will download all sources to you local filesystem.

Theoretically compiling openjdk is not a big deal, but there are some (hmmm....) strange behaviours if you want to use it for debugging.

At first of course we need to call ./configure to prepare specific makefiles for our system. We can read in documentation that we have to add --enable-debug flag to prepare fastdebug build. If you don't have proper libs or tools installed in your system it's right moment to install dependencies (configure output will clearly point out any lacks). After configuring and invoking make command you can face with such problem:
warning _FORTIFY_SOURCE requires compiling with optimization (-O)
Generating buffer classes
Generating exceptions classes
cc1plus: all warnings being treated as errors
Cool :) It happens only on some specific linux instalations (unfortunately including Fedora 20 :)). To solve it we have to remove _FORTIFY_SOURCE flag. Just comment (#) lines containing _FORTIFY_SOURCE in the following files:
  • hotspot/make/linux/makefiles/gcc.make
  • common/autoconf/flags.m4
Then you can move on with making jdk project and after dozen minutes you should see.
Finished building OpenJDK for target 'default'
Now it's time to import project to IDE Since we're still waiting for good C++ IDE from JetBrains we have to use NetBeans or even Eclipse. After finishing few steps needed to setup debugging commands (for example even for java -version). Start debugging, and... SIGSEGV received. Let's solve it by creating .gdbinit file in user home directory containing following lines:
handle SIGSEGV pass noprint nostop
handle SIGUSR1 pass noprint nostop
handle SIGUSR2 pass noprint nostop
Start debugging one more time - now it's better! Let's continue by adding line breakpoint. Start debugging, and... not working... :( I've extended .gdbinit by adding.
set logging on
One more debug try and in gdb.txt I saw such line:

No source file named hotspot/src/share/vm/memory/genCollectedHeap.cpp
I was pretty sure that --enable-debug will add -g flag to gcc compiler, but it seems I was wrong. I spent few hours googling and trying to solve it by changing gdb configurations, NetBeans config, etc. Still no effect. Fortunately Michal Warecki pointed me that probably OpenJDK during debug builds zips all debuginfo and if you want to debug (of course prepared debug build due to some other purposes?). After grepping makefiles I've found promising disable-zip-debug-info flag. So let's include it into our configure invocation. Also believe me it's hard to debug optimized code in C++ (you can try, but you will encounter strange thing happening, like debugger stepping lines in incorrect order (like starting method from line 4, going back to 2, then to 5 and to 3 :)). So we'll choose slowdebug option to avoid code optimization. Whole proper configure command is:
bash ./configure --with-debug-level=slowdebug --with-target-bits=64 --disable-zip-debug-info
Now we can invoke:
make
and wait for compilation to finish. Now you can check if everything works correctly by invoking ./java -version in 
build/linux-x86_64-normal-server-slowdebug/jdk/bin directory

You should see:
openjdk version "1.9.0-internal-debug"
OpenJDK Runtime Environment (build 1.9.0-internal-debug-kuba_2014_08_20_14_02-b00)
OpenJDK 64-Bit Server VM (build 1.9.0-internal-debug-kuba_2014_08_20_14_02-b00, mixed mode)
Let's try debugging. Add line breakpoint, start debugging, and... finally it's green! Have fun!
OpenJDK

Published at DZone with permission of Jakub Kubrynski, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Java Developers, Don't Throw Out Your Mac Yet: Apple Will Contribute To OpenJDK
  • Java Development Trends 2023
  • Binary Code Verification in Open Source World
  • Hack OpenJDK with NetBeans IDE

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: