Tom Martin
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    1
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- lintConfig: MD013: false MD025: false --- # DASM Spec > [TOC] The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [IETF RFC 2119](https://www.ietf.org/rfc/rfc2119.txt). Except "SHOULD", it shouldn't exist :> Authors: [NotStirred](https://github.com/NotStirred/) [Flames](https://github.com/CursedFlames/) ## Required tests to meet spec: [Dasm Tests](/iDj2EjQCQfWszbdf7DA5qw) # Definitions ## General Definitions - Simple Class Name: `Object` - Class Name (or fully qualified class name): `java.lang.Object`, `java.lang.String[]` - Internal Name: `java/lang/Object`, `I`, `Z` WARNING: asm's `getInternalName()` returns **descriptors** if given an array type - Descriptor - Type: `Ljava/lang/Object;`, `Z`, `I`, `[I`, `[[I`, `[Ljava/lang/String;` - Method: `(II)Ljava/lang/Object;`, `(Ljava/lang/String;)V` ## DASM Definitions - Redirect: A redirect specifies a substitution from one field/method/type to another when applying a transform. - Redirect set: A set of redirects that are used when applying a transform. - Transform: A transform copies a method/type and substitutes all fields/methods/types specified in the redirect sets used for that transform. ## Example Stages for Mixin - annotation processing - member validation - pre apply - member + bytecode validation - pre apply transforms - member + bytecode validation - post apply - member + bytecode validation - post apply transforms - full validation # Internal Spec ## Stages ### Annotation Processing Stage Collect all redirects and transforms from relevant classes ### Validation Stage Validate that no [invariants](##Validation) are broken ### Transformation Stage pre/post Apply transforms with redirects ## Redirects (Impl detail: Applied in listed order) ### FieldToMethod: ChunkPos.x → CloPos.getX() - Src owner - Src type - Field name - Dst owner - Getter name (must be zero args) - Setter name (must be one arg) (must exist if and only if the field is non-final) :::warning The field to method redirect **must** set the correct INVOKE instruction for the destination type; interfaces should be INVOKEINTERFACE and classes INVOKEVIRTUAL ::: ### ConstructorToFactory: ChunkAccess.\<init\> → CloAccess.construct - Src owner - Constructor method signature (no name, it's `<init>` :)) - Dst owner - New method name ### Field: ChunkAccess.chunkPos → CubeAccess.cloPos - Src owner - Src type - Field name - Dst owner - New field name ### Method - Src owner - Method name+signature - Dst owner - New method name ### Type: ChunkAccess → CloAccess - Src type - Dst type :::warning The type redirect **must** set the correct INVOKE instruction for the destination type; interfaces should be INVOKEINTERFACE and classes INVOKEVIRTUAL ::: ### No Redirect Chaining Redirects for a given transform **must** be applied in a single pass. For example: - Given type redirects A→B and B→A it results in swapping the types. - Given type redirects A→B and B→C it results in replacing B with C, and A with B (**not** replacing A with C) ## Transform - Field ? should we have this? - Method - MethodFromOther - Class ### Transform Chaining If the destination of a transform is itself used as the source for a second transform, the second destination **must** be the result of first applying the first set of redirects to the original source, followed by the second set of redirects. This **must** hold for any combination of arbitrarily many method and class transforms. :::warning ["No Redirect Chaining"](###No-Redirect-Chaining) only applies for a single transform. For example: if one transform redirects types A→B and B→A, and a chained transform applies the same, the resulting method **must** be identical to the pre-transformed original method. ::: ## Validation Validation **shall** be applied in all cases. In development environments, validation failures **shall** cause an immediate error. In production, validation failures **must** either cause an error or log the failure; by default, production environments **shall** log rather than erroring, this **may** be configured (e.g. with a flag). ### Validation pass types - Member validation - apply - Bytecode validation - Full validation - perform both member and bytecode validation, and also validate that ALL fields/methods/types referenced anywhere actually exist. ### Disallowed errors The following errors **must not** occur at runtime when validation is enabled; they **shall** be detected and reported during validation, using the invariants specified in this section. - VerifyError - UnsatisfiedLinkError - NoSuchFieldError - NoSuchMethodError - AbstractMethodError - IncompatibleClassChangeError - ClassCircularityError ### Member Validation #### Invariant 1 (destination/redirected source type parity) All field/method/fieldToMethod/constructorToFactory redirects **must** have corresponding type redirects such that the expected types/signatures specified in code match with those produced by redirecting the source field/method. Not doing so **shall** cause an error in [Validation](###Validation-Stage). :::warning **This includes the `this` parameter** for non-static methods and field accesses. ::: For example, a field redirect from `ChunkAccess.chunkPos` to `CubeAccess.cloPos` **must** have a corresponding type redirect from `ChunkPos` to `CloPos`. #### Invariant 2 (type redirect field and method completeness) The destination type of a type redirect **must** have corresponding fields and methods for all fields and methods on the source type, **including supertypes**, and **including constructors of the source type** (but not constructors of supertypes), such that it is not possible for transformed code to attempt to access nonexistent fields/methods after all redirects are applied. Not doing so **shall** cause an error in [Validation](###Validation-Stage). (TODO: this should be disableable for constructors - possibly for other cases? worth considering. Invariant 6 will still apply regardless.) :::info Note that this does not impose any additional limitations on the contents of the destination type; there may be extra fields and methods. ::: For example, for a type redirect from `ChunkAccess` to `CubeAccess`, fields/methods retaining the same name do not require an explicit redirect (eg: `ChunkAccess.unsaved` to `CubeAccess.unsaved`), while fields/methods with differing names do (eg: `ChunkAccess.getPos()` to `CubeAccess.cc_getCloPos()`). #### Invariant 3 (Subclasses) If there exists a type redirect for a given source class, subclasses of that class **must** have a type redirect, such that the destination class for the subclass extends the destination class for the original class. (Note that a class and its subclass **may** be redirected to the same type, i.e. if `B extends A`, `A` and `B` may both be redirected to `C`) (TODO a way to disable this if wanted? we want this for CC, but in simpler cases we might not.) #### Invariant 4 (Overridden subclass members) When a field/method is redirected, this redirect **shall** also be applied for subclasses that do not shadow/override the field/method. (TODO implementation detail; move elsewhere?). For fields/methods on subclasses that **do** shadow/override those of the superclass, there **must** also exist a redirect for the shadowed/overridden field/method. Not doing so **shall** cause an error in [Validation](###Validation-Stage). (TODO maybe have a flag to disable this? not sure if we always want this) :::info Observe that this requirement is not relevant in cases where there is a type redirect without a corresponding field/method redirect; for example `ChunkAccess.setBlockState` is type-redirected to `CubeAccess.setBlockState` without a method redirect, meaning (TODO wording) no things are required for overriding methods such as `LevelChunk.setBlockState`. ::: ### Bytecode Validation #### Invariant 5 (constructor to factory TODO name) If a constructor is redirected to a factory method, all other constructors that call that constructor **must** also have redirects to factory methods. (Impl detail: this **shall** be checked during mixin init, after preApply, and after postApply) #### Invariant 6 (Method body type/member redirect parity) All member accesses within a method body **must** have field/method redirects such that the destination members match the descriptors obtained by applying type redirects to the source members. This should respect field-to-method and constructor-to-factory redirects. (Impl detail: this **shall** be checked during mixin init, after preApply, and after postApply) ### Full Validation #### Existence Validation During a full validation pass, all fields/methods/types referenced in transformed code **must** exist and have access modifiers such that the transformed code is legal (i.e. visibility and field finality). ## Application Stage # Implementation/API Spec - ClassProvider - MappingsProvider ## Annotations - `@Dasm` ### Redirect sets - `@RedirectSet` - `@RedirectContainer` ### Redirects (TODO naming) - `@FieldToMethodRedirect` - `@ConstructorToFactory` - `@FieldRedirect` - `@MethodRedirect` - `@TypeRedirect` - `@AddFieldToSets` - `@AddMethodToSets` Add transform destination to a set: - `@AddTransformToSets` ### Transforms - `@TransformFromMethod` - `@TransformFromClass` ### Other - `@FieldSig` - `@MethodSig` - `@ConstructorMethodSig` - `@Ref` # Implementation Oddities

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully