Skip to content

Instantly share code, notes, and snippets.

View kay's full-sized avatar

Doug Lawrie kay

View GitHub Profile
@kay
kay / main.rs
Last active July 16, 2024 15:36
Wasmer 4.3.4 panics when using static typed host functions
/*
[dependencies]
wasmer = { version = "4.3.4" }
*/
use wasmer::{Cranelift, Function, Imports, Instance, Module, RuntimeError, Store, Value};
fn static_return_32_then_64_then_32(lhs: i32, rhs: i32) -> (i32, i64, i32) {
(lhs, lhs as i64 + rhs as i64, rhs)
}
@kay
kay / jdk11-hsdis-ubuntu.sh
Last active August 9, 2020 11:31
Build HotSpot disassembler for JDK 11 and 12
# The following is based on a fresh Ubuntu 18.04.2 LTS with gcc, make and perl already
# installed (not that perl has anything to do with any of this..)
#
# This is based on JDK 11 but for JDK 12 I've confirmed it builds ok with binutils-2.29
# and binutils-2.32
apt install mercurial
# Be nice if this didn't check out the universe
hg clone http://hg.openjdk.java.net/jdk/jdk11/
cd jdk11/src/utils/hsdis/
@kay
kay / hsdis-ubuntu.sh
Last active October 21, 2019 21:16 — forked from zajacmp3/hsdis-ubuntu.sh
Build hsdis for JDK 1.8 on Debian/Ubuntu
sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev g++-multilib mercurial texinfo
hg clone http://hg.openjdk.java.net/jdk8u/jdk8u
cd jdk8u
hg update jdk8u92-b14
sed -ri 's/subrepos="[^"]+"/subrepos="hotspot"/' ./make/scripts/hgforest.sh # only get hotspot
sed -ri 's/subrepos="[^"]+"/subrepos="hotspot"/' ./common/bin/hgforest.sh # only get hotspot
chmod +x ./get_source.sh; ./get_source.sh
cd hotspot/src/share/tools/hsdis
wget http://ftp.heanet.ie/mirrors/ftp.gnu.org/gnu/binutils/binutils-2.29.tar.gz
tar -xzf binutils-2.29.tar.gz
@kay
kay / ListJvmMonitorMetrics.java
Created June 27, 2018 00:25
List JVM monitoring metrics
package org.neverfear.services.jvmmonitor.api;
import static java.lang.System.out;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Set;
import sun.jvmstat.monitor.HostIdentifier;
import sun.jvmstat.monitor.Monitor;
@kay
kay / dogtag.c
Created May 27, 2013 19:06
tag_invalidate and tag_free
void tag_invalidate(memory_t * memory) {
TAG_TYPE * start = PTR_START_TAG(memory);
*start = TAG_INVALID_VALUE;
TAG_TYPE * end = PTR_END_TAG(memory);
*end = TAG_INVALID_VALUE;
}
bool tag_free(memory_t * memory) {
if (tag_underran(memory) || tag_overran(memory)) {
@kay
kay / dogtag.c
Created May 27, 2013 19:04
tag_underran and tag_overran
bool tag_underran(memory_t * memory) {
return *PTR_START_TAG(memory) != VALID_START_TAG;
}
bool tag_overran(memory_t * memory) {
return *PTR_END_TAG(memory) != VALID_END_TAG;
}
@kay
kay / dogtag.c
Last active December 17, 2015 19:09
tag_alloc
#define TAG_TYPE int
#define TAG_SIZE sizeof(TAG_TYPE)
#define VALID_START_TAG 0xDEADBEEF
#define VALID_END_TAG 0xCAFEBABE
#define TAG_INVALID_VALUE 0xBADC0DE5
#define PTR_START_TAG(memory) (TAG_TYPE *)(memory->ptr - TAG_SIZE)
#define PTR_END_TAG(memory) (TAG_TYPE *)(memory->ptr + memory->size)
@kay
kay / dogtag.c
Last active December 17, 2015 19:09
Simple implementation of the dog tag technique to detect memory corruption.
#include "dogtag.h"
bool tag_alloc(memory_t * memory, size_t size) {
void * ptr = malloc(size + (2 * TAG_SIZE));
if (ptr == NULL) {
return false;
}
TAG_TYPE * startPtr = ptr;
*startPtr = VALID_START_TAG;
package org.neverfear.ha;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import org.jgroups.JChannel;
import org.jgroups.blocks.locking.LockService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FailoverManager implements AutoCloseable, ChannelListener, Receiver {
private static final Logger LOGGER = LoggerFactory.getLogger(FailoverManager.class);
private static final String HA_CLUSTER = "ha-cluster";
private final JChannel channel;
private final int maximumClusterSize;
private final LeadershipResolver decider;