Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make MethodProbes use MethodHandles over reflection (HZ-3024) #25279

Merged
merged 46 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
4d90beb
Try out MethodProbes
JackPGreen Aug 23, 2023
0a90cc0
Refactor
JackPGreen Aug 23, 2023
670f19a
Add fix for static methods
JackPGreen Aug 24, 2023
0420650
Refactor
JackPGreen Aug 24, 2023
9637a79
Remove `bindTo`
JackPGreen Aug 29, 2023
14254b6
Refactor `int` constants to `enum`
JackPGreen Aug 29, 2023
b89e83b
Refactor
JackPGreen Aug 29, 2023
f93136f
Refactor
JackPGreen Aug 29, 2023
e4af74b
REVERT
JackPGreen Aug 29, 2023
0a86747
Swap to `invokeExact`
JackPGreen Aug 29, 2023
799a8ab
Try out MethodProbes
JackPGreen Aug 23, 2023
80c6c5e
Refactor
JackPGreen Aug 23, 2023
990c185
Add fix for static methods
JackPGreen Aug 24, 2023
70c5306
Refactor
JackPGreen Aug 24, 2023
b3e47ad
Remove `bindTo`
JackPGreen Aug 29, 2023
2dd9a48
Refactor `int` constants to `enum`
JackPGreen Aug 29, 2023
b2402b1
Refactor
JackPGreen Aug 29, 2023
67ab6eb
Refactor
JackPGreen Aug 29, 2023
8c7ae5a
REVERT
JackPGreen Aug 29, 2023
6a5e367
Swap to `invokeExact`
JackPGreen Aug 29, 2023
5db409e
Merge branch 'probe-method-handles' of https://github.com/JackPGreen/…
JackPGreen Sep 11, 2023
308068c
Revert `EMPTY_ARGS`
JackPGreen Sep 18, 2023
6fe9b79
REVERT
JackPGreen Sep 18, 2023
24fc1f0
Fix unchecked class issues
JackPGreen Sep 19, 2023
70379d7
Fix test types
JackPGreen Sep 19, 2023
652d05a
final if possible
JackPGreen Sep 19, 2023
d9e54b1
Make Probes `throw` `throwable`, not `exception`
JackPGreen Sep 19, 2023
9ffd2df
Calculate `primitive` flag dynamically
JackPGreen Sep 19, 2023
fb7c291
Support `invokeExact`
JackPGreen Sep 19, 2023
3feebf6
Roll back to reflection in some cases
JackPGreen Sep 19, 2023
ba90835
Refactor
JackPGreen Sep 20, 2023
fab31e1
Refactor
JackPGreen Sep 20, 2023
1a02dfd
Javadoc
JackPGreen Sep 20, 2023
7cc5136
Add `LambdaMetafactory`
JackPGreen Sep 20, 2023
4cb0077
Checkstyle
JackPGreen Sep 20, 2023
a00165c
Checkstyle
JackPGreen Sep 20, 2023
15ca076
Javadoc
JackPGreen Sep 20, 2023
fb5db6a
Split ProbeUtils enum & utility functionality
JackPGreen Sep 25, 2023
5fccd6f
REVERT
JackPGreen Sep 25, 2023
00afd56
Checkstyle
JackPGreen Sep 25, 2023
c437190
Remove Javadoc
JackPGreen Sep 25, 2023
845a41e
Constructor visibility
JackPGreen Sep 25, 2023
9fd3a03
Checkstyle
JackPGreen Sep 25, 2023
2c43ac7
Add diag method
JackPGreen Sep 25, 2023
943c494
Replace `throw Throwable` with `throw Exception`
JackPGreen Sep 29, 2023
63ce564
Remove `final` from method paramaters
JackPGreen Oct 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.hazelcast.internal.metrics;

/**
* A {@link ProbeFunction} that provides a double value and can be used to
* A {@link ProbeFunction} that provides a {@link double} value and can be used to
* create a probe using {@link MetricsRegistry#registerStaticProbe(Object, String, ProbeLevel, LongProbeFunction)}
*
* @param <S> the type of the source object.
Expand All @@ -26,8 +26,6 @@
public interface DoubleProbeFunction<S> extends ProbeFunction {

/**
* Gets the current value of the source object.
*
* @param source the source object.
* @return the current value of the source object.
* @throws Exception if something fails while getting the value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.hazelcast.internal.metrics;

/**
* A {@link ProbeFunction} that provides a long value and can be used to create
* A {@link ProbeFunction} that provides a {@link long} value and can be used to create
* a probe using {@link MetricsRegistry#registerStaticProbe(Object, String, ProbeLevel, LongProbeFunction)}
*
* @param <S> the type of the source object.
Expand All @@ -26,8 +26,6 @@
public interface LongProbeFunction<S> extends ProbeFunction {

/**
* Gets the current value of the source object as a long.
*
* @param source the source object.
* @return the current value of the source object.
* @throws Exception if something fails while getting the value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.hazelcast.internal.metrics.impl;

import static com.hazelcast.internal.metrics.impl.ProbeType.getType;
import static java.lang.String.format;

import com.hazelcast.internal.metrics.DoubleProbeFunction;
import com.hazelcast.internal.metrics.LongProbeFunction;
import com.hazelcast.internal.metrics.MetricDescriptor;
Expand All @@ -28,30 +31,18 @@
import java.util.Map;
import java.util.concurrent.Semaphore;

import static com.hazelcast.internal.metrics.impl.ProbeUtils.TYPE_COLLECTION;
import static com.hazelcast.internal.metrics.impl.ProbeUtils.TYPE_COUNTER;
import static com.hazelcast.internal.metrics.impl.ProbeUtils.TYPE_DOUBLE_NUMBER;
import static com.hazelcast.internal.metrics.impl.ProbeUtils.TYPE_DOUBLE_PRIMITIVE;
import static com.hazelcast.internal.metrics.impl.ProbeUtils.TYPE_LONG_NUMBER;
import static com.hazelcast.internal.metrics.impl.ProbeUtils.TYPE_MAP;
import static com.hazelcast.internal.metrics.impl.ProbeUtils.TYPE_PRIMITIVE_LONG;
import static com.hazelcast.internal.metrics.impl.ProbeUtils.TYPE_SEMAPHORE;
import static com.hazelcast.internal.metrics.impl.ProbeUtils.getType;
import static com.hazelcast.internal.metrics.impl.ProbeUtils.isDouble;
import static java.lang.String.format;

/**
* A FieldProbe is a {@link ProbeFunction} that reads out a field that is annotated with {@link Probe}.
*/
abstract class FieldProbe implements ProbeFunction {

final CachedProbe probe;
final Field field;
final int type;
final ProbeType type;
final SourceMetadata sourceMetadata;
final String probeName;

FieldProbe(Field field, Probe probe, int type, SourceMetadata sourceMetadata) {
FieldProbe(Field field, Probe probe, ProbeType type, SourceMetadata sourceMetadata) {
this.field = field;
this.probe = new CachedProbe(probe);
this.type = type;
Expand Down Expand Up @@ -79,28 +70,30 @@ String getProbeName() {
}

static <S> FieldProbe createFieldProbe(Field field, Probe probe, SourceMetadata sourceMetadata) {
int type = getType(field.getType());
if (type == -1) {
ProbeType type = getType(field.getType());
if (type == null) {
throw new IllegalArgumentException(format("@Probe field '%s' is of an unhandled type", field));
}

if (isDouble(type)) {
if (type.getMapsTo() == double.class) {
return new DoubleFieldProbe<S>(field, probe, type, sourceMetadata);
} else {
} else if (type.getMapsTo() == long.class) {
return new LongFieldProbe<S>(field, probe, type, sourceMetadata);
} else {
throw new IllegalArgumentException(type.toString());
}
}

static class LongFieldProbe<S> extends FieldProbe implements LongProbeFunction<S> {

LongFieldProbe(Field field, Probe probe, int type, SourceMetadata sourceMetadata) {
LongFieldProbe(Field field, Probe probe, ProbeType type, SourceMetadata sourceMetadata) {
super(field, probe, type, sourceMetadata);
}

@Override
public long get(S source) throws Exception {
switch (type) {
case TYPE_PRIMITIVE_LONG:
case TYPE_LONG_PRIMITIVE:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the type system is enriched with the other primitive types, you can use a VarHandle and use the same technique to prevent litter as with the MethodProbe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the type system is enriched with the other primitive types, you can use a VarHandle and use the same technique to prevent litter as with the MethodProbe.

I thought it already did for some reason.

Raised separately, although a very easy change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the type enrichment can be left for a future PR

return field.getLong(source);
case TYPE_LONG_NUMBER:
Number longNumber = (Number) field.get(source);
Expand All @@ -125,7 +118,7 @@ public long get(S source) throws Exception {

static class DoubleFieldProbe<S> extends FieldProbe implements DoubleProbeFunction<S> {

DoubleFieldProbe(Field field, Probe probe, int type, SourceMetadata sourceMetadata) {
DoubleFieldProbe(Field field, Probe probe, ProbeType type, SourceMetadata sourceMetadata) {
super(field, probe, type, sourceMetadata);
}

Expand Down