Skip to content

Java 9 compatibility #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ then
sudo apt-get update
sudo apt-get install opam
else
brew install opam ocaml camlp4
brew install opam ocaml camlp4
export OCAML_VERSION="system"
fi

Expand Down
3 changes: 2 additions & 1 deletion .travis.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
echo "Working on branch" $TRAVIS_BRANCH

OPAM_DEPENDS="ocamlfind camlzip extlib camomile"
OPAM_DEPENDS="ocamlfind camlzip extlib"

opam switch create $OCAML_VERSION
opam switch $OCAML_VERSION
eval `opam config env`

Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ matrix:
dist: trusty
sudo: required
env :
- OCAML_VERSION=4.02.3
- OCAML_VERSION=4.07.0
- os: linux
dist: trusty
sudo: required
env :
- OCAML_VERSION=4.07.0
- OCAML_VERSION=4.08.0
- os: osx

notifications:
Expand Down
3 changes: 1 addition & 2 deletions javalib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ build: [
install: [make "install"]
remove: ["ocamlfind" "remove" "javalib"]
depends: [
"ocaml" {>= "4.02"}
"ocaml" {>= "4.04"}
"conf-which" {build}
"ocamlfind" {build}
"camlzip" {>= "1.05"}
"camlp4"
"extlib"
"camomile"
]

synopsis: "Javalib is a library written in OCaml with the aim to provide a high level representation of Java .class files"
Expand Down
11 changes: 10 additions & 1 deletion src/jBasics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ type constant =
| ConstInvokeDynamic of bootstrap_method_index * method_signature
| ConstNameAndType of string * descriptor
| ConstStringUTF8 of string
| ConstModule of string
| ConstPackage of string
| ConstUnusable

(* Stackmap type. *)
Expand All @@ -177,7 +179,14 @@ type verification_type =
| VObject of object_type
| VUninitialized of int (* creation point *)

type stackmap = (int * verification_type list * verification_type list)
type stackmap_frame =
| SameFrame of int
| SameLocals of int * verification_type
| SameLocalsExtended of int * int * verification_type
| ChopFrame of int * int
| SameFrameExtended of int * int
| AppendFrame of int * int * verification_type list
| FullFrame of int * int * verification_type list * verification_type list

type version = {major :int; minor:int;}

Expand Down
11 changes: 10 additions & 1 deletion src/jBasics.mli
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ type constant =
| ConstInvokeDynamic of bootstrap_method_index * method_signature
| ConstNameAndType of string * descriptor
| ConstStringUTF8 of string
| ConstModule of string
| ConstPackage of string
| ConstUnusable

(** {1 Stackmaps} *)
Expand All @@ -342,7 +344,14 @@ type verification_type =
| VUninitialized of int (** creation point *)

(** Stackmap type. *)
type stackmap = (int* verification_type list * verification_type list)
type stackmap_frame =
| SameFrame of int
| SameLocals of int * verification_type
| SameLocalsExtended of int * int * verification_type
| ChopFrame of int * int
| SameFrameExtended of int * int
| AppendFrame of int * int * verification_type list
| FullFrame of int * int * verification_type list * verification_type list

(** {1 Errors} *)

Expand Down
13 changes: 2 additions & 11 deletions src/jClassLow.mli
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ type class_flag = [
| `AccEnum
| `AccInterface
| `AccSuper
| `AccModule
]

type access_flag = [
Expand All @@ -238,19 +239,9 @@ type access_flag = [
| `AccVarArgs
| `AccAnnotation
| `AccEnum
| `AccModule
]


(** DFr : Addition for 1.6 stackmap. *)
type stackmap_frame =
| SameFrame of int
| SameLocals of int * verification_type
| SameLocalsExtended of int * int * verification_type
| ChopFrame of int * int
| SameFrameExtended of int * int
| AppendFrame of int * int * verification_type list
| FullFrame of int * int * verification_type list * verification_type list

type mp_flags = [ `AccFinal | `AccSynthetic | `AccMandated | `AccRFU of int ]

type method_parameters = {
Expand Down
2 changes: 1 addition & 1 deletion src/jCode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ type jcode = {
c_line_number_table : (int * int) list option;
c_local_variable_table : (int * int * string * value_type * int) list option;
c_local_variable_type_table : (int * int * string * JSignature.fieldTypeSignature * int) list option;
c_stack_map : stackmap list option;
c_stack_map : stackmap_frame list option;
c_attributes : (string * string) list;
}

Expand Down
2 changes: 1 addition & 1 deletion src/jCode.mli
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ type jcode = {
(** (start_pc, length, name, type, index) *)
c_local_variable_type_table : (int * int * string * JSignature.fieldTypeSignature * int) list option;
(** LocalVariableTable for generics, described in the JVM Spec se8, §4.7.14 *)
c_stack_map : stackmap list option;
c_stack_map : stackmap_frame list option;
c_attributes : (string * string) list;
}

Expand Down
35 changes: 30 additions & 5 deletions src/jDumpBasics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ let rec dump_constant ch = function
JLib.IO.printf ch "invoke-dynamic : %d %s"
bmi
(ms_name ms)
| ConstModule s -> JLib.IO.printf ch "module %s" s
| ConstPackage s -> JLib.IO.printf ch "package %s" s

let dump_bootstrap_argument ch = function
| `String s -> dump_constant ch (ConstString s)
Expand Down Expand Up @@ -216,11 +218,34 @@ let dump_verification_type = function
| VObject c -> sprintf "Object %s" (object_value_signature c)
| VUninitialized off -> sprintf "Uninitialized %d" off

let dump_stackmap ch (offset,locals,stack) =
JLib.IO.printf ch "\n offset=%d,\n locals=[" offset;
List.iter (fun t -> JLib.IO.printf ch "\n %s" (dump_verification_type t)) locals;
JLib.IO.printf ch "],\n stack=[";
List.iter (fun t -> JLib.IO.printf ch "\n %s" (dump_verification_type t)) stack
(* let dump_stackmap ch (offset,locals,stack) =
* JLib.IO.printf ch "\n offset=%d,\n locals=[" offset;
* List.iter (fun t -> JLib.IO.printf ch "\n %s" (dump_verification_type t)) locals;
* JLib.IO.printf ch "],\n stack=[";
* List.iter (fun t -> JLib.IO.printf ch "\n %s" (dump_verification_type t)) stack *)

let dump_stackmap ch frame =
match frame with
| SameFrame k -> JLib.IO.printf ch "SameFrame(tag:%d)\n" k
| SameLocals (k,vtype) ->
JLib.IO.printf ch "SameLocals(tag:%d,%s)\n" k (dump_verification_type vtype)
| SameLocalsExtended (k,i,vtype) ->
JLib.IO.printf ch "SameLocalsExtended(tag:%d,%d,%s)\n"
k i (dump_verification_type vtype)
| ChopFrame (k,i) ->
JLib.IO.printf ch "ChopFrame(tag:%d,%d)\n" k i
| SameFrameExtended (k,i) ->
JLib.IO.printf ch "SameFrameExtended(tag:%d,%d)\n" k i
| AppendFrame (k,i,vtypes) ->
let svtypes = String.concat "," (List.map dump_verification_type vtypes) in
JLib.IO.printf ch "AppendFrame(tag:%d,%d,%s)\n" k i svtypes
| FullFrame (k,offset,locals,stack) ->
JLib.IO.printf ch "FullFrame(tag:%d," k;
JLib.IO.printf ch "\n offset=%d,\n locals=[" offset;
List.iter (fun t -> JLib.IO.printf ch "\n %s" (dump_verification_type t)) locals;
JLib.IO.printf ch "],\n stack=[";
List.iter (fun t -> JLib.IO.printf ch "\n %s" (dump_verification_type t)) stack;
JLib.IO.nwrite_string ch ")\n"

open JCode

Expand Down
2 changes: 1 addition & 1 deletion src/jDumpBasics.mli
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ val dump_constantpool : 'a JLib.IO.output -> constant array -> unit
val dump_verification_type : verification_type -> string

val dump_stackmap :
'a JLib.IO.output -> stackmap -> unit
'a JLib.IO.output -> stackmap_frame -> unit
(** [dump_stackmap ch sm] prints on [ch] the stackmap [sm]. *)

val dump_exc : 'a JLib.IO.output -> 'b -> JCode.exception_handler -> unit
Expand Down
21 changes: 2 additions & 19 deletions src/jDumpLow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -198,30 +198,13 @@ let access_flags = function
| `AccBridge -> "bridge"
| `AccSuper -> "`AccSuper"
| `AccSynthetic -> "synthetic"
| `AccModule -> "module"
| `AccRFU i -> Printf.sprintf "rfu 0x%X" i
) flags) ^ " "

let string_nwrite ch s = JLib.IO.nwrite_string ch s

let dump_java6_stackmap ch frame =
match frame with
| SameFrame k -> JLib.IO.printf ch "SameFrame(tag:%d)\n" k
| SameLocals (k,vtype) ->
JLib.IO.printf ch "SameLocals(tag:%d,%s)\n" k (dump_verification_type vtype)
| SameLocalsExtended (k,i,vtype) ->
JLib.IO.printf ch "SameLocalsExtended(tag:%d,%d,%s)\n"
k i (dump_verification_type vtype)
| ChopFrame (k,i) ->
JLib.IO.printf ch "ChopFrame(tag:%d,%d)\n" k i
| SameFrameExtended (k,i) ->
JLib.IO.printf ch "SameFrameExtended(tag:%d,%d)\n" k i
| AppendFrame (k,i,vtypes) ->
let svtypes = String.concat "," (List.map dump_verification_type vtypes) in
JLib.IO.printf ch "AppendFrame(tag:%d,%d,%s)\n" k i svtypes
| FullFrame (k,offset,locals,stack) ->
JLib.IO.printf ch "FullFrame(tag:%d," k;
dump_stackmap ch (offset,locals,stack);
string_nwrite ch ")\n"
let dump_java6_stackmap ch frame = dump_stackmap ch frame

let dump_inner_classes ch icl =
List.iter
Expand Down
8 changes: 4 additions & 4 deletions src/jFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ open JClassLow
let sep =
match Sys.os_type with
| "Unix"
| "Cygwin" -> ":"
| "Win32" -> ";"
| "Cygwin" -> ':'
| "Win32" -> ';'
| _ -> assert false

let replace_dot =
Expand Down Expand Up @@ -75,14 +75,14 @@ let open_path s =
type directories = string list

let make_directories dirs =
match JLib.String.nsplit dirs sep with
match String.split_on_char sep dirs with
| [] -> [Filename.current_dir_name]
| cp ->
List.filter is_dir cp

let class_path cp =
let cp_list =
match JLib.String.nsplit cp sep with
match String.split_on_char sep cp with
| [] -> [Filename.current_dir_name]
| cp -> cp
in
Expand Down
2 changes: 1 addition & 1 deletion src/jFile.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type class_path

(** [sep] is the class path separator. It contains a colon (:) under
Unix and Cygwin and a semi-colon (;) under Windows (or MinGW). *)
val sep : string
val sep : char

(** [class_path cp] opens a class path from the list [cp] of
directories and jar (or zip) files separated by {!JFile.sep}. jar
Expand Down
14 changes: 1 addition & 13 deletions src/jHigh2Low.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,7 @@ let h2l_inner_classes = function
in
[AttributeInnerClasses (List.rev_map h2l_ic icl)]

(* This function only build full frames. We don't try to compress the stackmap
information like javac. *)
let h2l_stackmap_table sm : stackmap_frame list =
let (_,table) =
List.fold_left
(fun (last,table) (pc,lv,sv) ->
if (last = 0) then
(pc,FullFrame(255,pc,lv,sv)::table)
else
let offset_delta = pc - last - 1 in
(pc,FullFrame(255,offset_delta,lv,sv)::table)
) (0,[]) sm in
List.rev table
let h2l_stackmap_table sm : stackmap_frame list = sm

let h2l_code2attribute consts bm_table = function
| Native -> []
Expand Down
45 changes: 5 additions & 40 deletions src/jLow2High.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,44 +96,7 @@ let low2high_attributes consts (al:JClassLow.attribute list) :attributes =
al);
}

let expanse_stackmap_table stackmap_table =
let (_,stackmap) =
List.fold_left
(fun ((pc,l,_),stackmap) frame ->
match frame with
| SameFrame k ->
let offset = pc + k + 1 in
let s = (offset,l,[]) in
(s,s::stackmap)
| SameLocals (k,vtype) ->
let offset = pc + k - 64 + 1 in
let s = (offset,l,[vtype]) in
(s,s::stackmap)
| SameLocalsExtended (_,offset_delta,vtype) ->
let offset = pc + offset_delta + 1 in
let s = (offset,l,[vtype]) in
(s,s::stackmap)
| ChopFrame (k,offset_delta) ->
let offset = pc + offset_delta + 1 in
let nb_chop = 251 - k in
let l_chop = List.rev
(JLib.List.drop nb_chop (List.rev l)) in
let s = (offset,l_chop,[]) in
(s,s::stackmap)
| SameFrameExtended (_,offset_delta) ->
let offset = pc + offset_delta + 1 in
let s = (offset,l,[]) in
(s,s::stackmap)
| AppendFrame (_,offset_delta,vtype_list) ->
let offset = pc + offset_delta + 1 in
let s = (offset,l@vtype_list,[]) in
(s,s::stackmap)
| FullFrame (_,offset_delta,lv,sv) ->
let offset = pc + offset_delta + 1 in
let s = (offset,lv,sv) in
(s,s::stackmap)
) ((-1,[],[]),[]) stackmap_table in
List.rev stackmap
let expanse_stackmap_table stackmap_table = stackmap_table

let low2high_code consts bootstrap_methods = function c ->
{
Expand Down Expand Up @@ -801,8 +764,6 @@ let low2high_innerclass = function
}

let low2high_class cl =
if cl.j_super = None && cl.j_name <> JBasics.java_lang_object
then raise (Class_structure_error "Only java.lang.Object is allowed not to have a super-class.");
let flags = cl.j_flags in
let (access,flags) = flags2access (flags :> access_flag list) in
let (accsuper,flags) = get_flag `AccSuper flags in
Expand All @@ -812,6 +773,10 @@ let low2high_class cl =
let (is_synthetic,flags) = get_flag `AccSynthetic flags in
let (is_annotation,flags) = get_flag `AccAnnotation flags in
let (is_enum,flags) = get_flag `AccEnum flags in
let (is_module,flags) = get_flag `AccModule flags in
if not (JBasics.get_permissive ()) &&
cl.j_super = None && cl.j_name <> JBasics.java_lang_object && not is_module
then raise (Class_structure_error "Only java.lang.Object is allowed not to have a super-class.");
let flags =
List.map
(function
Expand Down
4 changes: 2 additions & 2 deletions src/jManifest.mll
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ and section = parse
(* TODO : accept missing manifest version (for midlets) *)
let sections2manifest = function
| ((mv, v) :: main) :: sections
when String.lowercase mv = "manifest-version" ->
when String.lowercase_ascii mv = "manifest-version" ->
{main_section =
{manifest_version = List.map int_of_string (JLib.String.nsplit v ".");
main_attributes = main};
individual_sections =
List.map
(function
| (name, v) :: attributes
when String.lowercase name = "name" ->
when String.lowercase_ascii name = "name" ->
{name = v ; attributes = attributes}
| _ -> failwith "incorrect manifest")
sections}
Expand Down
Loading