Skip to main content

Posts

C++ Initialization Subtleties (significance of -Werror compiler option)

Modern C++ continuous integration build pipelines might produce huge logs which may be easily overlooked. Among other errors/warnings, a potential risk caused by invalid narrowing assignments might be lurking in those dark corners... This write up is a little reminder about an essential feature in modern C++ compilers and can help defend against that specific problem. Prior to C++11, the following was a valid assignment and still is even in C++20 or higher ... unsigned int unsignedSinceBirth = 10; unsignedSinceBirth = -10;  // assigning a negative value to an unsigned container printUnsignedVal(unsignedSinceBirth); which when compiled using these options "g++ -std=c++20 <cpp files> -o <executable-name>" does not even emit a warning. And an executable is generated successfully. The output of running that code is an arbitrary unexpected value. Modern C++ (post Cpp11) allow uniform initialization syntax which can help the compiler detect this situation as follows:
Recent posts

Achieving global total order in distributed systems without Sequencers

A seminal question to answer in a distributed event driven "fault tolerant" system is how to recreate state should there be a need for fault tolerance and recovery.  A typical and easy to rationalize approach is the assignment of a globally increasing sequence to the events flowing across the system. The intent is to bring a global "order" or "sequence" into the system. Later on this global ordering will pave the way for a resilient yet distributed system.  It will be: predicable - replaying the events from message commit logs will always produce the same net effect. reliable and fault tolerant - as long as there are commit logs maintained, faults recovery and late joining protocols will always have a way to catch up. The question then turns to " who should assign the order or sequence "? This post attempts to answer the 2nd question in an expository style (and will not delve into details). .......................................................

JVM's Boltzmann effects

This write-up discusses an aspect of JVM's just-in-time compilation  around dynamic method disp atch. Following are the results from a run of 5 measurement iterations of JMH (Java micro-benchmarking harness) showing that JVM could perform 69 million operations in the bi-morphic case than just 62 million operations in mega-morphic case . And no matter how many times the benchmark is run, the results remain the same. This benchmark was executed against a Java 8 runtime, similar results appear if we run the same code against Java 10's latest update.  The hierarchy of classes involved in this example is shown here: Above results are from a run of following benchmarking code and we can see  there is literally no difference between the two methods being benchmarked . Then what just happened? In general, JVM knows (via just in time compilation) how many possible types exist for a polymorphic reference type. With this awareness, JIT compiler can

Financial Risk Management Mind Maps

An asset class (finance) agnostic mind map of risk mgmt pathways taken by Sell side firms.. Recently drew on paper.. Every single node in this tree deserves a sepaarte detailed explanation or another mindmap, I'd keep extending in future. Following is just a starting point..

Mindmap for data stream analysis frameworks

In this post, I'd briefly discuss the evolution timeline of data stream processing frameworks and current state. A famous paper by Stonebraker et el few years ago established some guidelines for  truly streaming, fault tolerant computational frameworks. The mind map drawn in this post can be used as rough checklist to select/discard a streaming framework based on your application requirements. Similarities While there are differences in how streaming approaches process events, there are some commonalities like: Most of them achieve cluster mode execution via Yarn , Mesos and use Zookeper for cluster state management (for master-slave high availability). Many of them prepare a directed acyclic graph of computation which is presented to the master node in cluster which decides how to perform the computation in most efficient and parallel manner. Apache Kafka appears as a commonly employed approach as a fault tolerant event source. (though these frameworks provi

..Where Apache Camel meets Spring JMS

This post is relevant for developers who are aware of Apache Camel and use its JMS component to consume from a JMS broker. We are only discussing the message consumption part here. I'm assuming you are conversant with Camel's terminology of routes, endpoints, processors and EIPs. If not, following is a good place to start: Link --->  Apache Camel Home   Ever wondered what happens underneath when a Camel consumer route is defined to take messages from a JMS endpoint ? This post is an attempt to explain how Camel integrates with JMS via Spring APIs and how the business logic defined in a Camel route is invoked ? Following is a simplified sequence diagram showing the set-up process which will eventually lead to message consumption from JMS broker. . Creation of JMS endpoints in a camel context is initiated by definition (via Java/XML DSL). A JMS endpoint takes a number of configurable attributes as seen here Camel JMS Component . As soon as context is bootstrappe

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