Skip to content

Commit

Permalink
Add optimizer hints
Browse files Browse the repository at this point in the history
Summary:
Some Redex optimizations in the pipe which move/delete/inline static methods. Those optimizations may fubar what's going on in `SysUtil.LollipopSysdeps`, so prepping a hint annotation to guide Redex not to disturb these methods.

I expect the redex hints for fbandroid-at-large to be more precise in their language. However, since `//libraries/soloader` can not depend on code in `//java`, I'm just going to create a catch-all annotation here which will disable the relevant optimizations in redex for our fbandroid apps.

(FWIW, redex will not operate on hardcoded annotations; a mapping layer will say "this set of annotations means this, this set means that". So DoNotOptimize will be listed as suppressing inlining/movement/deletion etc.)

@public Add a hint (which may or may not be observed) to any optimizers in our tool chain that we don't want optimizations being applied to the annotated elements. Necessary to prevent inlining/movement of some methods on SysUtil$LollipopSysdeps.

Reviewed By: dariorussi

Differential Revision: D2989738

fbshipit-source-id: 4d4c5b8d91b146e7ac3700c2edfe1d008c3a08e1
  • Loading branch information
Brian Long authored and Pascal Hartig committed Jan 9, 2018
1 parent d07925d commit 84329ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions java/com/facebook/soloader/DoNotOptimize.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2004-present Facebook. All Rights Reserved.

package com.facebook.soloader;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.RetentionPolicy.CLASS;

/**
* A hint (which may or may not be observed) to any optimizers in our tool
* chain that we don't want optimizations being applied to the annotated
* elements.
*/
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR })
@Retention(CLASS)
public @interface DoNotOptimize {
}
2 changes: 2 additions & 0 deletions java/com/facebook/soloader/SysUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ public static void dumbDeleteRecursive(File file) throws IOException {
* downlevel.
*/
private static final class LollipopSysdeps {
@DoNotOptimize
public static String[] getSupportedAbis() {
return Build.SUPPORTED_32_BIT_ABIS; // We ain't doing no newfangled 64-bit
}

@DoNotOptimize
public static void fallocateIfSupported(FileDescriptor fd, long length) throws IOException {
try {
Os.posix_fallocate(fd, 0, length);
Expand Down

0 comments on commit 84329ca

Please sign in to comment.