Skip to main content

Posts

Dissecting Java object layout and sizeof() computation

This write up discusses how a rough mental calculation (close to accurate) can be performed to compute a java object size (shallow and deep). Target Java Virtual Machine: Hotspot 1.7.0_25 64 bit and Hotspot 1.7.0_51 32 bit Platform: Windows 7 64 bit,  Intel Core i5 Sandy Bridge Code: Pick this single class from my GitHub repo: [JavaObjectLayout] This code uses a third party library classmexer which uses Instrumentation to compute shallow and deep sizes of an object. The class I've written is to verify if this library is returning a correct size or not. class-mexer answers "what" is the size of an object, it does not explain "why". This write-up is an attempt to find that reason.  JavaObjectLayout uses sun.misc.Unsafe to sneak into an object's heap layout. The class is not general purpose but the approach I have applied can be followed to dissect any java object. You'd see use of absolute offsets to fetch a memory...

Market data subscriber prototype based on Disruptor

Let's talk about a market data subscriber application based on LMAX Disruptor I recently implemented. Source code hosted on my Github repo: https://github.com/NiinS/Java/tree/master/MarketDataSubscriber Quick Overview: The app subscribes to FX quotes and trade events from an event source and a Swing client displays it in a dynamically updating tabular structure as follows: Swing interface however is only an example of an end user which is making use of the processed events published by the app. Any number/kind of end user interfaces can be integrated with the application and they can process data in different ways. Following is a simplified application architecture diagram: The application employs a concept of gateways, an event wheel and business event processors.  Event Gateways : Gateways connect to actual event sources and publish raw market events to event wheel. Event wheel : Imagine an industrial flywheel which keeps rotating to gener...

C++11 std::thread Construction and Assignment Tricks

C++11 arrived with std::thread and related classes built within the standard. With the move semantics in place, the construction and assignment practices of 'std threads' deserve a small write up. Let's define a 'Runnable' first: class Runnable {    public:       virtual void operator ()() = 0;       virtual ~Runnable(){} }; class Task : Runnable {      public:          void operator ()()          {               //do sth here..          } };                                           ...

C++ logging using Apache Log4cxx on Linux

I'd demonstrate the set up of Apache log4cxx on Ubuntu 12.x in following steps: 1. Download all required packages 2. Build Log4cxx via Apache Maven 3. Use the libraries in a NetBeans C++ project on Ubuntu Linux. Reference URL: http://www.yolinux.com/TUTORIALS/Log4cxx.html This URL is quite detailed and explains things for other *nix operating systems as well. I wanted to start with minimum steps required, hence this post. I have a Windows 7 desktop and have Ubuntu 12.x 64-bit running on it via Oracle Virtualbox. So Ubuntu is running as a guest on my Windows 7 host. [The reference URL mentions different versions of  'libaprXX' libs but we have to use 'libapr1-dev' and 'libaprutil-dev', will see that later.] Prerequisites (install all of the following one by one) autoconf and automake --> sudo apt-get install autoconf automake libxml2 and libxml2-devel ( http://xmlsoft.org/ ) --> sudo apt-get install libxml2 libxml2-dev gmp ( ...