Skip to content

Commit

Permalink
Cherry-pick VM changes (#12021)
Browse files Browse the repository at this point in the history
* [gas] add gas charges for type creation

* [gas-calibration] Add calibration sample

* [move-vm] Implement a per-frame cache for paranoid mode

* fixup! [move-vm] Implement a per-frame cache for paranoid mode

* fixup! fixup! [move-vm] Implement a per-frame cache for paranoid mode

* fixup! fixup! fixup! [move-vm] Implement a per-frame cache for paranoid mode

* fixup! fixup! fixup! fixup! [move-vm] Implement a per-frame cache for paranoid mode

* [gas] add gas charges for dependencies

---------

Co-authored-by: Runtian Zhou <runtian@aptoslabs.com>
  • Loading branch information
vgao1996 and runtian-zhou authored Feb 15, 2024
1 parent 0e30927 commit 6b16e80
Show file tree
Hide file tree
Showing 25 changed files with 907 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"state_change_hash": "",
"event_root_hash": "",
"state_checkpoint_hash": null,
"gas_used": "4",
"gas_used": "5",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "",
Expand Down Expand Up @@ -280,7 +280,7 @@
"io_gas_units": "1",
"storage_fee_octas": "0",
"storage_fee_refund_octas": "0",
"total_charge_gas_units": "4"
"total_charge_gas_units": "5"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"state_change_hash": "",
"event_root_hash": "",
"state_checkpoint_hash": null,
"gas_used": "4",
"gas_used": "5",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "",
Expand Down Expand Up @@ -285,7 +285,7 @@
"io_gas_units": "1",
"storage_fee_octas": "0",
"storage_fee_refund_octas": "0",
"total_charge_gas_units": "4"
"total_charge_gas_units": "5"
}
}
],
Expand Down Expand Up @@ -412,7 +412,7 @@
"state_change_hash": "",
"event_root_hash": "",
"state_checkpoint_hash": null,
"gas_used": "4",
"gas_used": "5",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "",
Expand Down Expand Up @@ -578,7 +578,7 @@
"io_gas_units": "1",
"storage_fee_octas": "0",
"storage_fee_refund_octas": "0",
"total_charge_gas_units": "4"
"total_charge_gas_units": "5"
}
}
],
Expand Down Expand Up @@ -705,7 +705,7 @@
"state_change_hash": "",
"event_root_hash": "",
"state_checkpoint_hash": null,
"gas_used": "4",
"gas_used": "5",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "",
Expand Down Expand Up @@ -871,7 +871,7 @@
"io_gas_units": "1",
"storage_fee_octas": "0",
"storage_fee_refund_octas": "0",
"total_charge_gas_units": "4"
"total_charge_gas_units": "5"
}
}
],
Expand Down Expand Up @@ -998,7 +998,7 @@
"state_change_hash": "",
"event_root_hash": "",
"state_checkpoint_hash": null,
"gas_used": "4",
"gas_used": "5",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "",
Expand Down Expand Up @@ -1164,7 +1164,7 @@
"io_gas_units": "1",
"storage_fee_octas": "0",
"storage_fee_refund_octas": "0",
"total_charge_gas_units": "4"
"total_charge_gas_units": "5"
}
}
],
Expand Down Expand Up @@ -1291,7 +1291,7 @@
"state_change_hash": "",
"event_root_hash": "",
"state_checkpoint_hash": null,
"gas_used": "4",
"gas_used": "5",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "",
Expand Down Expand Up @@ -1457,7 +1457,7 @@
"io_gas_units": "1",
"storage_fee_octas": "0",
"storage_fee_refund_octas": "0",
"total_charge_gas_units": "4"
"total_charge_gas_units": "5"
}
}
],
Expand Down Expand Up @@ -1584,7 +1584,7 @@
"state_change_hash": "",
"event_root_hash": "",
"state_checkpoint_hash": null,
"gas_used": "4",
"gas_used": "5",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "",
Expand Down Expand Up @@ -1750,7 +1750,7 @@
"io_gas_units": "1",
"storage_fee_octas": "0",
"storage_fee_refund_octas": "0",
"total_charge_gas_units": "4"
"total_charge_gas_units": "5"
}
}
],
Expand Down Expand Up @@ -1877,7 +1877,7 @@
"state_change_hash": "",
"event_root_hash": "",
"state_checkpoint_hash": null,
"gas_used": "4",
"gas_used": "5",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "",
Expand Down Expand Up @@ -2043,7 +2043,7 @@
"io_gas_units": "1",
"storage_fee_octas": "0",
"storage_fee_refund_octas": "0",
"total_charge_gas_units": "4"
"total_charge_gas_units": "5"
}
}
],
Expand Down Expand Up @@ -2170,7 +2170,7 @@
"state_change_hash": "",
"event_root_hash": "",
"state_checkpoint_hash": null,
"gas_used": "4",
"gas_used": "5",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "",
Expand Down Expand Up @@ -2336,7 +2336,7 @@
"io_gas_units": "1",
"storage_fee_octas": "0",
"storage_fee_refund_octas": "0",
"total_charge_gas_units": "4"
"total_charge_gas_units": "5"
}
}
],
Expand Down
230 changes: 230 additions & 0 deletions aptos-move/aptos-gas-calibration/samples_ir/vector/vec-generic.mvir
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
module 0xcafe.VecGeneric {
struct D has copy, drop { x: u64 }
struct C<T> has copy, drop { x: T, y: u64 }
struct E<T> has copy, drop { x: T, y: u64 }
struct F<T> has copy, drop { x: T, y: u64 }
struct G<T> has copy, drop { x: T, y: u64 }

public make(): Self.C<Self.D> {
let d: Self.D;
label b0:
d = D { x: 0 };
return C<Self.D> { x: move(d), y: 0 };
}

public calibrate_vec_len_generic_impl(n: u64) {
let i: u64;
let c: Self.C<Self.D>;
let v: vector<Self.C<Self.D>>;
label entry:
i = 0;
c = Self.make();
v = vec_pack_1<Self.C<Self.D>>(move(c));
label loop_start:
jump_if_false (copy(i) < copy(n)) loop_end;
i = move(i) + 1;
Self.vec_len(&v);
jump loop_start;
label loop_end:
return;
}

public calibrate_vec_len_generic_inlined_impl(n: u64) {
let i: u64;
let c: Self.C<Self.D>;
let v: vector<Self.C<Self.D>>;
label entry:
i = 0;
c = Self.make();
v = vec_pack_1<Self.C<Self.D>>(move(c));
label loop_start:
jump_if_false (copy(i) < copy(n)) loop_end;
i = move(i) + 1;
_ = vec_len<Self.C<Self.D>>(&v);
jump loop_start;
label loop_end:
return;
}

public vec_len(v: &vector<Self.C<Self.D>>) {
label entry:
_ = vec_len<Self.C<Self.D>>(move(v));
return;
}

public entry calibrate_vec_len_generic_1_x100() {
label b0:
Self.calibrate_vec_len_generic_impl(10);
return;
}

public entry calibrate_vec_len_generic_1_x500() {
label b0:
Self.calibrate_vec_len_generic_impl(50);
return;
}

public entry calibrate_vec_len_generic_1_x1000() {
label b0:
Self.calibrate_vec_len_generic_impl(100);
return;
}

public entry calibrate_vec_len_generic_inlined_1_x100() {
label b0:
Self.calibrate_vec_len_generic_inlined_impl(10);
return;
}

public entry calibrate_vec_len_generic_inlined_1_x500() {
label b0:
Self.calibrate_vec_len_generic_inlined_impl(50);
return;
}

public entry calibrate_vec_len_generic_inlined_1_x1000() {
label b0:
Self.calibrate_vec_len_generic_inlined_impl(100);
return;
}

public make_gen<T>(v: T): Self.C<T> {
label b0:
return C<T> { x: move(v), y: 0 };
}

public calibrate_vec_len_generic_2_impl<T: drop>(n: u64, val: T) {
let i: u64;
let c: Self.C<T>;
let v: vector<Self.C<T>>;
label entry:
i = 0;
c = Self.make_gen<T>(move(val));
v = vec_pack_1<Self.C<T>>(move(c));
label loop_start:
jump_if_false (copy(i) < copy(n)) loop_end;
i = move(i) + 1;
Self.vec_len_gen<T>(&v);
jump loop_start;
label loop_end:
return;
}

public calibrate_vec_len_generic_inlined_2_impl<T: drop>(n: u64, val: T) {
let i: u64;
let c: Self.C<T>;
let v: vector<Self.C<T>>;
label entry:
i = 0;
c = Self.make_gen<T>(move(val));
v = vec_pack_1<Self.C<T>>(move(c));
label loop_start:
jump_if_false (copy(i) < copy(n)) loop_end;
i = move(i) + 1;
_ = vec_len<Self.C<T>>(&v);
jump loop_start;
label loop_end:
return;
}

public vec_len_gen<T>(v: &vector<Self.C<T>>) {
label entry:
_ = vec_len<Self.C<T>>(move(v));
return;
}

public entry calibrate_vec_len_generic_2_x100() {
let d: Self.D;
label b0:
d = D { x: 0 };
Self.calibrate_vec_len_generic_2_impl<Self.D>(10, move(d));
return;
}

public entry calibrate_vec_len_generic_2_x500() {
let d: Self.D;
label b0:
d = D { x: 0 };
Self.calibrate_vec_len_generic_2_impl<Self.D>(50, move(d));
return;
}

public entry calibrate_vec_len_generic_2_x1000() {
let d: Self.D;
label b0:
d = D { x: 0 };
Self.calibrate_vec_len_generic_2_impl<Self.D>(100, move(d));
return;
}

public entry calibrate_vec_len_generic_inlined_2_x100() {
let d: Self.D;
label b0:
d = D { x: 0 };
Self.calibrate_vec_len_generic_inlined_2_impl<Self.D>(10, move(d));
return;
}

public entry calibrate_vec_len_generic_inlined_2_x500() {
let d: Self.D;
label b0:
d = D { x: 0 };
Self.calibrate_vec_len_generic_inlined_2_impl<Self.D>(50, move(d));
return;
}

public entry calibrate_vec_len_generic_inlined_2_x1000() {
let d: Self.D;
label b0:
d = D { x: 0 };
Self.calibrate_vec_len_generic_inlined_2_impl<Self.D>(100, move(d));
return;
}

public calibrate_vec_len_generic_inlined_exterme_impl<T: drop>(n: u64, val: T) {
let i: u64;
let v: vector<Self.C<Self.E<Self.F<Self.G<T>>>>>;
let g: Self.G<T>;
let f: Self.F<Self.G<T>>;
let e: Self.E<Self.F<Self.G<T>>>;
let c: Self.C<Self.E<Self.F<Self.G<T>>>>;
label entry:
i = 0;
g = G<T> { x: move(val), y: 0};
f = F<Self.G<T>> { x: move(g), y: 0 };
e = E<Self.F<Self.G<T>>> { x: move(f), y: 0 };
c = C<Self.E<Self.F<Self.G<T>>>> { x: move(e), y: 0 };
v = vec_pack_1<Self.C<Self.E<Self.F<Self.G<T>>>>>(move(c));
label loop_start:
jump_if_false (copy(i) < copy(n)) loop_end;
i = move(i) + 1;
_ = vec_len<Self.C<Self.E<Self.F<Self.G<T>>>>>(&v);
jump loop_start;
label loop_end:
return;
}

public entry calibrate_vec_len_generic_inlined_exterme_x100() {
let d: Self.D;
label b0:
d = D { x: 0 };
Self.calibrate_vec_len_generic_inlined_exterme_impl<Self.D>(10, move(d));
return;
}

public entry calibrate_vec_len_generic_inlined_exterme_x500() {
let d: Self.D;
label b0:
d = D { x: 0 };
Self.calibrate_vec_len_generic_inlined_exterme_impl<Self.D>(50, move(d));
return;
}

public entry calibrate_vec_len_generic_inlined_exterme_x1000() {
let d: Self.D;
label b0:
d = D { x: 0 };
Self.calibrate_vec_len_generic_inlined_exterme_impl<Self.D>(100, move(d));
return;
}
}
Loading

0 comments on commit 6b16e80

Please sign in to comment.