Skip to content

Instantly share code, notes, and snippets.

View rednaxelafx's full-sized avatar

Kris Mok rednaxelafx

View GitHub Profile
@rednaxelafx
rednaxelafx / TestRandomizeString.java
Created November 9, 2012 08:46
Make typoglycemia text with Java 8/lambda. Excercise from Jeffrey Zhao's blog: http://blog.zhaojie.me/2012/11/how-to-generate-typoglycemia-text.html
import java.util.*;
import java.util.concurrent.*;
import static java.util.Comparators.comparing;
public class TestRandomizeString {
public static void main(String[] args) {
ThreadLocalRandom random = ThreadLocalRandom.current();
String text = args[0];
String result = String.join(" ",
@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
Created October 29, 2012 21:41
Example of running the debug helper functions from gdb on groovysh/JDK8b59-fastdebug, Ubuntu 12.04/AMD64
kmo@ubuntu:~
$ groovysh
Groovy Shell (2.0.1, JVM: 1.8.0-ea)
Type 'help' or '\h' for help.
------------------------------------------------------------------------------------------------------------------------------------------
groovy:000>
"Executing ps"
for thread: "main" #1 prio=5 os_prio=0 tid=0x00007f292800c000 nid=0x5fcb runnable [0x00007f293226c000]
java.lang.Thread.State: RUNNABLE
JavaThread state: _thread_in_native
@rednaxelafx
rednaxelafx / jdk7u5_new.txt
Created October 29, 2012 17:53
Output from PrintInterpreter on JDK7u5 and JDK8b59 with old/new hsdis plugin ("new" is the one with the pending 8000489 patch)
----------------------------------------------------------------------
Interpreter
code size = 109K bytes
total space = 199K bytes
wasted space = 90K bytes
# of codelets = 259
avg codelet size = 431 bytes
@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 / clhsdb_session
Created August 21, 2012 17:03
If a CompilerThread is not compiling anything, its env() will be null; same reflected in SA. No problem.
$ $JAVA_HOME/bin/java -version
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
$ jps
15245 JConsole
15269 Jps
$ sudo $JAVA_HOME/bin/java -cp $JAVA_HOME/lib/sa-jdi.jar sun.jvm.hotspot.CLHSDB
hsdb> attach 15245
Attaching to process 15245, please wait...
@rednaxelafx
rednaxelafx / Notes.md
Created July 12, 2012 10:14
Multiple Java threads look as if they've locked the same monitor, but actually haven't

vframe.cpp

void javaVFrame::print_lock_info_on(outputStream* st, int frame_count) {
  // If this is the first frame, and java.lang.Object.wait(...) then print out the receiver.
  if (frame_count == 0) {
    if (method()->name() == vmSymbols::wait_name() &&
        instanceKlass::cast(method()->method_holder())->name() == vmSymbols::java_lang_Object()) {
      // ...
  }
@rednaxelafx
rednaxelafx / ExtraUse.java
Created June 26, 2012 08:08
OptimizeStringConcat in HS24 won't optimize a StringBuilder with extra uses
public class ExtraUse {
public static void foo(Pair p) {
String s = "testing";
StringBuilder sb = new StringBuilder().append(s);
p.first = sb;
p.second = sb.append(s).toString();
}
public static void main(String[] args) throws Exception {
Pair p = new Pair();
@rednaxelafx
rednaxelafx / MultipleUse.foo.PrintAssembly
Created June 26, 2012 07:52
OptimizeStringConcat in HS24 will optimize the result of one StringBuilder to be used multiple times in another StringBuilder
Decoding compiled method 0x00007f9877cbbf90:
Code:
[Entry Point]
[Verified Entry Point]
[Constants]
# {method} 'foo' '()Ljava/lang/String;' in 'MultipleUse'
# [sp+0x30] (sp of caller)
;; N1: # B1 <- B12 B5 Freq: 1
;; B1: # B6 B2 <- BLOCK HEAD IS JUNK Freq: 1
@rednaxelafx
rednaxelafx / AppendAfterToString.java
Created June 26, 2012 07:41
OptimizeStringConcat in HS24 won't optimize a StringBuilder with append() calls after toString()
public class AppendAfterToString {
public static void foo(Pair p) {
String s = "testing";
StringBuilder sb = new StringBuilder();
sb.append(s).append(s);
p.first = sb.toString();
sb.append(s);
p.second = sb.toString();
}