Skip to content

Commit

Permalink
Showing 9 changed files with 24 additions and 46 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -4509,13 +4509,13 @@ public List<StrptimeToken> getCachedStrptimePattern(String pattern) {
/**
* Add a method, so it can be printed out later.
*
* @param name the name of the method
* @param id raw name String of the method to be profiled
* @param method
*/
void addProfiledMethod(final ByteList name, final DynamicMethod method) {
void addProfiledMethod(final String id, final DynamicMethod method) {
if (!config.isProfiling() || method.isUndefined()) return;

getProfilingService().addProfiledMethod(name, method);
getProfilingService().addProfiledMethod(id, method);
}

/**
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -497,7 +497,7 @@ private DynamicMethod putMethod(Ruby runtime, ByteList name, DynamicMethod metho

methodLocation.getMethodsForWrite().put(name, method);

runtime.addProfiledMethod(name, method);
runtime.addProfiledMethod(name.toString(), method);
return method;
}

@@ -1581,7 +1581,7 @@ public CacheEntry newCacheEntry(ByteList name, DynamicMethod method, int token)
if (method.isUndefined()) return new CacheEntry(method, token);

CacheEntry delegated = previous.newCacheEntry(name, method, token);
DynamicMethod enhancedMethod = getMethodEnhancer().enhance(name, delegated.method);
DynamicMethod enhancedMethod = getMethodEnhancer().enhance(name.toString(), delegated.method);

return new CacheEntry(enhancedMethod, delegated.token);
}
Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@
package org.jruby.runtime.profile;

import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.util.ByteList;

/**
* Implementations of this interface will be used to enhance methods with profiling information/ callbacks.
@@ -48,9 +47,9 @@ public interface MethodEnhancer {
* return delegate;
* }
* </pre>
* @param name the name of the given delegate
* @param id the name of the given delegate
* @param delegate the method to enhance
* @return the enhanced method. if nothing is to be done, the delegate itself can be returned
*/
public DynamicMethod enhance(ByteList name, DynamicMethod delegate);
public DynamicMethod enhance(String id, DynamicMethod delegate);
}
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@
import org.jruby.Ruby;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.runtime.ThreadContext;
import org.jruby.util.ByteList;

/**
* A ProfilingService is used to profile jruby programs.
@@ -67,8 +66,5 @@ public interface ProfilingService {
* @param name the name
* @param method the method
*/
@Deprecated
public void addProfiledMethod(String name, DynamicMethod method);

public void addProfiledMethod(ByteList name, DynamicMethod method);
}
Original file line number Diff line number Diff line change
@@ -34,8 +34,6 @@
import org.jruby.runtime.profile.ProfileCollection;
import org.jruby.runtime.profile.ProfileReporter;
import org.jruby.runtime.profile.ProfilingService;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* This implementation of {@link org.jruby.runtime.profile.ProfilingService} will be used for all profiling methods
@@ -68,22 +66,19 @@ public DefaultProfileReporter newProfileReporter(ThreadContext context) {
}

@Override
public void addProfiledMethod(String name, DynamicMethod method) {
addProfiledMethod(StringSupport.stringAsUTF8ByteList(name), method);
public void addProfiledMethod(String id, DynamicMethod method) {
profiledMethods.addProfiledMethod(id, method);
}

@Override
public void addProfiledMethod(ByteList name, DynamicMethod method) {
profiledMethods.addProfiledMethod(name, method);
}
/**
* @author Andre Kullmann
*/
private final class DefaultMethodEnhancer implements MethodEnhancer {
@Override
@SuppressWarnings("deprecation")
public DynamicMethod enhance(ByteList name, DynamicMethod delegate) {
profiledMethods.addProfiledMethod(name, delegate);
public DynamicMethod enhance(String id, DynamicMethod delegate) {
profiledMethods.addProfiledMethod(id, delegate);

return new ProfilingDynamicMethod(delegate);
}
}
Original file line number Diff line number Diff line change
@@ -132,11 +132,10 @@ static String methodName(ProfiledMethod profileMethod) {
final String displayName;
if (profileMethod != null) {
DynamicMethod method = profileMethod.getMethod();
ByteList name = profileMethod.getName();
// FIXME: bytelist_love: replace with just bytelist once we process Method to be ByteList.
if (name == null) name = StringSupport.stringAsUTF8ByteList(method.getName());
// FIXME: bytelist_love: consider all bytelist version of moduleHashMethod once name in Module is ByteList.
displayName = moduleHashMethod(method.getImplementationClass(), name.toString());
String id = profileMethod.getName();
if (id == null) id = method.getName();
// FIXME: bytelist_love: we are still using id here but methodName should return either id or encoded name depending on how it is used.
displayName = moduleHashMethod(method.getImplementationClass(), id.toString());
} else {
displayName = "<unknown>";
}
Original file line number Diff line number Diff line change
@@ -7,17 +7,16 @@
* A dynamic method + it's invocation name holder for profiling purposes.
*/
public class ProfiledMethod {

final ByteList name;
final String id;
final DynamicMethod method;

public ProfiledMethod(ByteList name, DynamicMethod method) {
this.name = name;
public ProfiledMethod(String id, DynamicMethod method) {
this.id = id;
this.method = method;
}

public ByteList getName() {
return name;
public String getName() {
return id;
}

public DynamicMethod getMethod() {
Original file line number Diff line number Diff line change
@@ -79,14 +79,10 @@ private ConcurrentMap<Long,ProfiledMethod> getMethods() {
return methods;
}

public void addProfiledMethod(final String name, final DynamicMethod method) {
addProfiledMethod(StringSupport.stringAsUTF8ByteList(name), method);
}

public void addProfiledMethod(ByteList name, DynamicMethod method ) {
public void addProfiledMethod(String name, DynamicMethod method ) {
final long serial = method.getSerialNumber();

if ( getMethods().size() >= getProfileMaxMethods()) {
if (getMethods().size() >= getProfileMaxMethods()) {
getWarnings().warnOnce(IRubyWarnings.ID.PROFILE_MAX_METHODS_EXCEEDED, "method count exceeds max of " + getConfig().getProfileMaxMethods() + "; no new methods will be profiled");
return;
}
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
import org.jruby.Ruby;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.runtime.ThreadContext;
import org.jruby.util.ByteList;

/**
* @author Andre Kullmann
@@ -21,7 +20,7 @@ public ProfileCollection newProfileCollection(ThreadContext context) {
public MethodEnhancer newMethodEnhancer(Ruby runtime) {
return new MethodEnhancer() {
@Override
public DynamicMethod enhance(ByteList name, DynamicMethod delegate) {
public DynamicMethod enhance(String id, DynamicMethod delegate) {
return delegate;
}
};
@@ -35,9 +34,4 @@ public ProfileReporter newProfileReporter(ThreadContext context) {
@Override
public void addProfiledMethod(String name, DynamicMethod method) {
}

@Override
public void addProfiledMethod(ByteList name, DynamicMethod method) {

}
}

0 comments on commit 35e3dcd

Please sign in to comment.