Reviewed By: sblackshear Differential Revision: D5172635 fbshipit-source-id: 67ed695master
parent
c0e20e0880
commit
7be1bfa89f
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2017 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
// Test may_alias treatment of arrays
|
||||
// two arrays of types in a subtype relation may alias, and race
|
||||
|
||||
@ThreadSafe
|
||||
class Parent {}
|
||||
|
||||
@ThreadSafe
|
||||
class Child extends Parent {}
|
||||
|
||||
@ThreadSafe
|
||||
class SubArr {
|
||||
Child[] childArr = new Child[5];
|
||||
Parent[] parentArr = childArr; // actual aliasing not required, but for documentation
|
||||
String[] strArr = new String[5];
|
||||
|
||||
public Child RWrace() {
|
||||
synchronized(this) {
|
||||
parentArr[3] = null;
|
||||
}
|
||||
|
||||
return childArr[4];
|
||||
}
|
||||
|
||||
public String NOrace() {
|
||||
synchronized(this) {
|
||||
parentArr[3] = null;
|
||||
}
|
||||
|
||||
return strArr[2];
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2017 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
// Fields must encapsulate the class they are declared in, not
|
||||
// the class they are potentially inherited into.
|
||||
|
||||
@ThreadSafe
|
||||
class SuperFld {
|
||||
|
||||
private int f = 0;
|
||||
public int getF() {
|
||||
return f; // should *not* report read/write race with SubFld.setF()
|
||||
}
|
||||
|
||||
protected int g = 0;
|
||||
public int getG() {
|
||||
return g; // must report read/write race with SubFld.setG()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
public class SubFld extends SuperFld {
|
||||
|
||||
private int f = 0;
|
||||
synchronized public void setF() {
|
||||
f = 5; // should *not* report
|
||||
}
|
||||
|
||||
synchronized public void setG() {
|
||||
g = 5; // must report
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2017 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
@ThreadSafe
|
||||
public class SwitchEnum {
|
||||
int[] a = new int[8];
|
||||
|
||||
// Java generates a class for the switch, which contains an int array
|
||||
// This leads to races where there are int arrays, here a[]
|
||||
public String getName(EnumClass value) {
|
||||
synchronized(this) {
|
||||
a[0] = 0; // should not report here
|
||||
}
|
||||
switch (value) {
|
||||
case VALUE1: return "value 1";
|
||||
case VALUE3: return "value 3";
|
||||
default: return "other";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum EnumClass { VALUE1, VALUE2, VALUE3 }
|
Loading…
Reference in new issue