On why and how to exit JVM on OnOutOfMemoryError

For a long time all my JVM-based Docker images were configured to exit on OOM error with -XX:OnOutOfMemoryError=”kill -9 %p” (%p is the current JVM process PID placeholder). It works well with XX:+HeapDumpOnOutOfMemoryError, because JVM will dump heap first, and then execute OnOutOfMemoryError command (see the relevant code in vm/utilities/debug.cpp ). But with version 8u92 there’s now a JVM option in the JDK to make the JVM exit when an OutOfMemoryError occurs:

From the release notes:

ExitOnOutOfMemoryError
When you enable this option, the JVM exits on the first occurrence of an out-of-memory error. It can be used if you prefer restarting an instance of the JVM rather than handling out of memory errors.

CrashOnOutOfMemoryError
If this option is enabled, when an out-of-memory error occurs, the JVM crashes and produces text and binary crash files.

Enhancement Request: JDK-8138745 (parameter naming is wrong though JDK-8154713ExitOnOutOfMemoryError instead of ExitOnOutOfMemory)

 

Why exit on OOM? OutOfMemoryError may seem like any other exception, but if it escapes from Thread.run() it will cause thread to die. When thread dies it is no longer a GC root, and thus all references kept only by this thread are eligible for garbage collection. While it means that JVM has a chance recover from OOME, its not recommended that you try. It may work, but it is generally a bad idea. See this answer on SO.

Single-file Play Framework application with Ammonite

Single-file Play Framework application with Ammonite courtesy of Li Haoyi ‏@li_haoyi

/**
* Single-file play framework application! Make sure everything
* works, as this is the test case that un-earthed #371
*/
load.ivy("com.typesafe.play" %% "play" % "2.5.0")
load.ivy("com.typesafe.play" %% "play-netty-server" % "2.5.0")
load.ivy("org.scalaj" %% "scalaj-http" % "2.2.1")
@
import play.core.server._, play.api.routing.sird._, play.api.mvc._
import scalaj.http._
val server = NettyServer.fromRouter(new ServerConfig(
rootDir = new java.io.File("."),
port = Some(19000), sslPort = None,
address = "0.0.0.0", mode = play.api.Mode.Dev,
properties = System.getProperties,
configuration = play.api.Configuration(
"play.server.netty" -> Map(
"maxInitialLineLength" -> 4096,
"maxHeaderSize" -> 8192,
"maxChunkSize" -> 8192,
"log.wire" -> false,
"eventLoopThreads" -> 0,
"transport" -> "jdk",
"option.child" -> Map()
)
)
)) {
case GET(p"/hello/$to") => Action { Results.Ok(s"Hello $to") }
}
Console.readLine()
server.stop()
view raw play.scala hosted with ❤ by GitHub

I hope that this awesome code snippet will encourage you to check out  Ammonite-REPL (A Modernized Scala REPL).

Monitoring WildFly Using BTrace

Today I was hoping to use BTrace to track a rather anoying bug in web application running inside WildFly application server. I’ve used BTrace some times in the past and my experience was nothing but positive. Until today, that is.

Probe deployment caused  a myriad of exceptions inside application server coming from instrumented classes  and all caused by missing btrace runtime.   The classloader separation of the AS getting in my way! I know a thing or two about classloading in WildFly, so I decided to add btrace  to system packages(just like Byteman)

jboss.modules.system.pkgs=org.jboss.byteman,com.sun.btrace

To my suprise, it wasn’t the end of the story because now my btrace script was unavailable

java.lang.ClassNotFoundException: TracingScript$1 from [Module "deployment.atrem.incubator.e5.ml-web.war:main" from Service Module Loader]
	at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
	at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
	at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
	at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
	... 120 more

My solution was to place tracing script in non-root package btrace.scripts

package btrace.scripts;

import com.sun.btrace.*;
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;

@BTrace
public class TracingScript {
//
}

and add the package itself to system packages

jboss.modules.system.pkgs=org.jboss.byteman,com.sun.btrace,btrace.scripts

which finally made it work. Now, back to the problem at hand.

JavaScript Webapps with Gradle

Shine Solutions Group

Duke_the_Ripper IAP4377

Gradle is a build tool on the JVM platform that’s been gaining prominence over the last few years. Gradle’s reach doesn’t stop with JVM languages though.  The most recent releases, 1.10 and 1.11, have improved support for compiling native code (C / C++ / Objective C) and introduced support for the .NET platform. For Android projects, Google have made Gradle the de facto build tool. It’s getting a name for its flexibility, so when the opportunity came to build a single page Javascript webapp we decided to put the latest addition to the polyglot build tool arsenal through its paces.

View original post 4 290 słów więcej

Adding Features to an existing Product

...code is the easy part...

Normally when building an eclipse product using Tycho, you specify all the features you require in the .product file. This creates a single root level IU. There are various situations where this is not desirable. For example you may have a core product with add-ons features – much like Eclipse itself – but only maintain a single .product file. You may also wish to be able to update some features without needing to rebuild the whole product. There is an open bug for Tycho to help with this in the future.

In this post we will concentrate on the former case. We will assume there is a prebuilt product published to a p2 repository – here we will use the Eclipse RCP product. It is possible to use these steps are part of an eclipse-repository build but you will need to adapt the default Tycho configuration to delay the product…

View original post 804 słowa więcej

Xperf Basics: Recording a Trace (the ultimate easy way)

Random ASCII - tech blog of Bruce Dawson

imageIf your Windows computer is running slowly – if a program takes a long time to launch, if a game has a poor frame rate, or if an idle application uses too much CPU time – the best way to investigate is to record an Event Tracing for Windows (ETW) trace. An ETW trace records a wealth of information (CPU sampling, context switches, disk I/O, custom data, and much more) that allows most performance problems to be understood by a trained expert. If you’re not a trained expert then you can still record an ETW trace, and then share it with somebody who is.

If a particular program is being slow or inefficient then you may be able to record an ETW trace and share it with the authors of that program. Quite often they can figure out what is going wrong, whether it is a bug on their side

View original post 1 048 słów więcej

Eclipse/JVM fails to start due to lack of memory

Eclipsed

Lately, when starting Eclipse, the JVM has failed to start.  A reboot of the system usually fixed the problem.  Until yesterday.  So I had to dig in and solve this problem.

I wanted to share my experiences with debugging this issue.

Added Note: This is not the bug by which Eclipse running under java 1.6u21 fails to pass the permgen size on to the JVM.  If you are running java 1.6u21 with Eclipse, don’t.

Determine why eclipse.exe is crashing with „-debug”

I edited my eclipse.ini and added the -debug option:


-startup
plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
512m
-debug
-vmargs
-Xms100m
-Xmx752m

Then I ran eclipse.exe from the command-line, hoping to get a bit more information:

$ ./eclipse.exe
Error occurred during initialization of VM
Could not reserve enough space for object heap

Now that’s a clear error message!

I need lots of memory

You may have noticed some pretty…

View original post 450 słów więcej

Bundle-NativeCode: Using platform-specific DLLs from OSGi

holistic tendencies

I’m currently doing some development on a large RCP application. One recent task required using a Windows DLL to open an email message through MAPI, which is made pretty easy with OSGi. But I encountered a few issues that I’m sure will bite other people.

Bundle-NativeCode

OSGi now provides some support for resolving and loading shared libraries/DLLs in Java applications. A bundle declaratively specifies its DLLs and associated platform requirements in their bundle manifest using the Bundle-NativeCode header. This header value is then used when loading a DLL through System.loadLibrary().

TheBundle-NativeCode header specifies a number of comma-delimited clauses. For example:

Bundle-NativeCode: lib/win32/x86/http.dll; lib/win/zlib.dll;
    processor=x86; osname=win32, 
  lib/macosx/libhttp.dylib; lib/macosx/libzlib.jnilib;
    osname=macosx; processor=x86; processor=x86_64,
  *

A clause specifies one or more DLLs. A clause is matched to the current platform using a set of parameters (e.g., processor and osname, but also osversion, language, or a selection-filter). Parameters of…

View original post 408 słów więcej

Arquillian – solving org.dbunit.database.AmbiguousTableNameException: OL$

Jeśli podczas uruchomienia testów integracyjnych wykorzystujących Arquillian Persistence Extension uruchmionych względem bazy Oracle pojawi się błąd

arquillian.persistence.dbunit.exception.DBUnitDataSetHandlingException: Unable to clean database.
	...
Caused by: org.dbunit.database.AmbiguousTableNameException: OL$
	at org.dbunit.dataset.OrderedTableNameMap.add(OrderedTableNameMap.java:198)
	at org.dbunit.database.DatabaseDataSet.initialize(DatabaseDataSet.java:231)
	at org.dbunit.database.DatabaseDataSet.getTableNames(DatabaseDataSet.java:272)
	at org.dbunit.database.DatabaseDataSet.createIterator(DatabaseDataSet.java:258)
	at org.dbunit.dataset.AbstractDataSet.iterator(AbstractDataSet.java:189)
	at org.dbunit.dataset.filter.AbstractTableFilter.iterator(AbstractTableFilter.java:91)
	at org.dbunit.dataset.FilteredDataSet.createIterator(FilteredDataSet.java:89)
	at org.dbunit.dataset.AbstractDataSet.iterator(AbstractDataSet.java:189)
	at org.dbunit.operation.DeleteAllOperation.execute(DeleteAllOperation.java:92)
	at org.jboss.arquillian.persistence.dbunit.cleanup.StrictCleanupStrategyExecutor.cleanupDatabase(StrictCleanupStrategyExecutor.java:56)
	... 181 more

to rozwiązaniem jest dodanie do pliku arquillian.xml wpisu

<extension qualifier="persistence-dbunit">
	<property name="schema">$nazwa-schematu$</property>
</extension>

Precedence: ordering or grouping?

Jon Skeet's coding blog

As I’ve mentioned before, I’m part of the technical group looking at updating the ECMA-334 C# standard to reflect the C# 5 Microsoft specification. I recently made a suggestion that I thought would be uncontroversial, but which caused some discussion – and prompted this „request for comment” post, effectively.

What does the standard say about precedence?

The current proposed standard includes the following text:

The order of evaluation of operators in an expression is determined by the precedence and associativity of the operators (§13.4.2).

Operands in an expression are evaluated from left to right.

When an expression contains multiple operators, the precedence of the operators controls the order in which the individual operators are evaluated. [Note: For example, the expression x + y * z is evaluated as x + (y * z) because the * operator has higher precedence than the binary + operator. end note

View original post 857 słów więcej