From 8d9ac1fc8e37a79d854e9e28935ccfc72b6799df Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 17 Jun 2021 12:34:11 +0200 Subject: [PATCH] WIP: remove Uncached data lib call from RAbstractVector.setData This is a temporary hack. --- .../runtime/data/RComplexArrayVectorData.java | 2 +- .../data/RComplexNativeVectorData.java | 4 +-- .../runtime/data/RDoubleArrayVectorData.java | 2 +- .../runtime/data/RDoubleNativeVectorData.java | 4 +-- .../r/runtime/data/RIntArrayVectorData.java | 2 +- .../r/runtime/data/RIntNativeVectorData.java | 4 +-- .../r/runtime/data/RListArrayDataLibrary.java | 4 +-- .../r/runtime/data/RListNativeData.java | 4 +-- .../runtime/data/RLogicalArrayVectorData.java | 2 +- .../data/RLogicalNativeVectorData.java | 4 +-- .../r/runtime/data/RRawArrayVectorData.java | 2 +- .../r/runtime/data/RRawNativeVectorData.java | 4 +-- .../runtime/data/RStringArrayVectorData.java | 2 +- .../r/runtime/data/RStringCharSXPData.java | 4 +-- .../r/runtime/data/RStringVecNativeData.java | 4 +-- .../r/runtime/data/ShareableVectorData.java | 29 +++++++++++++++++++ .../r/runtime/data/model/RAbstractVector.java | 11 +++++-- 17 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/ShareableVectorData.java diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RComplexArrayVectorData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RComplexArrayVectorData.java index eef9e698fc..45dc7c4d5e 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RComplexArrayVectorData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RComplexArrayVectorData.java @@ -44,7 +44,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -class RComplexArrayVectorData implements TruffleObject { +class RComplexArrayVectorData implements TruffleObject, ShareableVectorData { private final double[] data; private boolean complete; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RComplexNativeVectorData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RComplexNativeVectorData.java index d320a3a873..d6aa700528 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RComplexNativeVectorData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RComplexNativeVectorData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,7 +37,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -public class RComplexNativeVectorData implements TruffleObject { +public class RComplexNativeVectorData implements TruffleObject, ShareableVectorData { // We need the vector, so that we can easily use the existing NativeDataAccess methods // TODO: this field should be replaced with address/length fields and // the address/length fields and logic should be removed from NativeMirror diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDoubleArrayVectorData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDoubleArrayVectorData.java index 0554ec6538..15e26bde11 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDoubleArrayVectorData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDoubleArrayVectorData.java @@ -44,7 +44,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -public class RDoubleArrayVectorData implements TruffleObject { +public class RDoubleArrayVectorData implements TruffleObject, ShareableVectorData { private final double[] data; private boolean complete; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDoubleNativeVectorData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDoubleNativeVectorData.java index cc55b51915..4c95b00ca6 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDoubleNativeVectorData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDoubleNativeVectorData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,7 +37,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -public class RDoubleNativeVectorData implements TruffleObject { +public class RDoubleNativeVectorData implements TruffleObject, ShareableVectorData { // We need the vector, so that we can easily use the existing NativeDataAccess methods // TODO: this field should be replaced with address/length fields and // the address/length fields and logic should be removed from NativeMirror diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RIntArrayVectorData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RIntArrayVectorData.java index 2506cc0a87..58a4867119 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RIntArrayVectorData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RIntArrayVectorData.java @@ -44,7 +44,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -public class RIntArrayVectorData implements TruffleObject { +public class RIntArrayVectorData implements TruffleObject, ShareableVectorData { private final int[] data; private boolean complete; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RIntNativeVectorData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RIntNativeVectorData.java index c1919300c6..272b53ef29 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RIntNativeVectorData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RIntNativeVectorData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,7 +37,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -public class RIntNativeVectorData implements TruffleObject { +public class RIntNativeVectorData implements TruffleObject, ShareableVectorData { // We need the vector, so that we can easily use the existing NativeDataAccess methods // TODO: this field should be replaced with address/length fields and // the address/length fields and logic should be removed from NativeMirror diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListArrayDataLibrary.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListArrayDataLibrary.java index c5faf02ab0..46529cd0be 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListArrayDataLibrary.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListArrayDataLibrary.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -39,7 +39,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(value = VectorDataLibrary.class, receiverType = Object[].class) -public class RListArrayDataLibrary { +public class RListArrayDataLibrary implements ShareableVectorData { @ExportMessage public static NACheck getNACheck(@SuppressWarnings("unused") Object[] receiver) { return NACheck.getEnabled(); diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListNativeData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListNativeData.java index 897bb70617..41358878ed 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListNativeData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListNativeData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,7 +37,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -public class RListNativeData implements TruffleObject { +public class RListNativeData implements TruffleObject, ShareableVectorData { // We need the vector, so that we can easily use the existing NativeDataAccess methods // TODO: this field should be replaced with address/length fields and // the address/length fields and logic should be removed from NativeMirror diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RLogicalArrayVectorData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RLogicalArrayVectorData.java index de8e26e722..1ee2a86613 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RLogicalArrayVectorData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RLogicalArrayVectorData.java @@ -44,7 +44,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -class RLogicalArrayVectorData implements TruffleObject { +class RLogicalArrayVectorData implements TruffleObject, ShareableVectorData { private final byte[] data; private boolean complete; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RLogicalNativeVectorData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RLogicalNativeVectorData.java index 365b9c434d..4794796b9c 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RLogicalNativeVectorData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RLogicalNativeVectorData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -38,7 +38,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -public class RLogicalNativeVectorData implements TruffleObject { +public class RLogicalNativeVectorData implements TruffleObject, ShareableVectorData { // We need the vector, so that we can easily use the existing NativeDataAccess methods // TODO: this field should be replaced with address/length fields and // the address/length fields and logic should be removed from NativeMirror diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RRawArrayVectorData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RRawArrayVectorData.java index 7587773ed8..fb1dba3a2b 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RRawArrayVectorData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RRawArrayVectorData.java @@ -40,7 +40,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -class RRawArrayVectorData implements TruffleObject { +class RRawArrayVectorData implements TruffleObject, ShareableVectorData { private final byte[] data; RRawArrayVectorData(byte[] data) { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RRawNativeVectorData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RRawNativeVectorData.java index 79e6b98089..fd3256c6c3 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RRawNativeVectorData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RRawNativeVectorData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,7 +37,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -public class RRawNativeVectorData implements TruffleObject { +public class RRawNativeVectorData implements TruffleObject, ShareableVectorData { // We need the vector, so that we can easily use the existing NativeDataAccess methods // TODO: this field should be replaced with address/length fields and // the address/length fields and logic should be removed from NativeMirror diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringArrayVectorData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringArrayVectorData.java index 4339911747..c6e93a80e0 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringArrayVectorData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringArrayVectorData.java @@ -44,7 +44,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -class RStringArrayVectorData implements TruffleObject { +class RStringArrayVectorData implements TruffleObject, ShareableVectorData { private final String[] data; private boolean complete; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringCharSXPData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringCharSXPData.java index 8ec8d4a5cb..2ad6f1692f 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringCharSXPData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringCharSXPData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,7 +36,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -public class RStringCharSXPData { +public class RStringCharSXPData implements ShareableVectorData { private final CharSXPWrapper[] data; public RStringCharSXPData(CharSXPWrapper[] data) { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringVecNativeData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringVecNativeData.java index ad9ca7f868..bdf1f7fecb 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringVecNativeData.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringVecNativeData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,7 +37,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @ExportLibrary(VectorDataLibrary.class) -public class RStringVecNativeData implements TruffleObject { +public class RStringVecNativeData implements TruffleObject, ShareableVectorData { // We need the vector, so that we can easily use the existing NativeDataAccess methods // TODO: this field should be replaced with address/length fields and // the address/length fields and logic should be removed from NativeMirror diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/ShareableVectorData.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/ShareableVectorData.java new file mode 100644 index 0000000000..e7cee52f81 --- /dev/null +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/ShareableVectorData.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 3 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 3 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.r.runtime.data; + +/** + * A tagging interface for vector data that are shareable, i.e. writeable. + */ +public interface ShareableVectorData { +} diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/model/RAbstractVector.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/model/RAbstractVector.java index 9d593c4e46..3795fe263a 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/model/RAbstractVector.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/model/RAbstractVector.java @@ -56,6 +56,7 @@ import com.oracle.truffle.r.runtime.data.RSeq; import com.oracle.truffle.r.runtime.data.RSequence; import com.oracle.truffle.r.runtime.data.RStringVector; +import com.oracle.truffle.r.runtime.data.ShareableVectorData; import com.oracle.truffle.r.runtime.data.VectorDataLibrary; import com.oracle.truffle.r.runtime.data.VectorDataWithOwner; import com.oracle.truffle.r.runtime.data.closures.RClosure; @@ -93,8 +94,14 @@ public final void setData(Object data) { // "setOwner" may be a message in the VectorDataLibrary to make this fast ((VectorDataWithOwner) data).setOwner(this); } - // temporary solution to keep isShareable() fast - shareable = VectorDataLibrary.getFactory().getUncached().isWriteable(data); + // TODO: This is a temporary hack, we should implement this with appropriate messages in + // VectorDataLibrary. See GR-28570. + if (data instanceof ShareableVectorData || (this instanceof RList && data instanceof Object[])) { + shareable = true; + } else { + shareable = false; + } + assert shareable == VectorDataLibrary.getFactory().getUncached().isWriteable(data); verifyData(); }