Jitescript - Java API for Bytecode

Overview

Jitescript - Java API for Bytecode

This project is inspired by @headius's BiteScript. The goal is to produce a Java library with a similar API so that bytecode generation can be as nice in Java as BiteScript makes it in JRuby.

cloudbees rocks!

Quickstart

Just add the project maven dependency info:

<dependency>
  <groupId>me.qmx.jitescript</groupId>
  <artifactId>jitescript</artifactId>
  <version>0.3.0</version>
</dependency>

Then take a look at JiteClassTest example on how to use it.

How to get help

Join us on #dynjs channel at irc.freenode.net.

Comments
  • Code needs modernization for recent Java versions

    Code needs modernization for recent Java versions

    Modern Java complains about "raw types" when types such as Class or Enum are used; those should perhaps nowadays be spelled Class<?> and Enum<?>. Would you like a pull request for such a change?

    opened by tkoeppe 5
  • jitescript fails to build with asm-debug-all

    jitescript fails to build with asm-debug-all

    Hi,

    I noticed that jitescript fails to build if the dependency on asm-all is replaced by asm-debug-all. Here is the error displayed:

    src/main/java/me/qmx/jitescript/MethodDefinition.java:[58,36] error: incompatible types: ArrayList<VisibleAnnotation> cannot be converted to List<AnnotationNode>
    src/main/java/me/qmx/jitescript/FieldDefinition.java:[25,34] error: incompatible types: ArrayList<VisibleAnnotation> cannot be converted to List<AnnotationNode>
    

    This error doesn't happen with asm-all because the classes are stripped from the debug symbols and the generic signatures.

    Maybe VisibleAnnotation should extend AnnotationNode so the list contains the type expected?

    opened by ebourg 3
  • Annotations DSL

    Annotations DSL

    Support for annotating classes, methods, and fields in DSL.

    This change only supports 'visible' annotations. Only annotations with RetentionPolicy.RUNTIME will work.

    opened by ghost 3
  • Allowing access flags to be set on classes

    Allowing access flags to be set on classes

    Change to allow access flags to be set on classes with a default of ACC_PUBLIC. The ACC_SUPER access flag is always set.

    Other changes:

    • Adding child classes
    • Default constructor visibility
    • Some tests around class/constructor visibility
    opened by ghost 2
  • Adding ppc64le architecture support on travis-ci

    Adding ppc64le architecture support on travis-ci

    Hi, I had added ppc64le(Linux on Power) architecture support on travis-ci in the PR and looks like its been successfully added. I believe it is ready for the final review and merge. The travis ci build logs can be verified from the link below. https://travis-ci.com/github/kishorkunal-raj/jitescript/builds/191745974

    Reason behind running tests on ppc64le: This package is included in the ppc64le versions of RHEL and Ubuntu - this allows the top of tree to be tested continuously as it is for Intel, making it easier to catch any possible regressions on ppc64le before the distros begin their clones and builds. This reduces the work in integrating this package into future versions of RHEL/Ubuntu.

    Please have a look.

    Regards, Kishor Kunal Raj

    opened by kishorkunal-raj 1
  • CodeBlock: rename method parameters (ALERT: code style)

    CodeBlock: rename method parameters (ALERT: code style)

    Also, all instance variables except for arity and returns are now final.

    Note that in the version I copied over, the class itself is also final. Not the case here.

    opened by fge 1
  • Using jitescript to modify bytecode?

    Using jitescript to modify bytecode?

    Followup to a discussion on IRC (freenode, channel `#dynjs).

    I have taken on me to kickstart parboiled "1" development again, since it has halted two years ago, and have created grappa.

    Basically: you write parsers in Java and create your parser with:

    final MyParser parser = Parboiled.createParser(MyParser.class);
    

    This does the following:

    • create a ParserClassNode containing the bytecode of MyParser);
    • create a name for the new class, since the instance returned is a class inheriting your parser class;
    • for each RuleMethod in the ParserClassNode, that is, methods defined in the base class returning a Rule, perform a given number of transformations; those transformations are defined here.

    When you have a look at the classes defined here, what they all do (on the byte code copy) is to generate bytecode which is appended/prepended to the existing method bytecode.

    And that is done using raw ASM...

    Having googled around, I stumbled upon this library when watching a video on YouTube by the author of JRuby mentioning this library; but I don't see how I can use this library to modify existing bytecode?

    An example of what I mean is here.

    I know I'll have to modify this code one day (when I go Java 7 I want to go indy); but right now, I am looking for a library which can make it easier for me to generate that kind of "bytecode set", and there are many; a lot more such code extracts are available in the enclosing package. Can JiteScript help me here?

    opened by fge 1
  • Normalized CodeBlock return property

    Normalized CodeBlock return property

    The CodeBlock's return property was only set for reference types but not for primitives. This is rather not very consistent and is confusing for people relying on the property to be set.

    There might be some greater meaning to this descision but to me it seemed as if this property was simply forgoten for the primitive return opcodes. At least, this surprised me, so I guess it might surprise others, as well.

    opened by raphw 1
  • Bump junit from 4.8.2 to 4.13.1

    Bump junit from 4.8.2 to 4.13.1

    Bumps junit from 4.8.2 to 4.13.1.

    Release notes

    Sourced from junit's releases.

    JUnit 4.13.1

    Please refer to the release notes for details.

    JUnit 4.13

    Please refer to the release notes for details.

    JUnit 4.13 RC 2

    Please refer to the release notes for details.

    JUnit 4.13 RC 1

    Please refer to the release notes for details.

    JUnit 4.13 Beta 3

    Please refer to the release notes for details.

    JUnit 4.13 Beta 2

    Please refer to the release notes for details.

    JUnit 4.13 Beta 1

    Please refer to the release notes for details.

    JUnit 4.12

    Please refer to the release notes for details.

    JUnit 4.12 Beta 3

    Please refer to the release notes for details.

    JUnit 4.12 Beta 2

    No release notes provided.

    JUnit 4.12 Beta 1

    No release notes provided.

    JUnit 4.11

    No release notes provided.

    Changelog

    Sourced from junit's changelog.

    Summary of changes in version 4.13.1

    Rules

    Security fix: TemporaryFolder now limits access to temporary folders on Java 1.7 or later

    A local information disclosure vulnerability in TemporaryFolder has been fixed. See the published security advisory for details.

    Test Runners

    [Pull request #1669:](junit-team/junit#1669) Make FrameworkField constructor public

    Prior to this change, custom runners could make FrameworkMethod instances, but not FrameworkField instances. This small change allows for both now, because FrameworkField's constructor has been promoted from package-private to public.

    Commits
    • 1b683f4 [maven-release-plugin] prepare release r4.13.1
    • ce6ce3a Draft 4.13.1 release notes
    • c29dd82 Change version to 4.13.1-SNAPSHOT
    • 1d17486 Add a link to assertThrows in exception testing
    • 543905d Use separate line for annotation in Javadoc
    • 510e906 Add sub headlines to class Javadoc
    • 610155b Merge pull request from GHSA-269g-pwp5-87pp
    • b6cfd1e Explicitly wrap float parameter for consistency (#1671)
    • a5d205c Fix GitHub link in FAQ (#1672)
    • 3a5c6b4 Deprecated since jdk9 replacing constructor instance of Double and Float (#1660)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Use `getDeclaredClass` on `Enum`

    Use `getDeclaredClass` on `Enum`

    I don't know Java well, so I'd just like to leave this as a suggestion, without judgement:

    Our static analysis suggests a change at https://github.com/qmx/jitescript/blob/master/src/main/java/me/qmx/jitescript/VisibleAnnotation.java#L34, to change value.getClass() to value.getDeclaredClass(). The former returns some derived class for enums that declare methods, whereas the latter returns the actual enum type.

    I'm not sure if that's correct, but it was flagged as an error-prone pattern.

    opened by tkoeppe 0
  • Adding LambdaBlock DSL for Java 8 lambdas

    Adding LambdaBlock DSL for Java 8 lambdas

    Hey @qmx! I've added a simple DSL block for generating lambdas more easily, mostly because I find the multiple invokedynamic arguments required for lambdas is tough to get my head around.

    In a nutshell, lambdas require the following:

    • Functional interface type, method, and signature
    • Optional specialization of the functional interface method signature
    • The number and types of the arguments to capture off the stack
    • The method to delegate the lambda to

    Using this information, the relevant invokedynamic instruction is created to delegate into the implementation method.

    Caveats: The lambda block test (JiteClassTest#testLambda) is only run on Java 8. The test method exits if not running Java 8. I've taken steps to ensure Java 8 isn't required when using jitescript by coding all JDK 8 class names as strings. Is there a better way to manage the test given the JDK version constraint? :S

    Examples:

    opened by ghost 2
Owner
Doug Campos
Doug Campos
Mixin is a trait/mixin and bytecode weaving framework for Java using ASM

Mixin is a trait/mixin framework for Java using ASM and hooking into the runtime classloading process via a set of pluggable built-in or user-provided

SpongePowered 1.1k Jan 7, 2023
Chasm is a java bytecode transformer designed to handle collision between transformers wherever possible.

NOTE: This project is still in its early development. There's guaranteed bugs and missing functionality. Chasm - Collision Handling ASM What is Chasm?

null 51 Dec 30, 2022
The modern Java bytecode editor

Recaf An easy to use modern Java bytecode editor that abstracts away the complexities of Java programs. Recaf abstracts away: Constant pool Stack fram

Matt 4.5k Dec 31, 2022
cglib - Byte Code Generation Library is high level API to generate and transform Java byte code. It is used by AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.

cglib Byte Code Generation Library is high level API to generate and transform JAVA byte code. It is used by AOP, testing, data access frameworks to g

Code Generation Library 4.5k Jan 8, 2023
A Java 8+ Jar & Android APK Reverse Engineering Suite (Decompiler, Editor, Debugger & More)

Bytecode Viewer Bytecode Viewer - a lightweight user friendly Java Bytecode Viewer. New Features WAR & JSP Loading JADX-Core Decompiler Fixed APK & de

Kalen (Konloch) Kinloch 13.5k Jan 7, 2023
Java bytecode engineering toolkit

Java bytecode engineering toolkit Javassist version 3 Copyright (C) 1999-2020 by Shigeru Chiba, All rights reserved. Javassist (JAVA programming ASSIS

null 3.7k Dec 29, 2022
Mixin is a trait/mixin and bytecode weaving framework for Java using ASM

Mixin is a trait/mixin framework for Java using ASM and hooking into the runtime classloading process via a set of pluggable built-in or user-provided

SpongePowered 1.1k Jan 7, 2023
Log analyser / visualiser for Java HotSpot JIT compiler. Inspect inlining decisions, hot methods, bytecode, and assembly. View results in the JavaFX user interface.

JITWatch Log analyser and visualiser for the HotSpot JIT compiler. Video introduction to JITWatch video Slides from my LJC lightning talk on JITWatch

AdoptOpenJDK 2.8k Jan 3, 2023
Compiler of Java bytecode to JavaScript

TeaVM See documentation at the project web site. Useful links: Getting started Gallery Flavour source code repository Site source code repository Disc

Alexey Andreev 2.1k Jan 3, 2023
A Java agent that rewrites bytecode to instrument allocation sites

The Allocation Instrumenter is a Java agent written using the java.lang.instrument API and ASM. Each allocation in your Java program is instrumented;

Google 438 Dec 19, 2022
Log analyser / visualiser for Java HotSpot JIT compiler. Inspect inlining decisions, hot methods, bytecode, and assembly. View results in the JavaFX user interface.

JITWatch Log analyser and visualiser for the HotSpot JIT compiler. Video introduction to JITWatch video Slides from my LJC lightning talk on JITWatch

AdoptOpenJDK 2.8k Jan 3, 2023
Java bytecode obfuscator with GUI

Bozar A Java bytecode obfuscator with GUI Usage Download the version you want in releases for your platform Run the executable. Done. Let me know if o

null 101 Dec 31, 2022
Assembler/disassembler for java bytecode

Raung raung - yet another assembler/disassembler for java bytecode. Similar to Krakatau and Smali, based on ASM library. ❗ Warning: this project at a

null 20 Oct 2, 2022
Chasm is a java bytecode transformer designed to handle collision between transformers wherever possible.

NOTE: This project is still in its early development. There's guaranteed bugs and missing functionality. Chasm - Collision Handling ASM What is Chasm?

null 51 Dec 30, 2022
Java bytecode static analyzer

This project is abandoned and unlikely will be supported in future HuntBugs 0.0.11 New Java bytecode static analyzer tool based on Procyon Compiler To

Tagir Valeev 302 Aug 13, 2022
Kotlin-decompiled - (Almost) every single language construct of the Kotlin programming language compiled to JVM bytecode and then decompiled to Java again for better readability

Kotlin: Decompiled (Almost) every single language construct of the Kotlin programming language compiled to JVM bytecode and then decompiled to Java ag

The Self-Taught Software Engineer 27 Dec 14, 2022
The modern Java bytecode editor

Recaf An easy to use modern Java bytecode editor that abstracts away the complexities of Java programs. Recaf abstracts away: Constant pool Stack fram

Matt 4.5k Dec 31, 2022
HyCache - an open source caching tool based on bytecode enhancement implementation

HyCache is an open source caching tool.It is based on bytecode enhancement implementation, rather than spring's dynamic proxy. It can achieve a wider range of applications

zhaoshaohai 3 Sep 6, 2022
Generate facts from bytecode

soot-fact-generator generate facts from bytecode (source is https://github.com/plast-lab/doop-mirror/tree/master/generators) 通过soot解析bytecode生成fact,类似

null 14 Dec 28, 2022