{"id":16375006,"url":"https://github.com/moderocky/overlord","last_synced_at":"2025-03-23T03:32:40.759Z","repository":{"id":48228964,"uuid":"311655148","full_name":"Moderocky/Overlord","owner":"Moderocky","description":"A powerful memory management library. Perform illegal, unsafe and incredibly dangerous operations on your JVM's native memory with no restrictions.","archived":false,"fork":false,"pushed_at":"2021-08-04T15:43:59.000Z","size":42,"stargazers_count":46,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T17:08:10.706Z","etag":null,"topics":["java","memory-management","native","unsafe"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Moderocky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-10T12:43:53.000Z","updated_at":"2025-03-07T07:21:46.000Z","dependencies_parsed_at":"2022-09-21T05:06:26.479Z","dependency_job_id":null,"html_url":"https://github.com/Moderocky/Overlord","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moderocky%2FOverlord","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moderocky%2FOverlord/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moderocky%2FOverlord/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moderocky%2FOverlord/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Moderocky","download_url":"https://codeload.github.com/Moderocky/Overlord/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245052630,"owners_count":20553161,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","memory-management","native","unsafe"],"created_at":"2024-10-11T03:19:05.656Z","updated_at":"2025-03-23T03:32:40.143Z","avatar_url":"https://github.com/Moderocky.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Overlord\n=====\n### Opus #1\n\nA powerful memory management library.\n\nPerform illegal, unsafe and incredibly dangerous operations on your JVM's native memory with no restrictions.\n\nYou can also pretend this is C, and manage memory directly! :)\n\nFeatures:\n  * Create objects without using their constructor.\n  * Edit objects in heap memory.\n  * Assign and manage memory outside of the heap.\n  * Store objects and data outside of the heap.\n  * Edit intrinsic parts of an object, such as headers, klass pointers, mark words, etc.\n  * Transform objects to an incompatible type at runtime.\n  * Cast objects to incompatible types.\n  * Create shallow and deep perfect clones of objects.\n  * Construct objects using the constructor from a completely unrelated class.\n  * Trace where methods are called.\n  * Use real objects to provide the implementation for native methods.\n  * Load classes at runtime, both hidden and explicitly.\n  * Create pointers to objects in memory.\n  * Rewrite the behaviour of a method at runtime for reflective access.\n  * Break encapsulation and open jdk.internal classes for access.\n  * Silence those pesky \"illegal reflection\" warnings.\n \n\n### Maven Information\n```xml\n\u003crepository\u003e\n    \u003cid\u003epan-repo\u003c/id\u003e\n    \u003cname\u003ePandaemonium Repository\u003c/name\u003e\n    \u003curl\u003ehttps://gitlab.com/api/v4/projects/18568066/packages/maven\u003c/url\u003e\n\u003c/repository\u003e\n``` \n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003emx.kenzie\u003c/groupId\u003e\n    \u003cartifactId\u003eoverlord\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.1\u003c/version\u003e\n    \u003cscope\u003ecompile\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n### Examples\n\nShallow-clone an object (creates a NEW instance, but any non-primitive field will be a reference to the original.)\n```java \nfinal MyObject original = new MyObject();\nfinal MyObject clone = Overlord.shallowClone(source);\n\nassert original.objectField == clone.objectField;\n```\n\nDeep-clone an object (creates a NEW instance, any non-primitive non-constant field will be recursively deep-cloned from the original.)\n```java \nfinal MyObject original = new MyObject();\nfinal MyObject clone = Overlord.deepClone(source);\n\nassert original.objectField != clone.objectField;\n```\n\nWith the following class structure:\n```java\nstatic class NativeImplClass {\n    public native String getWord();\n    public native void setWord(String word);\n    public native int getNumber();\n    public native void setNumber(int number);\n}\n\nstatic class RealClass {\n    int number = 10;\n    String word = \"hello\";\n\n    protected String getWord() { return word; }\n    protected void setWord(String word) { this.word = word; }\n    protected int getNumber() { return number; }\n    protected void setNumber(int number) { this.number = number; }\n}\n```\n\nYou can use `NativeImplClass` as a blind implementation in the following:\n```java \nfinal RealClass original = new RealClass();\nfinal NativeImplClass cast = Overlord.transform(original, NativeImplClass.class); // Transforms 'original' to an instance of NativeImplClass\n// the 'cast' variable is strongly-typed and so valid hereafter\nOverlord.transform(original, RealClass.class); // Transforms 'original' back to its true class\n// Now any methods called will be executed on RealClass\n\ncast.setNumber(10); // The compiler will execute this public method from NativeImplClass\n                    // The JVM will *actually* execute the protected getNumber method from RealClass\n```\n\nSwapping a constructor:\n```java\nstatic class Class2 {\n    public final int number;\n    public final String name;\n\n    public Class2(String string) {\n        number = 10;\n        name = string;\n    }\n\n}\n\nstatic class Class1 {\n    public final int number;\n    public final String name;\n\n    public Class1(String string) {\n        number = 5;\n        name = string + \" \u003c- thing\";\n    }\n\n}\n```\n\nAny fields set in the copy constructor will either target the object's fields or be ignored silently.\n```java \nfinal Class1 class1 = Overlord.createSwapConstructor(Class1.class, Class2.class, \"hello\");\n\nassert class1.number == 10;\nassert class1.name.equalsIgnoreCase(\"hello\");\n```\n\nCreating an empty object:\n```java \nfinal Class1 obj = Overlord.createEmpty(Class1.class);\n```\n\nReplacing method behaviour for reflection access:\n```java \n{\n    Method method = Blob.class.getMethod(\"myMethod\");\n    Overlord.setReflectiveBehaviour(method, (obj, args) -\u003e \"please don't use reflection on me!\");\n}\n\n\nMethod method = Blob.class.getMethod(\"myMethod\");\n\n// method.invoke(new Blob()) == \"please don't use reflection on me!\"\n// new Blob().myMethod() == whatever the original was\n\nassert !method.invoke(new Blob()).equals(new Blob().myMethod());\n```\nSee RewriteBehaviourTest.class for more examples.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoderocky%2Foverlord","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoderocky%2Foverlord","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoderocky%2Foverlord/lists"}