src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ObjectContext.java
author mgronlun
Wed, 30 Oct 2019 19:43:52 +0100
changeset 58863 c16ac7a2eba4
permissions -rw-r--r--
8226511: Implement JFR Event Streaming Reviewed-by: egahlin, mseledtsov, mgronlun Contributed-by: erik.gahlin@oracle.com, mikhailo.seledtsov@oracle.com, markus.gronlund@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58863
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
     1
/*
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
     4
 *
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    10
 *
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    15
 * accompanied this code).
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    16
 *
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    20
 *
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    23
 * questions.
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    24
 */
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    25
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    26
package jdk.jfr.internal.consumer;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    27
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    28
import java.time.ZoneId;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    29
import java.util.HashMap;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    30
import java.util.List;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    31
import java.util.Map;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    32
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    33
import jdk.jfr.EventType;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    34
import jdk.jfr.ValueDescriptor;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    35
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    36
public final class ObjectContext {
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    37
    private final Map<ValueDescriptor, ObjectContext> contextLookup;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    38
    private final TimeConverter timeConverter;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    39
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    40
    public final EventType eventType;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    41
    public final List<ValueDescriptor> fields;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    42
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    43
    ObjectContext(EventType eventType, List<ValueDescriptor> fields, TimeConverter timeConverter) {
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    44
        this.contextLookup = new HashMap<>();
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    45
        this.eventType = eventType;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    46
        this.fields = fields;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    47
        this.timeConverter = timeConverter;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    48
    }
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    49
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    50
    private ObjectContext(ObjectContext parent, ValueDescriptor descriptor) {
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    51
        this.eventType = parent.eventType;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    52
        this.contextLookup = parent.contextLookup;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    53
        this.timeConverter = parent.timeConverter;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    54
        this.fields = descriptor.getFields();
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    55
    }
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    56
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    57
    public ObjectContext getInstance(ValueDescriptor descriptor) {
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    58
        ObjectContext context = contextLookup.get(descriptor);
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    59
        if (context == null) {
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    60
            context = new ObjectContext(this, descriptor);
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    61
            contextLookup.put(descriptor, context);
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    62
        }
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    63
        return context;
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    64
    }
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    65
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    66
    public long convertTimestamp(long ticks) {
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    67
        return timeConverter.convertTimestamp(ticks);
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    68
    }
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    69
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    70
    public long convertTimespan(long ticks) {
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    71
        return timeConverter.convertTimespan(ticks);
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    72
    }
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    73
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    74
    public ZoneId getZoneOffset() {
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    75
        return timeConverter.getZoneOffset();
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    76
    }
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents:
diff changeset
    77
}