Skip to content

Commit

Permalink
WIP: remove Uncached data lib call from RAbstractVector.setData
Browse files Browse the repository at this point in the history
This is a temporary hack.
  • Loading branch information
Pavel Marek committed Jun 17, 2021
1 parent 8d754b3 commit 8d9ac1f
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 8d9ac1f

Please sign in to comment.