Skip to content

Commit

Permalink
HCOLL-349 HCOLL-350 stage compilation via annotation processing
Browse files Browse the repository at this point in the history
  • Loading branch information
leventov committed Jul 17, 2015
1 parent eaf027b commit fb5f3cf
Show file tree
Hide file tree
Showing 73 changed files with 5,199 additions and 12,496 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.openhft</groupId>
<artifactId>stage-compiler</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2015 Higher Frequency Trading
*
* http://www.higherfrequencytrading.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.openhft.chronicle.hash.impl.stage.data.bytes;

import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.hash.AbstractData;
import net.openhft.chronicle.hash.impl.stage.entry.HashEntryStages;
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
import net.openhft.chronicle.hash.impl.stage.hash.KeyBytesInterop;
import net.openhft.sg.Stage;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;

@Staged
public class EntryKeyBytesData<K> extends AbstractData<K> {

@StageRef KeyBytesInterop<K, ?, ?> ki;
@StageRef HashEntryStages<K> entry;
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;


@Stage("CachedEntryKey") private K cachedEntryKey;
@Stage("CachedEntryKey") private boolean cachedEntryKeyRead = false;

private void initCachedEntryKey() {
cachedEntryKey = innerGetUsing(cachedEntryKey);
cachedEntryKeyRead = true;
}

@Override
public RandomDataInput bytes() {
checkOnEachPublicOperation.checkOnEachPublicOperation();
return entry.entryBS;
}

@Override
public long offset() {
checkOnEachPublicOperation.checkOnEachPublicOperation();
return entry.keyOffset;
}

@Override
public long size() {
checkOnEachPublicOperation.checkOnEachPublicOperation();
return entry.keySize;
}

@Override
public K get() {
checkOnEachPublicOperation.checkOnEachPublicOperation();
return cachedEntryKey;
}

@Override
public K getUsing(K usingKey) {
checkOnEachPublicOperation.checkOnEachPublicOperation();
return innerGetUsing(usingKey);
}

private K innerGetUsing(K usingKey) {
entry.entryBytes.position(entry.keyOffset);
return ki.keyReader.read(entry.entryBytes, size(), usingKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2015 Higher Frequency Trading
*
* http://www.higherfrequencytrading.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.openhft.chronicle.hash.impl.stage.data.bytes;

import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.hash.AbstractData;
import net.openhft.chronicle.hash.impl.stage.hash.KeyBytesInterop;
import net.openhft.chronicle.hash.impl.stage.input.HashInputBytes;
import net.openhft.lang.io.Bytes;
import net.openhft.sg.Stage;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;


@Staged
public class InputKeyBytesData<K> extends AbstractData<K> {
@StageRef HashInputBytes in;
@StageRef KeyBytesInterop<K, ?, ?> ki;

@Stage("CachedBytesInputKey") private K cachedBytesInputKey;
@Stage("CachedBytesInputKey") private boolean cachedBytesInputKeyRead = false;

private void initCachedBytesInputKey() {
cachedBytesInputKey = getUsing(cachedBytesInputKey);
cachedBytesInputKeyRead = true;
}

@Override
public RandomDataInput bytes() {
return in.inputStore;
}

@Override
public long offset() {
return in.inputKeyOffset;
}

@Override
public long size() {
return in.inputKeySize;
}

@Override
public K get() {
return cachedBytesInputKey;
}

@Override
public K getUsing(K usingKey) {
Bytes inputBytes = in.inputBytes;
inputBytes.position(in.inputKeyOffset);
return ki.keyReader.read(inputBytes, size(), usingKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2015 Higher Frequency Trading
*
* http://www.higherfrequencytrading.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.openhft.chronicle.hash.impl.stage.data.instance;

import net.openhft.chronicle.hash.impl.CopyingInstanceData;
import net.openhft.chronicle.hash.impl.stage.hash.KeyBytesInterop;
import net.openhft.chronicle.hash.impl.value.instance.KeyInitableData;
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
import net.openhft.lang.io.DirectBytes;
import net.openhft.sg.Stage;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;

@Staged
public abstract class InputKeyInstanceData<K, KI, MKI extends MetaBytesInterop<K, ? super KI>>
extends CopyingInstanceData<K> implements KeyInitableData<K> {

@StageRef KeyBytesInterop<K, KI, MKI> ki;

private K key = null;

@Override
public void initKey(K key) {
this.key = key;
}

@Override
public K instance() {
return key;
}

@Stage("Buffer") private DirectBytes buffer;
@Stage("Buffer") private boolean marshalled = false;

private void initBuffer() {
MKI mki = ki.keyMetaInterop(key);
long size = mki.size(ki.keyInterop, key);
buffer = getBuffer(this.buffer, size);
mki.write(ki.keyInterop, buffer, key);
buffer.flip();
marshalled = true;
}

@Override
public K getUsing(K usingKey) {
buffer.position(0);
return ki.keyReader.read(buffer, buffer.limit(), usingKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2015 Higher Frequency Trading
*
* http://www.higherfrequencytrading.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.openhft.chronicle.hash.impl.stage.entry;

import net.openhft.chronicle.hash.impl.VanillaChronicleHashHolder;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;

@Staged
public class AllocatedChunks {

@StageRef public VanillaChronicleHashHolder<?, ?, ?> hh;
@StageRef public SegmentStages s;
@StageRef public HashEntryStages<?> entry;

public int allocatedChunks = 0;

public void initAllocatedChunks(int allocatedChunks) {
this.allocatedChunks = allocatedChunks;
}

public void incrementSegmentEntriesIfNeeded() {
// don't increment
}

public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) {
initAllocatedChunks(hh.h().inChunks(entrySize));
entry.copyExistingEntry(s.alloc(allocatedChunks), bytesToCopy);
incrementSegmentEntriesIfNeeded();
}
}
Loading

0 comments on commit fb5f3cf

Please sign in to comment.