summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Neupauer <xmaton@messengeruser.com>2023-05-15 16:50:05 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-05-15 22:40:45 +0000
commitba0986ac66e3a22d211ad3707ad037fdc10910af (patch)
treec8bb00824af7b99e2bc9a3a48a02b6961b36d8a0
parentd7b25f8f62727ec1138d5b21fde6e82a1dfa8d97 (diff)
downloadmongo-ba0986ac66e3a22d211ad3707ad037fdc10910af.tar.gz
SERVER-76896 Add direct access for two common slot accessors
-rw-r--r--src/mongo/db/exec/sbe/values/slot.h5
-rw-r--r--src/mongo/db/exec/sbe/vm/vm.cpp30
-rw-r--r--src/mongo/db/exec/sbe/vm/vm.h6
-rw-r--r--src/mongo/db/exec/sbe/vm/vm_printer.cpp2
4 files changed, 42 insertions, 1 deletions
diff --git a/src/mongo/db/exec/sbe/values/slot.h b/src/mongo/db/exec/sbe/values/slot.h
index fdbf99605b7..3b07477a921 100644
--- a/src/mongo/db/exec/sbe/values/slot.h
+++ b/src/mongo/db/exec/sbe/values/slot.h
@@ -70,6 +70,11 @@ public:
* make a deep copy. The returned value is owned by the caller.
*/
virtual std::pair<TypeTags, Value> copyOrMoveValue() = 0;
+
+ template <typename T>
+ bool is() const {
+ return dynamic_cast<const T*>(this) != nullptr;
+ }
};
/**
diff --git a/src/mongo/db/exec/sbe/vm/vm.cpp b/src/mongo/db/exec/sbe/vm/vm.cpp
index 5bdcc7496a2..2f7c1bee391 100644
--- a/src/mongo/db/exec/sbe/vm/vm.cpp
+++ b/src/mongo/db/exec/sbe/vm/vm.cpp
@@ -33,6 +33,7 @@
#include "mongo/platform/basic.h"
#include "mongo/db/exec/sbe/expressions/expression.h"
+#include "mongo/db/exec/sbe/expressions/runtime_environment.h"
#include "mongo/db/exec/sbe/vm/vm.h"
#include "mongo/db/exec/sbe/vm/vm_printer.h"
@@ -77,6 +78,8 @@ namespace vm {
int Instruction::stackOffset[Instruction::Tags::lastInstruction] = {
1, // pushConstVal
1, // pushAccessVal
+ 1, // pushOwnedAccessorVal
+ 1, // pushEnvAccessorVal
1, // pushMoveVal
1, // pushLocalVal
1, // pushMoveLocalVal
@@ -480,8 +483,15 @@ void CodeFragment::appendConstVal(value::TypeTags tag, value::Value val) {
void CodeFragment::appendAccessVal(value::SlotAccessor* accessor) {
Instruction i;
- i.tag = Instruction::pushAccessVal;
+ i.tag = [](value::SlotAccessor* accessor) {
+ if (accessor->is<value::OwnedValueAccessor>()) {
+ return Instruction::pushOwnedAccessorVal;
+ } else if (accessor->is<RuntimeEnvironment::Accessor>()) {
+ return Instruction::pushEnvAccessorVal;
+ }
+ return Instruction::pushAccessVal;
+ }(accessor);
auto offset = allocateSpace(sizeof(Instruction) + sizeof(accessor));
offset += writeToMemory(offset, i);
@@ -7247,6 +7257,24 @@ void ByteCode::runInternal(const CodeFragment* code, int64_t position) {
break;
}
+ case Instruction::pushOwnedAccessorVal: {
+ auto accessor = readFromMemory<value::OwnedValueAccessor*>(pcPointer);
+ pcPointer += sizeof(accessor);
+
+ auto [tag, val] = accessor->getViewOfValue();
+ pushStack(false, tag, val);
+
+ break;
+ }
+ case Instruction::pushEnvAccessorVal: {
+ auto accessor = readFromMemory<RuntimeEnvironment::Accessor*>(pcPointer);
+ pcPointer += sizeof(accessor);
+
+ auto [tag, val] = accessor->getViewOfValue();
+ pushStack(false, tag, val);
+
+ break;
+ }
case Instruction::pushMoveVal: {
auto accessor = readFromMemory<value::SlotAccessor*>(pcPointer);
pcPointer += sizeof(accessor);
diff --git a/src/mongo/db/exec/sbe/vm/vm.h b/src/mongo/db/exec/sbe/vm/vm.h
index 2f43bdf5bb6..17b3eb29b7f 100644
--- a/src/mongo/db/exec/sbe/vm/vm.h
+++ b/src/mongo/db/exec/sbe/vm/vm.h
@@ -265,6 +265,8 @@ struct Instruction {
enum Tags {
pushConstVal,
pushAccessVal,
+ pushOwnedAccessorVal,
+ pushEnvAccessorVal,
pushMoveVal,
pushLocalVal,
pushMoveLocalVal,
@@ -433,6 +435,10 @@ struct Instruction {
return "pushConstVal";
case pushAccessVal:
return "pushAccessVal";
+ case pushOwnedAccessorVal:
+ return "pushOwnedAccessorVal";
+ case pushEnvAccessorVal:
+ return "pushEnvAccessorVal";
case pushMoveVal:
return "pushMoveVal";
case pushLocalVal:
diff --git a/src/mongo/db/exec/sbe/vm/vm_printer.cpp b/src/mongo/db/exec/sbe/vm/vm_printer.cpp
index 921463cab28..e545136cb56 100644
--- a/src/mongo/db/exec/sbe/vm/vm_printer.cpp
+++ b/src/mongo/db/exec/sbe/vm/vm_printer.cpp
@@ -296,6 +296,8 @@ public:
.writeValueToStream(tag, val);
break;
}
+ case Instruction::pushOwnedAccessorVal:
+ case Instruction::pushEnvAccessorVal:
case Instruction::pushAccessVal:
case Instruction::pushMoveVal: {
auto accessor = readFromMemory<value::SlotAccessor*>(pcPointer);