Skip to content

Instantly share code, notes, and snippets.

View rednaxelafx's full-sized avatar

Kris Mok rednaxelafx

View GitHub Profile
@rednaxelafx
rednaxelafx / Notes.md
Created December 12, 2011 06:40
Java 7's GC notification notes

GC notifications are sent to the ServiceThread, as shown in the Groovy shell example in this gist. The ServiceThread is a JavaThread, so it can execute Java code.

To see GC notification in action, refer to a conversation in hotspot-gc-dev. Another thread of interest is the discussions on 7110173: GCNotifier::pushNotification publishes stale data.

In the HotSpot VM, GC notifications are pushed with GCNotifier::pushNotification(), in GCMemoryManager::gc_end(), which is in turn called by MemoryService::gc_end().

hotspot/src/share/vm/runtime/serviceThread.cpp

@rednaxelafx
rednaxelafx / clhsdb_session
Created April 17, 2017 17:37
Figuring out what bytecode scala.Predef$.augmentString corresponded to
$ sudo $JAVA_HOME/bin/java -cp $JAVA_HOME/lib/sa-jdi.jar sun.jvm.hotspot.CLHSDB
Password:
hsdb> attach 15168
Attaching to process 15168, please wait...
hsdb> class scala.Predef$
scala/Predef$ @0x00000007c003eb60
hsdb> print 0x00000007c003eb60
public final class scala.Predef$ @0x00000007c003eb60
@rednaxelafx
rednaxelafx / jdk6u24_x86_client_Xint_flags.txt
Created April 18, 2011 06:39
difference in the ergonomics between "-server -Xint" and "-client -Xint" HotSpot VMs (JDK6u24)
[Global flags]
uintx AdaptivePermSizeWeight = 20 {product}
uintx AdaptiveSizeDecrementScaleFactor = 4 {product}
uintx AdaptiveSizeMajorGCDecayTimeScale = 10 {product}
uintx AdaptiveSizePausePolicy = 0 {product}
uintx AdaptiveSizePolicyCollectionCostMargin = 50 {product}
uintx AdaptiveSizePolicyInitializingSteps = 20 {product}
uintx AdaptiveSizePolicyOutputInterval = 0 {product}
uintx AdaptiveSizePolicyWeight = 10 {product}
uintx AdaptiveSizeThroughPutPolicy = 0 {product}
@rednaxelafx
rednaxelafx / PrintOptoAssembly
Created November 1, 2012 08:20
Log from running example in Item 66 of Effective Java 2nd on JDK6u25-fastdebug-amd64
{method}
- klass: {other class}
- this oop: 0x00000000bc925718
- method holder: 'StopThread$1'
- constants: 0x00000000bc925430 constant pool [29] for 'StopThread$1' cache=0x00000000bc925a90
- access: 0xc1000001 public
- name: 'run'
- signature: '()V'
- max stack: 1
- max locals: 2
@rednaxelafx
rednaxelafx / command_prompt_win7_x64
Created May 14, 2013 15:48
Ruby script to determine the architecture of a PE file. A port of the Perl version from http://stackoverflow.com/questions/495244/how-can-i-test-a-windows-dll-to-determine-if-it-is-32bit-or-64bit, courtesey of Paul Dixon
D:\temp>ruby petype.rb petype.rb
Not an executable
D:\temp>ruby petype.rb C:\Windows\system32\notepad.exe
amd64
D:\temp>ruby petype.rb C:\Windows\system32\jscript9.dll
amd64
D:\temp>ruby petype.rb C:\Windows\syswow64\jscript9.dll
@rednaxelafx
rednaxelafx / TestSIMD.java
Last active July 31, 2019 16:41
HotSpot C2 SIMD vectorization demo
import java.util.Arrays;
public class TestSIMD {
public static void doCompute(int[] a, int[] x, int[] y, int[] z) {
for (int i = 0; i < a.length; i++) {
a[i] = a[i] + x[i] * y[i] * z[i];
}
}
@rednaxelafx
rednaxelafx / spark-shell-session
Created July 30, 2019 06:26
Apache Spark master running on OpenJDK11u
$ bin/spark-shell
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.spark.unsafe.Platform (file:/home/krismok/code/work/oss-spark-readonly/assembly/target/scala-2.12/jars/spark-unsafe_2.12-3.0.0-SNAPSHOT.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of org.apache.spark.unsafe.Platform
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
19/07/30 06:03:19 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
@rednaxelafx
rednaxelafx / command_prompt
Created July 16, 2015 21:39
Demo of Clang++'s implementation of C++ static local variable
$ clang++ -S -emit-llvm yy.cc
@rednaxelafx
rednaxelafx / decompiled.cs
Created September 8, 2012 20:15
Simple example of C# iterator (generator) decompiled. Decompiled with ILSpy; turned off decompilation for iterators to see details.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
internal class Test
{
[CompilerGenerated]
private sealed class <GetNaturals>d__0 : IEnumerable<int>, IEnumerable, IEnumerator<int>, IEnumerator, IDisposable
@rednaxelafx
rednaxelafx / Notes
Created May 29, 2011 20:47
Example of HotSpot's PrintCompressedOopsMode's output. It's clear that UseCompressedOops can only be used with heap size < 32GB
The "size" field shows total reserved GC heap size in MB, which includes all generations (including PermGen).
"32-bits Oops" means the shift is zero; otherwise it'd be non-zero.
If UseCompressedOops is false, or if the heap is too big to use compressed oops, then PrintCompressedOopsMode won't print anything. The -Xmx32g example below show that ergonomics didn't set UseCompressedOops to true.
If the heap is too big, HotSpot would print a warning message and set UseCompressedOops to false.